Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss with variable

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

    stoploss with variable

    Hello,

    I can´t get it how to amend the conditons for a variable. My variable for stops at entry works fine with closed reversal bars (eg for short trades)

    cthigh=MAX(High, 2)[0] + (3*TickSize);

    but for entries before the current reversal bar is closed there can occur - of course - a stopout when the MAX of the closed bars ([0] and [1] is lower than the entry price in the revesal bar.

    How can I add to my condition with MAX to have the "MAX (of the last 2 bars and above eg 8 ticks above current price of the bar that is not closed yet)"?

    (There are reasons why I do not with simple setstoploss and distance in ticks)

    Thank you
    Tony
    Last edited by tonynt; 01-24-2014, 11:04 AM. Reason: clearify

    #2
    Hello Tony,

    Thank you for your post.

    You would want to use almost the same setup as you had done with the cthigh.

    However, I'm little confused on the the MAX(2 bars ago and 8 ticks above)

    Can you please elaborate more?
    Last edited by NinjaTrader_CalH; 01-24-2014, 11:39 AM.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. Usually it works fine with the MAX() I have posted. But it works fine only if the entry occurs at close of my key-reversalbar.

      But when I want to do the entry already before the close of the keyreversalbar then it can occur that its stopped out immediately because eg for a long the MIN(Low, 2)[0]) can be higher than the current entry price to cause an immediate stopout.

      Therefore I need to add to my variable so that the stop is the MIN of both, the MIN(Low, 2)[0]) and the current entryprice - some ticks (to avoid to be stopped out immediately and to have a stop for entry at close of bar and before close of bar.

      I hope I could explain better now.

      Thanks
      Tony


      Originally posted by NinjaTrader_Cal View Post
      Hello Tony,

      Thank you for your post.

      You would want to use almost the same setup as you had done with the cthigh.

      However, I'm little confused on the the MAX(2 bars ago and 8 ticks above)

      Can you please elaborate more?
      Last edited by tonynt; 01-24-2014, 04:14 PM. Reason: typing error

      Comment


        #4
        Tonynt,

        Based on what you are already doing with -

        cthigh=MAX(High, 2)[0] + (3*TickSize);

        You would want to apply that same functionality to your stop loss.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for your reply. Yes, this is what I´m asking for: how to add to the stopvariable so that it is the MAX of both
          cthigh=MAX(High, 2)[0] + (3*TickSize); && cthigh>= currentask()+8*TickSize
          SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);

          Thank you
          Tony

          Originally posted by NinjaTrader_Cal View Post
          Tonynt,

          Based on what you are already doing with -

          cthigh=MAX(High, 2)[0] + (3*TickSize);


          You would want to apply that same functionality to your stop loss.

          Comment


            #6
            Originally posted by tonynt View Post
            Hello,

            thank you for your reply. Yes, this is what I´m asking for: how to add to the stopvariable so that it is the MAX of both
            cthigh=MAX(High, 2)[0] + (3*TickSize); && cthigh>= currentask()+8*TickSize
            SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);

            Thank you
            Tony
            You would want to set the variable cthigh with MAX(High, 2)[0] + (3 * TickSize);

            You would then use the rest of that-
            cthigh>= currentask()+8*TickSize

            as your condition to test the value of cthigh against what you looking for.
            If its true then in the IF statement you would set the Stop Loss

            SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);

            Code:
            cthigh=MAX(High, 2)[0] + (3*TickSize); 
            
            if(cthigh>= currentask()+8*TickSize)
            {
                SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);
            }
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              thank you for your reply.

              But if it is not > current+8tick then there will not be a stoploss at the entry?

              I understand your suggestion that the stop is only when both true(?)

              The stop should be at the max of the both values in every case.

              Please correct me if I´m wrong. Thank you!

              Best regards
              Tony

              Originally posted by NinjaTrader_Cal View Post
              You would want to set the variable cthigh with MAX(High, 2)[0] + (3 * TickSize);

              You would then use the rest of that-
              cthigh>= currentask()+8*TickSize

              as your condition to test the value of cthigh against what you looking for.
              If its true then in the IF statement you would set the Stop Loss

              SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);

              Code:
              cthigh=MAX(High, 2)[0] + (3*TickSize); 
              
              if(cthigh>= currentask()+8*TickSize)
              {
                  SetStopLoss("Sr3a", CalculationMode.Price, cthigh, false);
              }

              Comment


                #8
                Originally posted by tonynt View Post
                But if it is not > current+8tick then there will not be a stoploss at the entry?
                Correct, if you want to place a different stop loss when that condition is not true, then you would need to set up another condition after the first one for a back scenario

                Originally posted by tonynt View Post
                I understand your suggestion that the stop is only when both true(?)
                Not sure what you mean here. There is only one condition being tested.

                Originally posted by tonynt View Post
                The stop should be at the max of the both values in every case.
                What other values are involved here? There is only one that is being set and then testing that price against the "currentask()+8*TickSize"
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Cal,

                  this way you don´t have a stop when both conditions !=true? you would do an entry with this stop?

                  I try it again, different way:

                  cthigh1=MAX(High, 2)[0] + (3*TickSize);
                  cthigh2=currentaks()+(8*TickSize);

                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  if(cthigh1>= cthigh2)
                  {SetStopLoss("Sr3a", CalculationMode.Price, cthigh1, false);}

                  else if(cthigh2 > cthigh1)
                  {SetStopLoss("Sr3a", CalculationMode.Price, cthigh2, false);}
                  }

                  else if (Position.MarketPosition == MarketPosition.Short)
                  {
                  if(GetCurrentBid() >= Position.AvgPrice + (8*TickSize))
                  {then do...
                  }

                  Does this make sense?

                  I meant if it is possible to have the max of cthigh1and cthigh2 in one Max() to have this code in a simplier and clear solution.

                  Thanks
                  Tony





                  Originally posted by NinjaTrader_Cal View Post
                  Correct, if you want to place a different stop loss when that condition is not true, then you would need to set up another condition after the first one for a back scenario


                  Not sure what you mean here. There is only one condition being tested.


                  What other values are involved here? There is only one that is being set and then testing that price against the "currentask()+8*TickSize"

                  Comment


                    #10
                    Tony,

                    No, you would not be able to do this as you want for your code.

                    The method you have set up is going to be the proper way for your needs
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by tonynt View Post
                      Cal,

                      this way you don´t have a stop when both conditions !=true? you would do an entry with this stop?

                      I try it again, different way:

                      cthigh1=MAX(High, 2)[0] + (3*TickSize);
                      cthigh2=currentaks()+(8*TickSize);

                      if (Position.MarketPosition == MarketPosition.Flat)
                      {
                      if(cthigh1>= cthigh2)
                      {SetStopLoss("Sr3a", CalculationMode.Price, cthigh1, false);}

                      else if(cthigh2 > cthigh1)
                      {SetStopLoss("Sr3a", CalculationMode.Price, cthigh2, false);}
                      }


                      else if (Position.MarketPosition == MarketPosition.Short)
                      {
                      if(GetCurrentBid() >= Position.AvgPrice + (8*TickSize))
                      {then do...
                      }

                      Does this make sense?

                      I meant if it is possible to have the max of cthigh1and cthigh2 in one Max() to have this code in a simplier and clear solution.

                      Thanks
                      Tony
                      Are you asking about the part that I have emphasized in red?

                      In that case, it can be written:
                      Code:
                      if (Position.MarketPosition == MarketPosition.Flat)
                      {
                           SetStopLoss("Sr3a", CalculationMode.Price, [B][COLOR=Blue]Math.Max(cthigh1, cthigh2)[/COLOR][/B], false);
                      }

                      Comment


                        #12
                        koganam,

                        thank you very much for your reply! A forum is as good as members like you!

                        Wish you a great day!

                        Best regards
                        Tony

                        Originally posted by koganam View Post
                        Are you asking about the part that I have emphasized in red?

                        In that case, it can be written:
                        Code:
                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
                             SetStopLoss("Sr3a", CalculationMode.Price, [B][COLOR=Blue]Math.Max(cthigh1, cthigh2)[/COLOR][/B], false);
                        }

                        Comment


                          #13
                          koganam,

                          I set the stops referring to your hint - thank you again - but I seems there is something wrong (I do something wrong)

                          I have
                          ctlow1=MIN(Low, 2)[0] - (3*TickSize);
                          ctlow2=GetCurrentAsk()-(10*TickSize);

                          and
                          SetStopLoss("Lr3a", CalculationMode.Price, Math.Min(ctlow1, ctlow2), false);
                          SetStopLoss("Lr3b", CalculationMode.Price, Math.Min(ctlow1, ctlow2), false);

                          In the attached screenshot there is the stop at 114,18 (10 pips below entry price) but it should be at 114,12 (3 Pips below the low of the green bar) because this is min and also lower than the entry-10 pips, no?

                          Thank you so much!

                          Best regards
                          Tony
                          Attached Files

                          Comment


                            #14
                            Originally posted by tonynt View Post
                            koganam,

                            I set the stops referring to your hint - thank you again - but I seems there is something wrong (I do something wrong)

                            I have
                            ctlow1=MIN(Low, 2)[0] - (3*TickSize);
                            ctlow2=GetCurrentAsk()-(10*TickSize);

                            and
                            SetStopLoss("Lr3a", CalculationMode.Price, Math.Min(ctlow1, ctlow2), false);
                            SetStopLoss("Lr3b", CalculationMode.Price, Math.Min(ctlow1, ctlow2), false);

                            In the attached screenshot there is the stop at 114,18 (10 pips below entry price) but it should be at 114,12 (3 Pips below the low of the green bar) because this is min and also lower than the entry-10 pips, no?

                            Thank you so much!

                            Best regards
                            Tony
                            Hard to say without knowing the details of your entry. You may want to Print() out the values, to be sure. Remember that you are using CurrentAsk, which can be a considerable spread away from Close[0], as it depends on the bid/ask spread on the particular instrument. In this particular instance a bid/ask spread of 3 units will probably mean that the values are actually equal.

                            Comment


                              #15
                              koganam,

                              thank you again for your reply.

                              The entry is at my black dashed line in the range chart. As one condition of the stop is Min(low)2, so the stop should be in every case below the Min of the green upbar (which is the lowest), no? Is the spread then important to determine the stop?

                              Thank you
                              Tony

                              Originally posted by koganam View Post
                              Hard to say without knowing the details of your entry. You may want to Print() out the values, to be sure. Remember that you are using CurrentAsk, which can be a considerable spread away from Close[0], as it depends on the bid/ask spread on the particular instrument. In this particular instance a bid/ask spread of 3 units will probably mean that the values are actually equal.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,279 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              51 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Working...
                              X