Support Board
Date/Time: Fri, 24 Jan 2025 11:07:54 +0000
Post From: ACSIL - UDP request for resetting Persistent Variables re sc.SetDefaults
[2019-01-10 09:08:38] |
PeterSt - Posts: 36 |
I love it when someone else comes up with a solution I could not think of myself. This is what works very well, assumed we are not to lousy to give the chart the focus and use Ctrl-Insert : // bool Recompile = 0; // Set to 1 when the SetDefaults are to be executed. Back to 0 for data processing. 10-01-2019,PS, Deactivated.
// if (Recompile || sc.SetDefaults) // 06-01-2019,PS, Recompile. // if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults) // 10-01-2019,PS, Like this. Ctrl-Insert after Rebuild in VS. // 10-01-2019,PS, The above is formally not correct because the initialization code // will then execute twice. See log of the situation when the If above is active : //Chart: Base Graph | Study: Custom DLL Study | **RECALC** DEF | 2019-01-10 05:40:46 * ***************** //EUR.USD-CASH-IDEALPRO 2 Sec #1 | Reloading chart. | 2019-01-10 05:40:46 //Using Bid/Ask average for last trade price for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:46 //Interactive Brokers | Starting real-time market data updates for: EUR.USD-CASH-IDEALPRO. ID: 1 | 2019-01-10 05:40:46 //Interactive Brokers | Subscribing to Symbol: EUR, SecurityType: CASH, Expiration: , Exchange: IDEALPRO, Primary Exchange: // , Currency: USD, Multiplier: , CallPut: , Strike: , LocalSymbol: , TradingClass: | 2019-01-10 05:40:46 //Interactive Brokers | Requesting security definition data for: EUR.USD-CASH-IDEALPRO. ID: 1 | 2019-01-10 05:40:46 //Intraday data recording state for symbol EUR.USD-CASH-IDEALPRO is set to download 'Pending'. | 2019-01-10 05:40:46 //Delaying start of download for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:46 //Interactive Brokers | Market data type is Live for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:47 //Chart: EUR.USD-CASH-IDEALPRO 2 Sec #1 | Study: // XX04Trading Example: Using Moving Average and Target and Stop | **RECALC** BAR 0 | 2019-01-10 05:40:47 * if (sc.IsFullRecalculation && sc.Index==0 && !sc.SetDefaults) // 10-01-2019,PS, Like this being leaner. Ctrl-Insert after Rebuild in VS. { // Set the study configuration and defaults. if (sc.SetDefaults) { sc.AddMessageToLog("**RECALC** DEF", 1); // This one is called first. } else { sc.AddMessageToLog("**RECALC** BAR 0", 1); // After that, this one is called. } sc.GraphName = "XX04Trading Example: Using Moving Average and Target and Stop"; BuyEntrySubgraph.Name = "XX04Buy Entry"; BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP; BuyEntrySubgraph.PrimaryColor = RGB(64, 255, 0); BuyEntrySubgraph.LineWidth = 3; BuyEntrySubgraph.DrawZeros = false; return; } What the above is all about, is this not-so-intuitive situation : if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults)
So we tend to do it like this, but this will trigger the execution of the Init code twice; one time because it is just explicitly done by Sierra (the general method of working) and one time at the build-up of the Chart which a. implies IsFullRecalculation to be true and b. will run through the first bar. Leaving out either IsFullRecalculation or Index==0 does not matter (but either could be omitted). The crux is here that both IsFullRecalculation and SetDefaults will not be true at the same time and as the log shows (this log is from the Study loading), the SetDefaults is first. In my view it is harmless when each of these is not performed (but one has to), shown by the log data. This led to my decision to only execute the Init code on the IsFullRecalculation. It is to be noted that the "&& !sc.SetDefaults" is required, because else again the Init code executes twice. Without the "code of proof", it looks like this : //if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults) // 10-01-2019,PS, Like this. Ctrl-Insert after Rebuild in VS.
if (sc.IsFullRecalculation && sc.Index==0 && !sc.SetDefaults) // 10-01-2019,PS, Like this being leaner. Ctrl-Insert after Rebuild in VS. { // Set the study configuration and defaults. sc.AddMessageToLog("**RECALC**", 0); sc.GraphName = "XX04Trading Example: Using Moving Average and Target and Stop"; BuyEntrySubgraph.Name = "XX04Buy Entry"; BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP; BuyEntrySubgraph.PrimaryColor = RGB(64, 255, 0); BuyEntrySubgraph.LineWidth = 3; BuyEntrySubgraph.DrawZeros = false; return; } The additional neat thing of this, is that on Ctrl-Ins immediately shows what the effect is on the changes in the Init code (because it happens instantly, contrary to a compile step or even explicit Remove and Add of the Study). Thank you very much for your help ! Peter |