Support Board
Date/Time: Sun, 22 Dec 2024 21:17:13 +0000
[User Discussion] - Study behavior change after running AutoTrade System Based Bar Backtest
View Count: 961
[2015-01-25 17:19:23] |
User85417 - Posts: 3 |
There a study I wrote (began with user contributed source code) that plots the previous day high, low, and close. The study is working correctly on the chart. However after running the AutoTrade System Based Bar Backtest the high and low plots change to plot the high and low of the beginning bar of the new day. THe close plot does not change. Running Chart Recalculate, the high and low plots are fixed. I want to use this code in a strategy and backtest it, but running the backtest breaks the code. I'm thinking that a possible fix would involve a new array that stores the high and low. However, those who are more familiar with SC backtesting might have a better fix. Also, I'm curious about how the backtesting is changing the behavior. Screenshot images below. The first image is of the study plots before the backtest was run. Plots are of the previous day: Red = High, Orange = Close, Green = Low http://www.sierrachart.com/image.php?l=142220467574.png http://www.sierrachart.com/image.php?l=1422204753412.png SCSFExport scsf_ORTradeSignal(SCStudyGraphRef sc) { int sc_index = 0; SCSubgraphRef Output1 = sc.Subgraph[sc_index++]; SCSubgraphRef Output2 = sc.Subgraph[sc_index++]; SCSubgraphRef Output3 = sc.Subgraph[sc_index++]; // // Declare Inputs // int InputIndex = 0; SCInputRef DistanceFromCandle = sc.Input[InputIndex++]; if (sc.SetDefaults) { sc.GraphName="OR Trade Signal"; sc.StudyDescription="Opening Range Trade Signals"; // // Default Input Settings // DistanceFromCandle.Name = "DistanceOfSignalFromBar"; DistanceFromCandle.SetInt(1); // // Default Output Settings // Output1.Name="Close"; Output1.DrawStyle = DRAWSTYLE_DASH; Output1.PrimaryColor = RGB(255,128,0); Output2.Name="High"; Output2.DrawStyle = DRAWSTYLE_DASH; Output2.PrimaryColor = RGB(255,0,0); Output3.Name="Low"; Output3.DrawStyle = DRAWSTYLE_DASH; Output3.PrimaryColor = RGB(0,255,0); sc.ScaleRangeType = SCALE_SAMEASREGION; sc.GraphRegion = 0; sc.AutoLoop = 0; //0 for manual looping sc.FreeDLL = FREEDLL; sc.DrawZeros=0; return; } /***************************************************************************** * * Create Sub-Graph outputs * ****************************************************************************/ float& High = sc.PersistVars->f1; float& Low = sc.PersistVars->f2; float& DailyHigh = sc.PersistVars->f3; float& DailyLow = sc.PersistVars->f4; float& Close = sc.PersistVars->f5; float& DailyClose = sc.PersistVars->f6; int& iDstart = sc.PersistVars->i1; int plot_offset = DistanceFromCandle.GetInt(); int i,j; if (sc.UpdateStartIndex == 0) { iDstart=0; High = sc.BaseDataIn[SC_HIGH][0]; Low = sc.BaseDataIn[SC_LOW][0]; } // Manual looping, therefore all processing is done in this for loop // //loop for all bars starting at the farthest back in time for (i = sc.UpdateStartIndex; i < sc.ArraySize; i++) { int p = i-1, BarDoW, PreviousBarDoW; BarDoW = sc.BaseDateTimeIn[i].GetDayOfWeek(); //get this bar's DoW PreviousBarDoW = sc.BaseDateTimeIn[p].GetDayOfWeek(); //get previous' DoW // DayOfWeekEnum SUNDAY = 0, MONDAY = 1, TUESDAY = 2, WEDNESDAY = 3, // THURSDAY = 4, FRIDAY = 5, SATURDAY = 6 if(BarDoW != PreviousBarDoW) // new day { DailyHigh = High; DailyLow = Low; High = sc.BaseDataIn[SC_HIGH][i]; Low = sc.BaseDataIn[SC_LOW][i]; DailyClose = Close; //Get the HL for the first minute FirstMinHigh = sc.BaseDataIn[SC_HIGH][i] + 0.75; FirstMinLow = sc.BaseDataIn[SC_LOW][i] - 0.75; } else //update the HLC for the day { Close = sc.BaseDataIn[SC_LAST][i]; if(sc.BaseDataIn[SC_HIGH][i] > High) High = sc.BaseDataIn[SC_HIGH][i]; if(sc.BaseDataIn[SC_LOW][i] < Low) Low = sc.BaseDataIn[SC_LOW][i]; } //Display outputs Output1[i] = DailyClose; Output2[i] = DailyHigh; Output3[i] = DailyLow; } } |
[2015-01-25 19:08:51] |
Sierra Chart Engineering - Posts: 104368 |
What you are describing is a bug with the study you are using. Use the Sierra Chart Daily OHLC study to get the data you need and reference the data by following the method described here: http://www.sierrachart.com/index.php?page=doc/doc_ACSILProgrammingConcepts.html#UsingStudyData Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: