Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Indicator as Condition for Profit

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

    Adding Indicator as Condition for Profit

    Hi,

    can you tell me is it possible in the strategy bellow to link my profit taking with the
    following condition: MACD(BarsArray[1], 12, 26, 9).Diff[0] < 0 instead with the
    existing condition execution.Order.AvgFillPrice + (profit * TickSize)



    /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
    which ensures your strategy has received the execution which is used for internal signal tracking. */
    if (entryOrder != null && entryOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    // Stop-Loss order 4 ticks below our entry price
    stopOrder = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (initialStopDistance * TickSize), "MyStop", "MyEntry");

    // Target order 8 ticks above our entry price
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (profit * TickSize), "MyTarget", "MyEntry");

    }
    }

    // Reset our stop order and target orders' IOrder objects after our position is closed.
    if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    {
    stopOrder = null;
    targetOrder = null;
    }
    }

    #2
    flexi, that would be possible yes - which order type would you want to use if the condition is fulfilled? You would not monitor for this price / indicator condition based exit though in OnExecution() but your OnBarUpdate() method then.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    78 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X