Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Move stop loss and target with mouse

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

    Move stop loss and target with mouse

    Hi,

    I am developing an automated tsrategy wth ninjascript, when i place an order with STOPLOSS and TP i can't move them manually with mouse like when trading manually,
    so my question is how i can manage stoploss and TP manually after my automated startegy placed an order ?

    thank you in advance

    #2
    Hello pechtri,

    Thanks for your post.

    When using Set methods, orders will move back based on the strategy's Calculate mode. For example, if you use a Calculate mode of OnBarClose, the Set methods would move back to their original position on the close of a bar. Instead, you would need to use Exit methods such as ExitLongStopLimit with the isLiveUntilCanceled property set to true and ensure that your logic is only calling the Exit methods once so that the order does not reset. When the isLiveUntilCanceled property is set to true the order will NOT expire at the end of a bar but instead remain live until the CancelOrder() method is called or its time in force is reached.

    Please refer to the help guide link below regarding Exit methods and the isLiveUntilCanceled property.

    https://ninjatrader.com/support/help...gstoplimit.htm

    Also, please refer to the attached example strategy demonstrating how this could be accomplished.​
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello again,

      It works for Long position, but when i Try with Short positions i get this Errors
      i think the problem is with the stoploss , but i couldnt fix it ..
      I am using this for entry
      HTML Code:
      EnterShort("Short");
      isOrderActive = true;
      then this :

      HTML Code:
      if (Position.MarketPosition == MarketPosition.Short && isOrderActive == true)
                  {
                      ExitShortStopLimit(0, true, Position.Quantity, prevClose + (20 * TickSize), prevClose, "MyStop", "Short");
                      ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - 25 * TickSize, "MyTarget", "Short");
      
                      isOrderActive = false;
                  }​
      thank you in advance
      Attached Files
      Last edited by pechtri; 09-19-2023, 03:43 PM.

      Comment


        #4
        Hello pechtri,

        Thanks for your notes.

        The message is letting you know that buy stop or buy stop limit order was submitted to the wrong side of the market. Buy stop orders must be placed above the current ask price. Sell stop orders must be placed below the current bid price.

        If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.

        I recommend adding debugging prints to the strategy to determine why the order is being rejected. One line above where the buy stop order is placed, print the GetCurrentAsk() and print the price being submitted to the order method.

        Below is a link to a forum post that demonstrates using prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        Something you could consider is using GetCurrentBid() and GetCurrentAsk() to offset orders so that they are more likely to land on the correct side of the market.

        See these help guide pages for more information.
        GetCurrentBid(): https://ninjatrader.com/support/help...currentbid.htm
        GetCurrentAsk(): https://ninjatrader.com/support/help...currentask.htm

        You could also consider using RealtimeErrorHandling.IgnoreAllErrors to trap order errors in OnOrderUpdate.

        Please note that setting this property value to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. To do this you could trap the rejected order by checking if the OrderState is Rejected within OnOrderUpdate() followed by defining your own order rejection handling behavior for the rejected order.

        Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().

        RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm​​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        39 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X