Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Conditional Stop-Loss query

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

    Conditional Stop-Loss query

    Hi,

    I was wondering if it is possible to program a stop-loss that activates only if volatility rises above a certain level. Basically I am running a strategy with the following stop-loss programmed in the Initialize() section: SetStopLoss("", CalculationMode.Ticks, stop, true);

    This works fine, however I noticed that in low volatility days I am often stopped out despite no real trend talking place. Is it possible to apply a volatility filter so that the stop-loss is only activated when standard deviation is above a certain threshold? would this need to be programmed in the OnBarUpdate() section? If yes, would the following code make the trick?

    Code:
      
           protected override void Initialize()
            {
                Add(PeriodType.Day, 1);
                CalculateOnBarClose = true;
                EntryHandling     =    EntryHandling.UniqueEntries;
                ExitOnClose = false;
            }
            protected override void OnBarUpdate()
            {
                [B]//Enter long condition with volatility filter[/B]
                if (CrossAbove(...)
                    && ATR(BarsArray[1],atrlength)[0] >= 1.5)
                {
                    EnterLong();
                    SetStopLoss("", CalculationMode.Ticks, stop, true);
                }
    
               [B] //Enter long condition[/B]
                if (CrossAbove(...)
                {
                    EnterLong();
                }

Latest Posts

Collapse

Topics Statistics Last Post
Started by CarlTrading, 03-31-2026, 09:41 PM
1 response
67 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by CarlTrading, 04-01-2026, 02:41 AM
0 responses
36 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 03-31-2026, 11:44 PM
0 responses
60 views
1 like
Last Post CaptainJack  
Started by CarlTrading, 03-30-2026, 11:51 AM
0 responses
62 views
0 likes
Last Post CarlTrading  
Started by CarlTrading, 03-30-2026, 11:48 AM
0 responses
53 views
0 likes
Last Post CarlTrading  
Working...
X