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

SezStopLoss Position.AvgPrice

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

    SezStopLoss Position.AvgPrice

    Hallo,

    I have a problem with following code for Stoploss:

    SetStopLoss(CalculationMode.Price, Position.AvgPrice - TicksizevalueSL*TickSize);
    The code is in OnBarUpdate.

    Ticksizevalue SL is integrated in Variables:
    private int TicksizevalueSL = 30;

    NT gives following error-message:
    "Calculated stop order price for strategy 'ABODRPattern0712' was smaller/equal 0. No stop order placed."

    What ist the error?

    Thanks Blackburn

    #2
    Hello Blackburn,
    You are submitting the stop order when you are flat/entry order is yet to be filled. The Position.AvgPrice will return 0 (zero) in such scenario. A stop trigger price cannot be 0.

    You can check for a valid average price before submitting the stop.
    Code:
    if (Position.AvgPrice > 0)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - TicksizevalueSL*TickSize);
    }

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      thanks Joydeep; it works.

      Comment


        #4
        How can I reset this stoploss value?

        Comment


          #5
          Hello Blackburn,
          You can simply reassign the Set() method to modify the stop loss value

          Code:
          if (condition)
          {
            SetStopLoss(CalculationMode.Price, Position.AvgPrice - TicksizevalueSL*TickSize);
          }
          else if (condition)
          {
            //set the stop to breakeven
             SetStopLoss(CalculationMode.Price, Position.AvgPrice);
          }
          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 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
          22 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X