Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to align Indicator with Strat. TimeFrame

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

    How to align Indicator with Strat. TimeFrame

    hey there,

    I am in need of some NT8 calculation advise here, as none of it seems to calculate right as compared to DATA BOX/Chart vs print out values, and what it executes on.

    In the interest of saving space, I just left MACD and RSI cross for the last bar, and thus an entry decision. However, it executes later than I would want according to the chart, and that's because the values are bogus. I check it, using print; what could be causing these miscalculations? I added some initializing code to show that it's all there right. This is happening for ALL indicator values. If i include a bring out for Bollinger bands, the top of the band print out is above 35 for the entry point, and it's easy to see visible from the chart that 35 is only hit or exceeding for Bollinger Bands around May 10th, not Jun 6-8.

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    //RSI
    PeriodRSI = 14;
    SmoothRSI = 3;
    //MACD
    FastMacd = 12;
    SlowMacd = 26;
    SmoothMacd = 9;
    }
    else if (State == State.Configure)
    {
    smaFast = EMA(Fast);
    smaSlow = EMA(Slow);
    smaLarge = EMA(Large);
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade)
    return;
    // Crossing up MACD and RSI, I've left other indicators out of this - as compared to screenshot
    if ( Position.MarketPosition == MarketPosition.Flat && CrossAbove(RSI(PeriodRSI,SmoothRSI).Value,RSI(Peri odRSI,SmoothRSI).Avg,3) && CrossAbove(MACD(FastMacd,SlowMacd,SmoothMacd).Valu e, MACD(FastMacd,SlowMacd,SmoothMacd).Avg,5)
    {
    Print("YOU ARE HERE");
    Print(RSI(PeriodRSI,SmoothRSI).Value[0]);
    Print(RSI(PeriodRSI,SmoothRSI).Avg[0]);
    Print(MACD(FastMacd,SlowMacd,SmoothMacd).Value[0]);
    Print(MACD(FastMacd,SlowMacd,SmoothMacd).Avg[0]);
    ExitShort();

    EnterLongLimit((int)orderQuantity,GetCurrentBid(), "LONG Limit 1.1 ");
    Print("LONG Limit 1.1 "+ Position.Instrument + " At current price: "+GetCurrentBid());
    justEntered = true;

    }

    --> THESE are the values from DATA BOX:
    (RSI(PeriodRSI,SmoothRSI).Value[0]) = 66.07
    (RSI(PeriodRSI,SmoothRSI).Avg[0]) =63.23
    (MACD(FastMacd,SlowMacd,SmoothMacd).Value[0]) = 0.772
    (MACD(FastMacd,SlowMacd,SmoothMacd).Avg[0]) = 0.304
    I'm also not confusing previous bar with this bar, since RSI value for the current entry bar is 63.55. In fact below print values do not show up EVER on the data box or chart

    --> THESE are the values from OUTPUT:
    (RSI(PeriodRSI,SmoothRSI).Value[0]) = 64.10
    (RSI(PeriodRSI,SmoothRSI).Avg[0]) =59.60
    (MACD(FastMacd,SlowMacd,SmoothMacd).Value[0]) = 0.365
    (MACD(FastMacd,SlowMacd,SmoothMacd).Avg[0]) = 0.227

    Any idea what could be causing this?

    Please help, I've spent days on this, and can't figure it out.
    Attached Files

    #2
    Hello lmatiukas, and thank you for your query.

    I am including a simple indicator which is very much like yours, except that it also prints times in addition to current indicator values. If you look carefully at the time in your data box, and compare that time to the times reported by this script directly, you will notice that your data box updates infrequently, and is always lagging behind your script times.

    Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      thanks so much for sharing that tid-bit, and so these are strange results I get.
      Using YOUR code as an indicator, or adding it just before the IF statement:

      The time is 6/7/2016 4:00:00 PM
      Data box value is currently 66.0699757188835

      using this code inside the IF statement:
      The time is 6/7/2016 4:00:00 PM
      Data box value is currently 64.1077986689114

      66.07 is the correct value showing up on the chart for the strategy.

      Considering that this is your code:

      protected override void OnBarUpdate()
      {
      if (CurrentBar < 1)
      {
      return;
      }

      Print("The time is " + Time[0]);
      Value[0] = RSI(14,3)[0];
      Print("Data box value is currently " + RSI(14,3)[0]);
      }

      And this is my entire code for that one type of entry, I don't see any logical differences... How am I getting wrong values, see anything I missed?:

      protected override void OnBarUpdate()
      {

      if (CurrentBar < BarsRequiredToTrade)
      {
      return;
      }

      ao = bwAO().AOBarPlot[0];//SMA(Median,5)[0] - SMA(Median,34)[0];
      ao1 = bwAO().AOBarPlot[1];//SMA(Median,5)[1] - SMA(Median,34)[1];
      ao2 = bwAO().AOBarPlot[2];//SMA(Median,5)[2] - SMA(Median,34)[2];
      ao3 = bwAO().AOBarPlot[3];//SMA(Median,5)[3] - SMA(Median,34)[3];
      ao4 = bwAO().AOBarPlot[4];//SMA(Median,5)[4] - SMA(Median,34)[4];

      // Crossing up MACD and RSI, check all others
      if ( smaLarge[0]>=smaLarge[1] && TSSuperTrend(_smode,_length,_multiplier,_maType,_s mooth,_showArrows,_colorBars,_playAlert)[0]>TSSuperTrend(_smode,_length,_multiplier,_maType,_ smooth,_showArrows,_colorBars,_playAlert)[1] && Position.MarketPosition == MarketPosition.Flat && CrossAbove(RSI(PeriodRSI,SmoothRSI).Value,RSI(Peri odRSI,SmoothRSI).Avg,3) && Close[0]>Close[1] && MESA_AMA(fastLimit,slowLimit).Values[0][0] > MESA_AMA(fastLimit,slowLimit).Values[1][0] && CrossAbove(MACD(FastMacd,SlowMacd,SmoothMacd).Valu e, MACD(FastMacd,SlowMacd,SmoothMacd).Avg,5) && Close[0]>=smaSlow[0] && Close[0] > BollingerTripleState_V4NT8(numStdDev,period,narrow _Tick_Threashold,wide_Tick_Threashold,displayData, myLines,shading,opacity).Middle[0] && High[1] < BollingerTripleState_V4NT8(numStdDev,period,narrow _Tick_Threashold,wide_Tick_Threashold,displayData, myLines,shading,opacity).Upper[1] && ao > ao1 && ao1 > ao2 )
      {
      Print("YOU ARE HERE");
      Print("The time is " + Time[0]); //so I can match times
      Value[0] = RSI(14,3)[0]; //double checking with hard values
      Print("Data box value is currently " + RSI(14,3)[0]); //printing hard values
      Print(RSI(PeriodRSI,SmoothRSI).Value[0]); //PeriodRSI = 14, SmoothRSI=3
      Print(RSI(PeriodRSI,SmoothRSI).Avg[0]);
      Print(MACD(FastMacd,SlowMacd,SmoothMacd).Value[0]);
      Print(MACD(FastMacd,SlowMacd,SmoothMacd).Avg[0]);
      ExitShort();

      EnterLongLimit((int)orderQuantity,GetCurrentBid(), "LONG Limit 1.1 ");
      Print("LONG Limit 1.1 "+ Position.Instrument + " At current price: "+GetCurrentBid());
      justEntered = true;

      }

      How can the values change, just because they're inside of an If statement. Also if I simplify the if statement to something like if (1==1), then the values are printed out properly. So something WITHIN that statement is changing the value of the same time frame [0].

      -- Also there are no typos in this code, and it compiles, as I've noticed due to formatting, there would seem MACD has a typo in here --

      -- ALSO, twilight zone doesn't end there. If I leave JUST smaLarge[0]>=smaLarge[1] in my if statement, or if include unlimited amount of sma checks for [1],[2] and so on, I also get CORRECT data box printouts.
      Last edited by lmatiukas; 07-20-2016, 09:37 PM.

      Comment


        #4
        Time and Bar series calls appear to be volatile in NT8. That is, when you call Close[0] , you are truly getting the most recent Close tick, and not the Close tick before OnBarUpdate was called. I am including a script which demonstrates this by calling a print statement, sleeping for 3 seconds, and calling another print statement. The two print statements have two different values.

        Sample output :

        The time is 17-Jul-16 16:05:02, close is 18512
        The time is 17-Jul-16 16:05:05, close is 18511.5
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X