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 charlesugo_1, 05-26-2026, 05:03 PM
0 responses
56 views
0 likes
Last Post charlesugo_1  
Started by DannyP96, 05-18-2026, 02:38 PM
1 response
143 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by CarlTrading, 05-11-2026, 05:56 AM
0 responses
160 views
0 likes
Last Post CarlTrading  
Started by CarlTrading, 05-10-2026, 08:12 PM
0 responses
96 views
0 likes
Last Post CarlTrading  
Started by Hwop38, 05-04-2026, 07:02 PM
0 responses
276 views
0 likes
Last Post Hwop38
by Hwop38
 
Working...
X