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?
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();
}
