Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

sequence of comnder OnBarUpdate()mands u

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

    sequence of comnder OnBarUpdate()mands u

    I have 2 sections under OnBarUpdate():

    1) Condition set (define conditions that have to be met to triger action)

    2) Modification of StopLoss based on market condition:
    2.1 Once the price is greater than entry price by 12%, close half the position and set stop loss to breakeven
    2.2 Resets the stop loss to the original value when all positions are closed
    Question:
    is the sequence of of 1) and 2) important or not at all? Meaning shall I first place SetStopLoss (2) under OnBarUpdate() or rather list the Condition set (1). Or maybe the sequence doesnt matter at all because they are actioned independently one from another regardless of their sequence under OnBarUpdate()?

    Example:
    OnBarUpdate()
    if (Close[0] > Position.AvgPrice * 1.12)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }

    if (ema21(21)[0] > sma89(89).Plot0[0]
    {
    EnterLong(DefaultQuantity, "");
    }

    Question:
    Is SetStopLoss actioned 1st compared to EnterLong or they ar independent one from another and doesn't affect one another in any way?
    In other words if SetStopLoss followed the EnterLong in such code would it change anything?

    #2
    Hello ionaz,

    As long as you reset after your order is filled and before a new order is place you can reset it anywhere. It is just simpler to reset the SetStopLoss() at the beginning so that way before any order an be placed it is reset.

    Since, SetStopLoss() condition is placed before EnterLong() it will be called first, but they are going to be independent of each other. It looks like you are modifying your Stop Loss so you would want to keep it before EnterLong() as you may not have an Position.AvgPrice in the same bar that you are calling your Entry signal.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    88 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    48 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    30 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    34 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    68 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X