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 nuobo, Today, 07:43 PM
    0 responses
    1 view
    0 likes
    Last Post nuobo
    by nuobo
     
    Started by ETFVoyageur, Today, 02:04 PM
    3 responses
    21 views
    0 likes
    Last Post ETFVoyageur  
    Started by cre8able, Today, 06:18 PM
    0 responses
    5 views
    0 likes
    Last Post cre8able  
    Started by ETFVoyageur, Today, 06:05 PM
    0 responses
    6 views
    0 likes
    Last Post ETFVoyageur  
    Started by TAJTrades, 04-28-2024, 09:46 AM
    2 responses
    17 views
    0 likes
    Last Post TAJTrades  
    Working...
    X