Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting the value for historical bars.

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

    Setting the value for historical bars.

    I want to predict the max. price change 3 bars into the future. Therefore when I generate my data set, what I am trying to predict/forecast has to be placed back 3 bars ago. Hope I said the correctly.

    So the DataSeries Class Set method has a format of DataSeries.Set(int, barsago, double value); So my simple indicator the has the price change for 3 bars into the future is:
    protected override void OnBarUpdate()
    {

    //Trgt.Reset();
    if(CurrentBar < lookBack) return;
    if( Close[0] - Close[lookBack] >= 0.00 )
    {
    Trgt.Set(lookBack, High[HighestBar(High,lookBack)] - Close[lookBack] );
    }
    else Trgt.Set(lookBack, Low[LowestBar(Low,lookBack)] - Close[lookBack] );
    }

    Now when adding this indicator to a chart everything is plotted correctly. The last 3 bars, right edge are empty. As they should be.

    The problem comes in when I try and use this indicator in another indicator in which I create the file that contain all of the data that I want to train on. The script: SampleStreamWriter was used as the basis to create the file. I do not get the correct value from the indicator. I am getting some price from somewhere. The name of the indicator is MyTarget. Here is some of the code where I write everything to the file.

    Print("Time:" + Time[lookback].ToString() + " Target: " +MyTarget(Close,lookback).Trgt[3].ToString());

    sw.WriteLine(Time[lookback].ToString()
    + "," + Close[lookback]
    + "," + High[lookback]
    + "," + Low[lookback]
    + "," + Close[lookback + 1]
    + "," + High[lookback + 1]
    + "," + Low[lookback + 1]
    + "," + Close[lookback + 2]
    + "," + High[lookback + 2]
    + "," + Low[lookback + 2]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineK[lookback]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineD[lookback]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineK[lookback + 1]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineD[lookback + 1]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineK[lookback + 2]
    + "," + DinapoliStochastic(Close, 3, 3, 5).LineD[lookback + 2]
    + "," + MyTarget(lookback)[3] );

    I have been able to verify that all of the data being exported to the file is correct except for what MyTarget()[3] is returning. The data is being returned is not even close. As I said, it's some kind of price data.

    Is there something about using barsago in the Set method that I have failed to understand?

    Thanks

    #2
    Perhaps you are running into updating issues. Please see the Help Guide document on Update().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      If I use the normal method of Set:
      Trgt.Set( High[HighestBar(High,lookBack)] - Close[lookBack] );

      Then calling this indicator from another indicator gives me the correct results. After making the appropriate adjustment i.e.
      + MyTarget(lookback)[0]


      Read about the Update() method but not sure if this would fix the problem. Not sure if the Update() would need to be added to my 1st indicator or the second indicator. Also, the second indicator is not plotting anything. The 2nd indicator is just writing a a bunch of lines/records to a text file.

      Comment


        #4
        Not sure what your issue is. You need to reference the plot that has value. Referencing just the indicator generally won't yield values from the particular plot you want. If you are using DataSeries objects things are generally kept up to date for you. You will need to debug to find what values it is returning.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X