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

SetStopLoss not triggering

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

    #16
    Hello,

    Thank you for the reply.

    Could you provide an export of the script as you have it currently any provide the output you had seen for the prints?

    I would like to review the script further to see what may be happening, if you could also provide any settings the script needs and instrument/timeframe tested on that would be helpful.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #17
      Jesse,
      I'm including the sample script and an image which doesn't show much since there weren't any exits, except at the end of the day. I tested with a 2 minutes TF.

      Besides testing exits with Close[0]< (Close[0]-2*ATR(3)[0]), I also used CrossAbove/CrossBelow with the same negative results. Again, the "Print" of the values are consistent, just that at time of entries/exits they seem false values.

      Thanks for all the assistance.
      Attached Files

      Comment


        #18
        Hello,

        I tried this on and around the time in the image and do see that no exit conditions were true.

        I looked at the Prints you had added and used the same ones and received no output where the Close was less than the calculated value.

        One way to see this would be to use the following print, which showed me zero results:
        Code:
        if(Close[0]<(Close[0]-2*ATR(3)[0]))
        	Print(Close[0] + " < " + (Close[0]-2*ATR(3)[0]));

        I had also tried changing the condition to see if exits occurred:

        Code:
        Close[0]>(Close[0]-2*ATR(3)[0]
        This resulted in exits happening, I believe you would need to reevaluate the equations you are using to see why the exit is not happening.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #19
          Jesse,
          Thanks for taking the time to look into this. I am trying to understand this from a simpler perspective. I will use the Parabolic SAR as a comparison where candles are blue when they are above, else blank. I have included an image showing that it is consistent with:
          Code:
          protected override void OnBarUpdate()
                  {
                      if (Close[0]>ParabolicSAR(0.02, 0.2, 0.02)[0] )
                      {
                          if (colorBars ) 
                          {
                              BarColor           = Color.Blue;
                          }
                      }
                  }
          Following, I have replaced the PSAR with the ATR Trailing Stop where candles are blue when above the trailing stop, else blank. The output window printout shows consistent values with the trailing stop indicator, but now all the candles are blue (see image).
          Code:
          protected override void OnBarUpdate()
                  {
                      if (Close[0]>(Close[0]-2*ATR(3)[0]) )
                      {
                          if (colorBars ) 
                          {
                              BarColor           = Color.Blue;
                          }
                      }
          In reversing the equation to
          Code:
          if (Close[0]<(Close[0]-2*ATR(3)[0]) )
          all the candles are blank.

          Therefore, why the values from the output window are true and valid, but at the time of execution (candles being colored) the values are viewed as false? What and where am I missing out?
          Attached Files

          Comment


            #20
            Hello,

            I had not seen any values become true while using Less than, I had noted this previously:
            I looked at the Prints you had added and used the same ones and received no output where the Close was less than the calculated value.
            Because I had not seen the value become Less than the condition value, I had expected no exits to be placed. If you are getting some cases where the numbers are equal and not equating true, you would need to instead use Less than Or Equal to: <=

            Could you provide a specific scenario for me to run the script and see the result you are or where the output window shows True but the condition had not become true? Also could you provide the output you see, that could me help understand what you are seeing better.

            I look forward to being of further assistance
            JesseNinjaTrader Customer Service

            Comment


              #21
              Jesse, thanks for all the help. I finally was able to get it to work.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              57 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              20 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              9 views
              0 likes
              Last Post cre8able  
              Working...
              X