Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Value refrerenced from Indicator in a Stragey is different from indicator data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Value refrerenced from Indicator in a Stragey is different from indicator data

    Hi,

    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:
    05/03 16:00:00 000 BWIC(60 Minute)@183, fastSum=26394, mediumSum=26394, SenkouSpanA=13197, SenkouSpanB=13221.75, KumoDir=-1


    Debug output from the Strategy:
    05/03 16:00:00 000 1-BWIC @183={ D=-1, TenkanSen=13197, KijunSen=13197, ChikouSpan=0, SenkouSpanA=13197, SenkouSpanB=13197, KumoDir=0, PriceKumoDir=-1, PriceBaseLineDir=-1}
    See that the (bar 183 on the 60 minute, 05/03 16:00:00 000) SenkouSpanA are indentical, but SenkouSpanB and KumoDir are different.

    Here is the Indicator relevant code:
    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
    ​
    Here is the Strategy relevant code:
    Code:
        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]+"}");
            }
        }        ​
    Here is the chart with the strategy:
    Click image for larger version

Name:	Screenshot 2023-05-25 at 0.29.38.png
Views:	160
Size:	923.3 KB
ID:	1252884

    #2
    Hello Shai Samuel,

    Thank you for writing in.

    I see your strategy is only printing when BarsInProgress == 0 and you are only adding the indicator calculated on the primary series visually with AddChartIndicator(BWICs[0]);
    I am curious what the results would be if you added the indicator calculated on the 60-minute series visually with AddChartIndicator(BWICs[1]); and isolated your print statements for each BarsInProgress calling OnBarUpdate() (for example, printing the values from the indicator based on the 60-minute series when BarsInProgress ==1).

    The following page in the help guide is a useful overview of working with multi-time frame & instruments:Another option to test would be to comment out your currently added instances of the BWIC indicator and add only the BWIC based on the added 60-minute series and double-check the results. Isolating this time frame might help to narrow down and better understand how the strategy is calculating.

    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Josephina55, 06-14-2025, 06:30 PM
    0 responses
    16 views
    0 likes
    Last Post Josephina55  
    Started by mathfrick2023, 05-08-2025, 12:51 PM
    8 responses
    77 views
    0 likes
    Last Post Yogaman
    by Yogaman
     
    Started by several, 04-22-2025, 05:21 AM
    2 responses
    249 views
    0 likes
    Last Post Lukasxgtx  
    Started by cherkoul, 06-12-2025, 11:21 PM
    0 responses
    18 views
    0 likes
    Last Post cherkoul  
    Started by NTEducationTeam, 06-12-2025, 02:30 PM
    0 responses
    30 views
    0 likes
    Last Post NTEducationTeam  
    Working...
    X