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

NinjaScript Custom Trailing Stop Issue

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

    NinjaScript Custom Trailing Stop Issue

    Hello,
    I'm trying to understand why my NinjaScript strategy isn't functioning. The goal is for the stop to move 3 ticks above or below a favorable bar in the direction of the trade after a manually entered trade - so essentially a trailing stop loss but based on the bar and bar-type.

    I was having some issues initializing the stopOffset in OnStateChange() so I moved it to OnBarUpdate() - not sure if that's appropriate. Once I add the strategy to my chart, nothing happens once the conditions are met.
    Attached Files

    #2
    Hello majin_bo,

    Thanks for your post.

    I do not see where you are placing an entry order anywhere in the code you shared.

    SetStopLoss() preps NinjaTrader to submit a protective order when an entry order placed by the strategy is filled.

    Does your strategy call any Entry order methods, such as EnterLong(), to place an entry order from the strategy?

    Note that custom NinjaScript strategies cannot see manually placed orders or orders placed by other strategies. They are only able to see the orders submitted by that specific strategy instance.

    Here is a reference sample you could view demonstrating modifying the price of stop loss and profit target orders in NinjaScript: https://ninjatrader.com/support/help...of_stop_lo.htm

    And, my colleague Chelsea has created educational examples of Strategy Builder breakeven and trailing stop in the Strategy Builder here for you to view:


    Below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040


    Further, to understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121​​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I didn't realize the entry had to be placed within the script as well. That's all I need for now, thank you for the response and the resources you posted.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AaronKoRn, Today, 09:49 PM
      0 responses
      6 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Today, 08:42 PM
      0 responses
      9 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Today, 07:51 PM
      0 responses
      10 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,976 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Today, 06:48 PM
      0 responses
      9 views
      0 likes
      Last Post rbeckmann05  
      Working...
      X