I am trying to make a stop loss and take profit targets dynamic based on values of a specified average true range. I'd like to include max and min values for the ATR, thus keeping my stop sizes and take profits from being too large or too small. I keep getting this CS0103 error though. I'm not sure why as it seems like the for block I have to set ATR_Stop defines the value, so I am confused as to why I cannot call the value later in the code as a reference for my stop loss value. Any help here would be greatly appreciated.
The variable that is tripping me up is 'ATR_Stop'
// Set ATR max and min
bool ATR_middle = ATR(20)[0] >= 1.5 && ATR(20)[0] <= 5;
bool ATR_min = ATR(20)[0] < 1.5;
bool ATR_max = ATR(20)[0] > 5;
if (ATR_middle)
{
double ATR_Stop = ATR(20)[0];
}
else if (ATR_min)
{
double ATR_Stop = 1.5;
}
else
{
double ATR_Stop = 5;
}
// Enter Long Positions
if (trade_times && upper_threshold)
{
if (cross_above)
{
EnterLong("LongPosition");
// Sets Stop-Loss
SetStopLoss("LongPosition", CalculationMode.Price, Closes[0][0] - (atrMultiplierStop * ATR_Stop), false);
// Sets Take-Profit
SetProfitTarget("LongPosition", CalculationMode.Price, Closes[0][0] + (atrMultiplierProfit * ATR_Stop), false);
}
}
// Exit Positions
if (!market_hours)
{
ExitLong();
ExitShort();
}
}
region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="FastMA", Order=1, GroupName="Parameters")]
public int FastMA
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="MidMA", Order=2, GroupName="Parameters")]
public int MidMA
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="SlowMA", Order=3, GroupName="Parameters")]
public int SlowMA
{ get; set; }
#endregion
}
}
Comment