Is it possible to set a stop loss or a trail stop equal to the output of an indicator. I'm trying to do this and in backtest, it does not work correctly.
I'm trying to set the a Variable's value equal to the indicator and then set the stop loss equal to the Variable.
This does not work as it always sets the trail stop equal to 1 tick.
Does anyone know what method I would use in the Strategy builder or what code I may try?
Thanks in advance,
dendy.
Code below:
#region Variables
// Wizard generated variables
private int sMAFast = 6; // Default setting for SMAFast
private int sMASlow = 12; // Default setting for SMASlow
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
SetTrailStop("", CalculationMode.Ticks, Variable1, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (SMA(SMAFast)[0] > SMA(SMAFast)[1]
&& SMA(SMASlow)[0] > SMA(SMASlow)[1]
&& VOLMA(12)[0] > VOLMA(12)[1]
&& ToTime(Time[0]) >= ToTime(13, 0, 0)
&& ToTime(Time[0]) <= ToTime(16, 10, 0))
{
EnterLong(DefaultQuantity, "");
Variable1 = ATRStop(12)[0];
Comment