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 Davide999, 05-18-2023, 03:55 AM
    4 responses
    554 views
    1 like
    Last Post kcwasher  
    Started by Stanfillirenfro, Today, 07:23 AM
    2 responses
    9 views
    0 likes
    Last Post Stanfillirenfro  
    Started by rexsole, Today, 08:39 AM
    2 responses
    6 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    6 responses
    29 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by gbourque, Today, 06:39 AM
    2 responses
    14 views
    0 likes
    Last Post gbourque  
    Working...
    X