Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLoss & Profit Target

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

    StopLoss & Profit Target

    Normally I put SetProftTarget & SetStopLoss under State.Configure. However for the strategy I am working on it has multiple variations of profit targets and stop losses based on certain variables. Am I unable to use the SetProftTarget & SetStopLoss under the OnBarUpdate? I can't get it to work and I am not sure why.

    HTML Code:
    if(Position.MarketPosition == MarketPosition.Long && Trigger122BullTargets == true)
                {
                    SetProfitTarget(CalculationMode.Currency,Bull122TargetPrice);
                    SetStopLoss(CalculationMode.Currency,BullStopPrice);
                    return;
                }
                
                else if(Position.MarketPosition == MarketPosition.Long && Trigger122BullTargets == false)
                {
                    SetProfitTarget(CalculationMode.Currency,BullTargetPrice);
                    SetStopLoss(CalculationMode.Currency,BullStopPrice);
                    return;
                }​
    Instead the only way I can figure out a similar way of doing it by using the below code in OnBarUpdate. Just looking for clarification why the above code wouldn't work.
    HTML Code:
    if(Position.MarketPosition == MarketPosition.Long && Trigger122BullTargets == true)
                {
                    if(Close[0]>=Bull122TargetPrice)
                    {
                        ExitLong();
                    }
                    else if(Close[0]<BullStopPrice)
                    {
                        ExitLong();
                    }
                    return;
                }
                if(Position.MarketPosition == MarketPosition.Long && Trigger122BullTargets == false)
                {
                    if(Close[0]>=BullTargetPrice)
                    {
                        ExitLong();
                    }
                    else if(Close[0]<BullStopPrice)
                    {
                        ExitLong();
                    }
                    return;​
    Thanks

    #2
    Hello algospoke,

    SetStopLoss() and SetProfitTarget() can be called within OnBarUpdate(). These need to be called before calling an entry order method.

    Below is a link to the ProfitChaseStopTrailSetMethodsExample example which demonstrates.


    Note, the CalculationMode.Currency means you are looking for an amount of loss or gain, not a specific price.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    164 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    85 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    126 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    207 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    185 views
    0 likes
    Last Post CarlTrading  
    Working...
    X