Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multi time frame does not take a trade

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

    multi time frame does not take a trade

    Hi

    I am trading from a 5 min or 10 min barchart with CalculateOnBarClose=true.
    In order to be able to play around with stops and profits during the trade I changed the same strategy to CalculateOnBarClose=false. This is working after some difficulties, but it is not possible to backtest this strategy.
    So I was thinking of using 2 timeframes in the strategy – with CalculateOnBarClose=true. A 5 min and an 1 min timeframe. The entry signal is taken from the 5 min and the close/high/etc of the 1 min bars is used for playing with stops and profits.
    According to the documentation orders can only be taken at the barclose of the primary timeframe, in Ninjascript the condition if(BarsInProgress==0). So the 1 min timeframe has to be the primary timeframe.

    I developed a very small test script
    It is a sma crossover with only an entry and some kind of trailing.
    In the script I count the 1 min bars and at bar 5 the entry signal of the 5 min timeframe is checked.
    In order to check the progress of the script the value of some variables is written to the output window.

    - I have observed the following
    - The strategy does not take any entry trade
    - The exit is working but as no entry trade is taken there is no exit trade
    - The boolean Long changes from false to true the next 1 min bar after it has become false, independently of the value of Barcount.

    The last item I really do not understand as Long can only change to true when eg the condition if(Barcount==5) is met.

    I really should appreciate if any one could could shed some light on this problem.
    I have attached a part of a screenshot of the output window.
    (The strategy is running on the Dax with european times)
    The script follows below.

    SCRIPT

    Variables
    double Max=0;
    bool Long=false;
    int Barcount=0;


    if(BarsInProgress==0)
    {
    Barcount=Barcount+1;

    if(Barcount==5
    && CrossAbove(Closes[1][0], SMA(BarsArray[1],5), 1)
    && Long==false)
    {
    EnterLong("Test");
    Long=true;
    }

    //*******************Trailing
    if(Long=true)
    {
    if(Close[0]>Max)
    {
    Max=Close[0];
    }
    if(Close[0]<=(Max-10*TickSize))
    {
    ExitLong("Test");
    Long=false;
    Max=0;
    }
    }
    if(Barcount==5) // reset barcount to 0
    Barcount=0;
    Print(Time.ToString()+" "+ Close[0].ToString()+" "+Max.ToString()+" "+Barcount.ToString()+" "+Long.ToString());
    }
    if(BarsInProgress==1)
    Print(Time.ToString()+" "+ Close[0].ToString()+" "+Max.ToString()+" "+Barcount.ToString()+" "+Long.ToString()+" "+"5min");

    Attached Files

    #2
    Are you sure it is not entering trades? I copied your code and it is executing trades for me. The reason your bool value changes from independent of your Barcount value is because the condition to change doesn't require a Barcount check. You are only checking if your Close is less than equal to Max-10*TickSize.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      I am sure that it does not take any trade. I am running it now on live data- ER2 december contract.
      It does not take an entry trade.
      The entry conditions are

      if(Barcount==5
      && CrossAbove(Closes[1][0], SMA(BarsArray[1],5), 1)
      && Long==false)
      {
      EnterLong("Test");
      Long=true;
      }

      When the boolean runs into false it turns into true the next 1 min bar.
      It looks like that all the entry conditions do not work.
      Below is a part of the output window. the boolean turns true at the second 1 min bar (european time)

      13-9-2007 20:55:00 791,5 792,2 0 True
      13-9-2007 20:55:00 791,5 792,2 0 True 5min
      13-9-2007 20:56:00 791,2 0 1 False
      13-9-2007 20:57:00 790,8 790,8 2 True
      13-9-2007 20:58:00 791,1 791,1 3 True


      I attach the script so that you are sure to have an exact copy of the strategy.

      Attached Files

      Comment


        #4
        Here is the problem:

        In your trailing code you have
        //*******************Trailing
        if(Long=true)

        It should be
        if(Long==true)
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh

          Thanks
          How stupid of me.
          It is working fine now.

          Comment


            #6
            I have a similar issue. My multi-time frame strategy will only enter a trade on the bip0 and not on bip3 like I also want. If I comment out the entry on bip0, then it will enter on bip3 but it will never exit.

            I simply want to enter/exit two instruments at same time.

            Code:
            Add(PeriodType.Minute, 2); // bip 1
            Add("$USDJPY", PeriodType.Minute, 2); // bip2
            Add("NQ 12-08", PeriodType.Minute, 2); // bip3
            
            .
            .
            .
            
            if (BarsInProgress == 0 && FirstTickOfBar)
            {
              if (Position.MarketPosition == MarketPosition.Flat)
            {
            EnterLong(DefaultQuantity, "long 1 es");
            EnterLong(3, DefaultQuantity, "long 1 nq");
            }
            Above enters long1 es, does not enter long1 nq.

            Now elsewhere, to exit:

            Code:
            if (BarsInProgress == 0)
            {
            ExitLong("Get out", "long 1 es");
            ExitLong(3, "Get out", long 1 nq");
            }
            I believe I've shown relevant code. Again, it will enter bip0 (long 1 es) and exit bip0 (long 1 es) no problem. But, it will not enter/exit bip3 (long 1 nq) on the next line.

            If I comment out the entry/exit bip0 line, it will neter long 1 nq (bip3) but it will never exit (forced exit, market close).

            Thanks for help.

            Mike

            Comment


              #7
              Someone will follow up on this post on Monday.
              RayNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Ray View Post
                Someone will follow up on this post on Monday.
                Thanks Ray, as always. When's the last time you took a vacation!? I hope after NT7 you can go off to some far away island and relax some

                Comment


                  #9
                  ctrlbrk,

                  Have you increased your EntriesPerDirection setting? Or changed your EntryHandling setting?
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    OK wow I need some sleep. Entries per direction was it... duh...

                    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