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

Reset Strategy

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

    Reset Strategy

    Hello,
    I'd like to reset the steps of my strategy after hit a stop loss, a profit target or after the end of a session .
    Please, can someone help me?
    Thanks in advance,
    Daniel

    #2
    Hi danluc,

    Thanks for posting and welcome to our forums. If you need to monitor for fill state on orders submitted with SetProfitTarget() or SetStopLoss(), the following sample can help:


    This sample can help reset values for each new trading session:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for quick answer Ryan.
      I'll try to clarify:
      My strategy has a cross above moving average looking back 8 periods and a condition with ADX looking back 5 periods (among others conditions). When the conditions are met, the strategy, for example, enter long and hit a profit target of 10 ticks. The problem is: the conditions, after profit target, are still valid and strategy will enter long again without a NEW cross above moving average because is still recognizing the cross above of 8 periods ago.
      Is it possible this kind of reset?

      Thanks

      Comment


        #4
        If the conditions are true for order submission, then it will submit orders. You need to modify your conditions so they're only true when you want to enter.

        If you only want to evaluate crossing conditions for the most current bar, set your crossing lookback to 1 instead of 8.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I have the same issue as Danluc, as explained below:

          <<My strategy has a cross above moving average looking back 8 periods... When the conditions are met, the strategy, for example, enter long and hit a profit target of 10 ticks. The problem is: the conditions, after profit target, are still valid and strategy will enter long again without a NEW cross above moving average because is still recognizing the cross above of 8 periods ago... >>

          Does anybody know if it's possible to "reset" a strategy after a stop loss or profit target is hit?

          Thank you.
          Alex

          Comment


            #6
            Hello Alex,

            Thank you for your note.

            When your conditions become true, are you submitting a enterlong call or setting a bool variable to true, for which another set of conditions are checking the value of and submitting the order?

            If you could please post the code for your entry long method that would be helpful.

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Hello Alan,

              Thanks for the fast reply.
              I'll try to explain my strategy, it is divided in two parts:

              Condition 1 : SMA20 crosses above the SMA50
              Condition 2 : Price closes above the SMA20
              If Condition 1 happens before Condition 2 (within a LookBackPeriod of 20 bars), then EnterLong.

              Condition 1 : SMA20 crosses below the SMA50
              Condition 2: Price closes below the SMA20
              If Condition 1 happens before Condition 2 (within a LookBackPeriod of 20 bars),
              then EnterShort.

              There is a Stop Loss, but no Profit Target since I simply want to Enter the opposite direction when the conditions become true.

              The problem is, when I hit a Stop Loss, the conditions are still valid and the strategy will enter the same direction again without a NEW SMA20/SMA50 cross because it is still recognizing the SMA20/SMA50 cross that happened within 20 bars ago...

              Is there a way to "Reset" my strategy when I enter long/short, so that my strategy won't consider the older cross aboves when I hit my stop loss?

              I linked a picture of my code.

              Thank in advance!
              Alex
              Attached Files
              Last edited by alexismailhot; 05-25-2018, 07:21 PM.

              Comment


                #8
                Hello alexismailhot,

                From your code snippet, it looks like if you were to set SMA20CrossAboveSma50 or priceTriggerLong to -1 after you submit your EnterLong call, then whatever it is that sets these to something other than -1, would be required to happen before the next long call. This is how you could prevent this condition remaining true.

                I have attached a screen of the variables you would want to set to -1 just below the EnterLong call.

                Please let us know if you need further assistance.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Alan,

                  Unfortunatly, this doesn't work too, because even if I set SMA20CrossAboveSma50 to -1 after the EnterLong call, SMA20CrossAboveSma50 will be re-assigned to the MRO value on the next bar update... Wich means that it won't get reset, since the MRO value will replace the -1...

                  I have attached a picture of the code and highlighted where it fails.

                  Let me know if you think of anything else, and thank you so much for your time!
                  Alex
                  Attached Files

                  Comment


                    #10
                    Hello alexismailhot,

                    If you only set SMA20CrossAboveSma50 when you're flat, this would prevent it from being reset.

                    So above where you set the value of SMA20CrossAboveSma50, have the following if statement.

                    Code:
                    if (Position.MarketPosition == MarketPosition.Flat)
                    See Market Position Section of our helpguide.



                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PaulMohn, Today, 12:36 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post PaulMohn  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    38 views
                    0 likes
                    Last Post love2code2trade  
                    Started by alifarahani, Today, 09:40 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post alifarahani  
                    Started by junkone, Today, 11:37 AM
                    3 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by frankthearm, Yesterday, 09:08 AM
                    12 responses
                    44 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X