Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-TimeFrame in Ver 7

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

    Multi-TimeFrame in Ver 7

    What is wrong with the following code?

    I am running a 1min strategy.
    I simply want to enter long if the last primary 1min bar(High[0]) on current day crosses above the previous days high(Highs[1][0]).
    I want to set the Profit target on Entry as ATR(20) Daily bars (ATR(BarsArray[1],20)[0])

    I can plot the correct entry/exit/target levels via an Indicator but when I try to run the same code in a Strategy it gives me garbage.

    Thanks for any assistance.


    public class EnterOnPrevDailyHigh : Strategy
    {

    protected override void Initialize()
    {
    Add(PeriodType.Day, 1);

    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    // Ensure at least 50 Days lookback
    if (CurrentBar < 72000) //50D*24Hrs*60min
    return;

    if (BarsInProgress != 0)
    return;

    double LongStopIn = Highs[1][0];
    double LongTarget = LongStopIn + (ATR(BarsArray[1],20)[0]);
    double LongStopLoss = LongStopIn - (ATR(BarsArray[1],20)[0]);

    if ((High[0] > LongStopIn) && (Position.MarketPosition == MarketPosition.Flat))
    {
    EnterLong(1000, "Enter Long");
    SetStopLoss(LongStopLoss);
    SetProfitTarget(LongTarget);
    }

    }

    #2
    I suggest printing the timestamp of your BarsInProgress 1 context to see which daily bar you are actually processing. Perhaps you are accessing the values of a bar you were not expecting.

    Print(Times[1][0].ToString());
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,

      There is no problem with the date of the Daily bar. It successfully gives me the date of the previous days close for each minute of the current day.

      The below Indicator uses same code, gives correct levels.

      The Strategy is an extremely simple piece of code that can be put into any of the other competing packages in minutes, yet with NT 7 it has a number of our experienced programmers complaining about 'yet another' Ninja Version 7 issue.

      Is this the case? Can anyone there actually successfully run the code as a 1min Strategy against 3 months worth of FX spot pairs with a 5pm EST close and exit-on-close set to false.?


      Thanks for any help


      public class EnterOnPrevDailyHighPlot : Indicator
      {

      protected override void Initialize()
      {
      Add(PeriodType.Day, 1);

      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "LongStopIn"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "LongTarget"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "LongStopLoss"));

      Overlay = true;
      }


      protected override void OnBarUpdate()
      {
      // 50 Days lookback
      if (CurrentBar < 72000)
      return;

      LongStopIn.Set(Highs[1][0]);
      LongTarget.Set(Highs[1][0] + (ATR(BarsArray[1],20)[0]);
      StopLoss.Set(Highs[1][0] - (ATR(BarsArray[1],20)[0]);

      }

      Comment


        #4
        The indicator model is not the same as the strategy model. How many days are you actually loading on the chart for the strategy to run on? I.e. does it have enough days loaded to satisfy 50 days as suggested in the code?

        Can you please provide an example as to what exactly are the values you see versus what values you were hoping to see? It would probably be easier if you just attached your whole strategy as an exported NinjaScript assembly and provided us with the exact instrument, chart settings, and strategy settings used in your testing so we can see what you see on our end.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          Please find Indicator and Strategy .cs attached.

          I am testing on AUDJPY , 1min bars, Forex session template, out on close=false, 6 months of lookback historical data.

          Realistically, the instrument and settings should be irrelevant.

          Would very much appreciate knowing if this is a Ninja version 7 thing.
          Have already dedicated overly excessive time into getting MTF to work in this version with continuously dubious results.

          Thanks for your help
          Attached Files

          Comment


            #6
            abfc123, I tested on my end here on a 1 min FX spot chart and I think you're just running into rounding values working with doubles, you would see it printing your calc'ed values to the output window - have you tried rounding those to the instrument's ticksized before formulating your trade entry / exit conditions?

            Print(Instrument.MasterInstrument.Round2TickSize(L ongStopIn));
            Print(Instrument.MasterInstrument.Round2TickSize(L ongTarget));
            Print(Instrument.MasterInstrument.Round2TickSize(L ongStopLoss));

            Comment


              #7
              Thanks,

              The rounding To Tick size did the trick.
              Very relieved!

              Thank you again for your rapid responses

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              633 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              364 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              567 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              568 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X