Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

waiting one bar before entering

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

    waiting one bar before entering

    ​Hi i am trying to figure out what i am doing wrong but i need to make sure next trade will be at least 1 bar, but since this strategy on firstickofbar should it use 2 instead of 1 on both equasions?
    There seems to be a wrong syntax here..

    && (BarsSinceExitExecution("34B Short") > 1 || BarsSinceExitExecution("34B Short") == -1)
    && (BarsSinceExitExecution("34B Long") > 1 || BarsSinceExitExecution("34B Long") == -1)

    EnterShort(PositionSize, "34B Short");
    SetParabolicStop("34B Short", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);


    Click image for larger version

Name:	image.png
Views:	123
Size:	46.5 KB
ID:	1258107

    #2
    Hello tkaboris,

    Thanks for your post.

    This would be the correct use of BarsSinceExitExecution() to have the strategy wait at least 1 bar before the Entry method is called.

    See this help guide page for more information about BarsSinceExitExecution() and sample code: https://ninjatrader.com/support/help...lightsub=barss inceexit

    Note that Set methods prep NinjaTrader to submit a protective order upon the fill of an entry so SetParabolicStop() should be called before the EnterShort() method.

    For example:

    SetParabolicStop("34B Short", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);
    EnterShort(PositionSize, "34B Short");

    If the strategy is not behaving as expected, debugging prints should be added to the script to understand how it is behaving and placing orders.

    ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, last question, is it possible to set ParabolilcSarSL just above the previous bar high/low? or it wont work with setparabolicstop method...?
      SetParabolicStop("34B Short", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);

      Comment


        #4
        Hello tkaboris,

        Thanks for your notes.

        The SetParabolicStop() method's value parameter determines the value the trailing stop order is offset from the position entry price.

        When using CalculationMode.Ticks, the value parameter would be the number of ticks you want to offset the stop loss order from the entry order.

        This means ParabolicSarSL would need to be the number of ticks you want to place the stop loss away from the entry, not the price (such as Low[0] + 1 * TickSize) you want to submit the order to. For example, you could use a value of 10 to place the stop loss 10 ticks away from the entry order.

        See this help guide page for more information about SetParabolicStop(): https://ninjatrader.com/support/help...abolicstop.htm
        Last edited by NinjaTrader_BrandonH; 06-29-2023, 09:36 AM.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          HI can you please help me even though it seems that i use right syntax my strategy still doesnt wait 2 bars for next execution. I dont know what to print to find out..

          && (BarsSinceExitExecution("34B Short") > 1 || BarsSinceExitExecution("34B Short") == -1)
          && (BarsSinceExitExecution("34B Long") > 1 || BarsSinceExitExecution("34B Long") == -1)​

          EnterShort(PositionSize, "34B Short");

          if (UseFixedSL)
          {
          ExitShortStopMarket(0, true, Position.Quantity, stopShort, "SLS", "34B Short");

          }

          if (UseFixedTP)
          {
          ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (TickSize * ProfitTargetTicks), "PTS", "34B Short");

          }​

          Click image for larger version

Name:	image.png
Views:	107
Size:	45.1 KB
ID:	1258260

          Comment


            #6
            Hello tkaboris,

            Thanks for your notes.

            "...still doesnt wait 2 bars for next execution"

            Currently, your condition is set up to wait for at least 1 bar has passed since your exit execution occurs. This means that if at least 1 bar has passed, the Entry method could be triggered to submit an order.

            If you would like to have the script wait for at least 2 bars to pass since your last exit, you could compare BarsSinceExitExecution() > 2.

            One line above your condition to place the entry order you should print out BarsSinceExitExecution("34B Short") and BarsSinceExitExecution("34B Long") to understand how those conditions are evaluating in that condition.

            Note that BarsSinceExitExecution() returns the number of bars that have passed since your last execution.

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
            https://ninjatrader.com/support/foru...121#post791121
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              HI i did added to both longs and shorts and I only get prints -1, before and after strategy takes a trade.
              if (shortsOn)
              Print(BarsSinceExitExecution("34B Short"));
              Print(BarsSinceExitExecution("34B Long"));
              {​

              -1
              -1
              -1
              -1
              -1
              -1
              -1
              -1​
              Last edited by tkaboris; 06-29-2023, 12:52 PM.

              Comment


                #8
                Hello tkaboris,

                Thanks for your notes.

                A BarsSinceExitExecution() print of -1 means that a previous exit does not exist for those signal names "34B Short" and "34B Long". Note that the signal name passed into this method should be the signal name of the exit order, not the signal name of the entry order.

                From the BarsSinceExitExecution() help guide page: "An int value that represents a number of bars. A value of -1 will be returned if a previous exit does not exist."

                BarsSinceExitExecution(): https://ninjatrader.com/support/help...texecution.htm

                If your exit order signal name is "SLS" or "PTS", this is the signal name that should be used in the BarsSinceExitExecution() method.

                If you are using SetParabolicStop() for your exit orders then the signal name of "Parabolic stop" should be passed into BarsSinceExitExecution() instead of "34B Short" and "34B Long".

                From the SetParabolicStop() help guide: "The signal name generated internally by this method is "Parabolic stop" which can be used with various methods such as BarsSinceExitExecution(), or other order concepts which rely on identifying a signal name​."

                SetParabolicStop(): https://ninjatrader.com/support/help...abolicstop.htm
                Last edited by NinjaTrader_BrandonH; 06-29-2023, 01:20 PM.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  ok i think it was my probelm, i was entring signal name from entry. So if my exit orders are below, depending on what is selected I should use
                  (BarsSinceExitExecution("SLL")
                  (BarsSinceExitExecution("PTL")
                  (BarsSinceExitExecution("Parabolic Stop Long")

                  34B Long is the entry name when i enter long.


                  ExitLongStopMarket(0, true, Position.Quantity, stopLong, "SLL", "SR3 Long");
                  ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "SR3 Long");
                  SetParabolicStop("Parabolic Stop Long", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);

                  Comment


                    #10
                    Hello tkaboris,

                    Thanks for your notes.

                    Yes, that is correct. The Exit order signal names should be used for BarsSinceExitExecution(), not the Entry order signal name.

                    This is because BarsSinceExitExecution() looks for the last exit order that occurred so you would need to provide the Exit order's signal name in that method.

                    Note that the signal name of SetParabolicStop() will be "Parabolic stop", not "Parabolic Stop Long".

                    From the SetParabolicStop() help guide: "The signal name generated internally by this method is "Parabolic stop" which can be used with various methods such as BarsSinceExitExecution(), or other order concepts which rely on identifying a signal name​."
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok thank you, its clear but one thing.
                      In my strategy i get to choose how to place order either with parabolic or fixed stop and profit.. Its clear with fixed Stop loss and fixed take profit. but with parabolic its not.
                      If i enter long like this
                      EnterLong(PositionSize, "34B Long");

                      Then if i pass "Parabolic stop" as name, like below, the strategy will not know which parabolicstop it is.
                      SetParabolicStop("ParabolicStop", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);

                      it seems it should be as follows for parabolic order
                      SetParabolicStop("34B Long", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);


                      (BarsSinceExitExecution("ParabolicStop") > 2 || BarsSinceExitExecution("ParabolicStop") == -1)
                      Can you please clarify?
                      Which way would be correct for parabolic?

                      Comment


                        #12
                        Hello tkaboris,

                        Thanks for your note.

                        The signal name of SetParabolicStop() is "Parabolic stop" and the signal name cannot be changed to a unique name.

                        You would pass in the Entry order signal name to the fromEntrySignal parameter of the SetParabolicStop() method, such as SetParabolicStop("34B Long", CalculationMode.Ticks, ParabolilcSarSL, false, 0.02, 0.2, 0.02);

                        The BarsSinceExitExecution() syntax for detecting a SetParabolicStop() order would be BarsSinceExitExecution("Parabolic stop") > 2 || BarsSinceExitExecution("Parabolic stop") == -1

                        See the SetParabolicStop() and BarsSinceExitExecution() help guide pages linked on post Private Messages for more information.
                        Brandon H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Jonafare, 12-06-2012, 03:48 PM
                        5 responses
                        3,986 views
                        0 likes
                        Last Post rene69851  
                        Started by Fitspressorest, Today, 01:38 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Fitspressorest  
                        Started by Jonker, Today, 01:19 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Jonker
                        by Jonker
                         
                        Started by futtrader, Today, 01:16 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post futtrader  
                        Started by Segwin, 05-07-2018, 02:15 PM
                        14 responses
                        1,792 views
                        0 likes
                        Last Post aligator  
                        Working...
                        X