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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X