Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need some help multitime-frame

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

    Need some help multitime-frame

    Hi guys,

    i´m new to ninja script. the last couple of days i read through the ninja guide and created some strategies, which a working fine. but now i have some problems and need some help.

    i have the following code created
    {
    if (CrossAbove(High, Swing(8).SwingHigh, 1))
    EnterLong;
    }
    now, i know when i backtest this strategy i will get my entrys only on the next bars open after the above code is true. until here, it works.
    but now i want to add another timeframe. so i added a PeriodType.Minute, 1. i want to create a code that says: if the high from the 1 Minute bars object crossabove the last swinghigh from the primary bars 15 min., then enter a long position. but i dont get the correct entrys.


    {
    if (BarsInProgress == 1)
    if (CrossAbove(High, Swing(8).SwingHigh[0], 1)
    EnterLong();
    }

    can someone help me out. thank you.

    #2
    mako1983, welcome to our forums - to calculate the Swing High's on your primary series still in this context please pass in the needed series to the method : Swing(Highs[0], 8).SwingHigh[0]

    Comment


      #3
      Wow, it works. Thank you for your quick reply. You guys are awesome!
      i will come back to you, if i have another question.

      Comment


        #4
        Hey guys, need your help again.

        I added a simple BarsSinceEntry()>10 to my Entry Condition, and when i backtest the stategie, there are no entrys. I read somewhere here on this board a few weeks ago that in backtest i have to add something to get BarsSinceEntry started. But i cant find it anymore.

        My Code:
        {
        if (BarsInProgress ==1)
        if (CrossAbove(High,Swing(Highs[0],8).SwingHigh[0],1)&&BarsSinceEntry()>10)
        EnterLong();
        }

        Comment


          #5
          You would need at least one historical entry without BarsSinceEntry to kick this into gear in your backtesting, right now your condition set would not trigger at all since BarsSinceEntry does not have reference to a prior entry.

          Comment


            #6
            So, the last two days i tried a couple of things and read through some old threads.

            So i come up with the following code, but it doesn´t work correctly. Could you please look at it.

            Now i get one entry to get it started, but my Condition with BarsSinceEntry still is not working.

            private bool tradeOnce=false;

            if (Position.MarketPosition == MarketPosition.Flat && tradeOnce == false)
            {
            EnterLong();
            tradeOnce = true;
            }

            {
            //Einstieg bei Durchbruch letztem Swing High
            if (BarsInProgress ==1)
            if (CrossAbove(High,Swing(Highs[0],8).SwingHigh[0],1)&&BarsSinceEntry()>10)
            {
            EnterLong();
            }

            }
            {
            //Ausstieg bei Unterschreiten letztem Swing Low
            if (BarsInProgress == 1)
            if (CrossBelow(Low, Swing(Lows[0],8).SwingLow[0],1))
            ExitLong();

            }

            Comment


              #7
              It's looking like your exit condition is then not triggering as expected - do you have the end of day exit set to true in the strategy options?

              I would add Prints / TraceOrders to further debug the ordering behavior and triggering of your defined conditions here:



              Comment


                #8
                i have the end of day exit set to false. i only want to close my position if the exit condition triggers.

                Comment


                  #9
                  I see, thanks - then you would need to debug why the exit condition is not triggering as you expect and thus the trade is kept open and of course no other EntryLong() occurs.

                  Comment


                    #10
                    The trade is not kept open. look at the picutre. i get an entry to get it started, and then my exit condition triggers. my problem is, i don´t get any entrys with my second entry condition as long as BarsSinceEntry()>10 is in that condition. if i remove BarsSinceEntry, then it works.

                    Comment


                      #11
                      Originally posted by mako1983 View Post
                      So, the last two days i tried a couple of things and read through some old threads.

                      So i come up with the following code, but it doesn´t work correctly. Could you please look at it.

                      Now i get one entry to get it started, but my Condition with BarsSinceEntry still is not working.
                      Maybe I am just not understanding what you are trying to do. What does BarsSinceEntry have to do with your particular ENTRY condition? BarsSinceEntry would seem to be meaningless, and incapable of evaluation, unless you have already entered a position. I think you have a circular argument which can never trigger as written.

                      From the online help:

                      BarsSinceEntry()

                      Definition
                      Returns the number of bars that have elapsed since the last specified entry.

                      Comment


                        #12
                        Hello koganam...i set entry per direction to 20. if i work without bars since entry, i will get an entry for everytime the high cross above the last swing high.(picture 1) but i only want one entry per swing high (picture 2), so i though bars since entry would help.



                        Comment


                          #13
                          Ah, that makes sense.

                          It looks like maybe your first trade is being executed against barSeries0? Have you tried executing the entire entry code sequence against barSeries1, thus:

                          Code:
                          private bool tradeOnce=false;
                          
                          if (BarsInProgress == 1)
                          {
                          if (Position.MarketPosition == MarketPosition.Flat && tradeOnce == false)
                          {
                          EnterLong();
                          tradeOnce = true;
                          }
                          
                          {
                          //Einstieg bei Durchbruch letztem Swing High
                          if (CrossAbove(High,Swing(Highs[0],8).SwingHigh[0],1)&&BarsSinceEntry()>10)
                          {
                          EnterLong();
                          }
                          
                          }
                          {
                          //Ausstieg bei Unterschreiten letztem Swing Low
                          if (CrossBelow(Low, Swing(Lows[0],8).SwingLow[0],1))
                          ExitLong();
                          }
                          }

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          663 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          376 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          110 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          575 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          580 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X