I am developing a strategy based on an indicator that I modified a little bit from the the source. Basically I added a few plots with some calculations. The indicator displays correctly on the screen, and when debuged the Dataseries holds the correct values.
For the strategy, I added 2 additional DataSeries, using AddDataSeries, and called the indicator 3 times using the original Close[0] and the 2 new ones. So basically I have the same indicator in 3 different time frames (15/60/240 minutes).
In this strategy, when calculating the signal, I am getting values that are a little different from what I have in the indicator for the same bar. See the debug printout and the relevant pieces of code.
Your help is very appricated

Debug output from the Indicator:
Debug output from the Strategy:
Here is the Indicator relevant code:
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"BWIC"; Name = "BWIC"; Calculate = Calculate.OnBarClose; IsOverlay = true; ... AddPlot(Brushes.Red, "TenkanSen (Conversion Line)"); AddPlot(Brushes.Purple, "KijunSen (Base Line)"); AddPlot(Brushes.MediumBlue, "ChikouSpan (Lagging Span)"); AddPlot(CloudAreaColorUp, "SenkouSpanA (Leading Span A)"); AddPlot(CloudAreaColorDown, "SenkouSpanB (Leading Span B)"); ShowTransparentPlotsInDataBox = true; AddPlot(Brushes.Transparent,"PriceKumoDir"); AddPlot(Brushes.Transparent,"PriceBaseLineDir"); AddPlot(Brushes.Transparent,"KumoDir"); AddPlot(Brushes.Transparent,"KumoWidthTicks"); AddPlot(Brushes.Transparent,"CurBar"); } else if (State == State.DataLoaded) { } } protected override void OnBarUpdate() { CurBar[0] = CurrentBar; if ((CurrentBar < PeriodFast) || (CurrentBar < PeriodMedium) || (CurrentBar < PeriodSlow)) return; double fastSum = MAX(High, PeriodFast)[0]+MIN(Low, PeriodFast)[0]; double mediumSum = MAX(High, PeriodMedium)[0]+MIN(Low, PeriodMedium)[0]; TenkanSen[0] = fastSum/2.0; KijunSen[0] = mediumSum/2.0; ChikouSpan[PeriodMedium] = Close[0]; SenkouSpanA[0] = (fastSum+mediumSum)/4.0; SenkouSpanB[0] = (MAX(High, PeriodSlow)[0]+MIN(Low, PeriodSlow)[0])/2.0; KumoDir[0] = SenkouSpanA[0].ApproxCompare(SenkouSpanB[0]); PriceKumoDir[0] = Close[0].ApproxCompare(KumoDir[0]>0?SenkouSpanA[0]:SenkouSpanB[0]); PriceBaseLineDir[0] = Close[0].ApproxCompare(KijunSen[0]); KumoWidthTicks[0] = Math.Round(Math.Abs(SenkouSpanA[0]-SenkouSpanB[0])/TickSize,0); Print(Time[0].ToString("MM/dd HH:mm:ss fff")+" BWIC("+Bars.BarsPeriod.Value+" "+Bars.BarsPeriod.BarsPeriodTypeName+")@"+CurrentBar+", fastSum="+fastSum+", mediumSum="+mediumSum +", SenkouSpanA="+SenkouSpanA[0]+", SenkouSpanB="+SenkouSpanB[0]+", KumoDir="+KumoDir[0]); } #region Output Properties [Browsable(false)][XmlIgnore]public Series<double> TenkanSen { get { return Values[0]; }} [Browsable(false)][XmlIgnore]public Series<double> KijunSen { get { return Values[1]; }} [Browsable(false)][XmlIgnore]public Series<double> ChikouSpan { get { return Values[2]; }} [Browsable(false)][XmlIgnore]public Series<double> SenkouSpanA { get { return Values[3]; }} [Browsable(false)][XmlIgnore]public Series<double> SenkouSpanB { get { return Values[4]; }} [Browsable(false)][XmlIgnore]public Series<double> PriceKumoDir { get { return Values[5]; }} [Browsable(false)][XmlIgnore]public Series<double> PriceBaseLineDir { get { return Values[6]; }} [Browsable(false)][XmlIgnore]public Series<double> KumoDir { get { return Values[7]; }} [Browsable(false)][XmlIgnore]public Series<double> KumoWidthTicks { get { return Values[8]; }} [Browsable(false)][XmlIgnore]public Series<double> CurBar { get { return Values[9]; }} #endregion
protected int TFH1 = -1; protected int TFH2 = -1; protected BWIC[] BWICs; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "BWAAIC"; } else if (State == State.Configure) { TFH1 = 1; TFH2 = 2; AddDataSeries(BarsPeriodType.Minute, 60); AddDataSeries(BarsPeriodType.Minute, 240); } else if (State==State.DataLoaded) { BWICs = new BWIC[] {BWIC(Closes[0], 9, 26, 5, 40, Brushes.Green, Brushes.Red, 26), BWIC(Closes[TFH1], 9, 26, 5, 40, Brushes.Green, Brushes.Red, 26), BWIC(Closes[TFH2], 9, 26, 5, 40, Brushes.Green, Brushes.Red, 26)}; AddChartIndicator(BWICs[0]); } } protected override void OnBarUpdate() { if (BarsInProgress==0) { int[] dirs = { Closes[0][0].ApproxCompare(Opens[0][0]), Closes[TFH1][0].ApproxCompare(Opens[TFH1][0]), Closes[TFH2][0].ApproxCompare(Opens[TFH2][0])}; Print(Time[0].ToString("MM/dd HH:mm:ss fff")+" @"+CurrentBars[0]+" ======================== "); Print(Time[0].ToString("MM/dd HH:mm:ss fff")+" @"+CurrentBars[0]+" 2-BWIC @"+CurrentBars[TFH2]+"={ D="+dirs[2] +", TenkanSen="+BWICs[2].TenkanSen[0]+", KijunSen="+BWICs[2].KijunSen[0]+", ChikouSpan="+BWICs[2].ChikouSpan[0] +", SenkouSpanA="+BWICs[2].SenkouSpanA[0]+", SenkouSpanB="+BWICs[2].SenkouSpanB[0]+", KumoDir="+BWICs[2].KumoDir[0] +", PriceKumoDir="+BWICs[2].PriceKumoDir[0]+", PriceBaseLineDir="+BWICs[2].PriceBaseLineDir[0]+"}"); Print(Time[0].ToString("MM/dd HH:mm:ss fff")+" @"+CurrentBars[0]+" 1-BWIC @"+CurrentBars[TFH1]+"={ D="+dirs[1] +", TenkanSen="+BWICs[1].TenkanSen[0]+", KijunSen="+BWICs[1].KijunSen[0]+", ChikouSpan="+BWICs[1].ChikouSpan[0] +", SenkouSpanA="+BWICs[1].SenkouSpanA[0]+", SenkouSpanB="+BWICs[1].SenkouSpanB[0]+", KumoDir="+BWICs[1].KumoDir[0] +", PriceKumoDir="+BWICs[1].PriceKumoDir[0]+", PriceBaseLineDir="+BWICs[1].PriceBaseLineDir[0]+"}"); Print(Time[0].ToString("MM/dd HH:mm:ss fff")+" @"+CurrentBars[0]+" 0-BWIC @"+CurrentBars[0]+"={ D="+dirs[0] +", TenkanSen="+BWICs[0].TenkanSen[0]+", KijunSen="+BWICs[0].KijunSen[0]+", ChikouSpan="+BWICs[0].ChikouSpan[0] +", SenkouSpanA="+BWICs[0].SenkouSpanA[0]+", SenkouSpanB="+BWICs[0].SenkouSpanB[0]+", KumoDir="+BWICs[0].KumoDir[0] +", PriceKumoDir="+BWICs[0].PriceKumoDir[0]+", PriceBaseLineDir="+BWICs[0].PriceBaseLineDir[0]+"}"); } }
Comment