Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss Issue

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

    Stop Loss Issue

    Hey! I'm very new to coding, so bare with me. This feels like an easy issue to solve but for some reason I can't seem to figure it out.

    My Goal: To have my initial stop loss set at the previous candle low, and move to breakeven when I'm 10 ticks in profit, and be set there the remainder of the trade.

    My Issue: In order for my stop loss to move to BE, I have to have the Strategy setup to calculate "On each tick". However, when I set the strategy to "On each tick", the initial stop loss doesn't even show up.

    I'm assuming the issue is because the Method I have both stops in is OnBarUpdate() ?
    Again, I'm extremely new to this so any insight or help is much appreciated.

    Here's a look at the code
    Click image for larger version

Name:	Screenshot (592).png
Views:	260
Size:	265.7 KB
ID:	1177839

    #2
    Hello perrytradez,

    Thanks for your question.

    When processing OnEachTick or OnPriceChange BarsAgo 0 references will represent the developing bar, when using OnBarClose, BarsAgo 0 references reflect the bat that had just closed.

    Also keep in mind that when using Calculate.OnEachTick and OnPriceChange, historical data is still going to be processed following OnBarClose behaviors. Once the strategy starts processing realtime data, it will then be cable to process following OnEachTick or OnPriceChange behaviors.

    Something else to keep in mind is that if a stop loss is submitted to the other side of the market (If Low[0] reflects a price level that ends up being on the other side of current bid/ask prices when the order is processed) the order would be rejected. When processing historical data, rejected orders are ignored.

    You could consider triggering your entry condition for a check of IsFirstTickOfBar so the entry happens on bar closes, and to change the Low[0] reference to Low[1], so it reflects the previous bar's low, after we get the first tick of a new bar. Otherwise, you could consider comparing Low[0] to GetCurrentBid, to make sure Low[0] is less than the current bid price and would be valid for a Sell Stop Market Order. You can also consider using GetCurrentAsk/GetCurrentBid to offset your initial stop at a greater distance if Low is not a valid price for the stop loss.

    IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

    GetCurrentAsk - https://ninjatrader.com/support/help...currentask.htm

    GetCurrentBid - https://ninjatrader.com/support/help...currentbid.htm

    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    24 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    120 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 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
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X