I am trying to create a custom stop variable that considers the max of a group of initialized indicators such as SMA, Swing, PSAR for example on a long:
else if (State == State.DataLoaded)
{ //Other strategy variables defined here...
LongStopLoss1 = Math.Max(Swing1.SwingLow,PSAR1,SMA1);
ShortStopLoss1 = Math.Min(Swing1.SwingHigh,PSAR1,SMA1);
}
//....define the long and short entry conditions
protected override void OnBarUpdate()
{//Define a long entry and a short entry
//Set3
if (Position.MarketPosition==MarketPosition.Long)
{if (CrossBelow(Close,LongStopLoss1))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
And do the reverse for defining a ShortStopLoss1 condition and test if Close crosses above it. Currently I couldn't get the Math.Max to work so I am getting around creating a Stop variable by testing if each indicator is crossed like this:
// Set 3
if (Position.MarketPosition==MarketPosition.Long)
{
if (CrossBelow(Close, PSAR1,1)
|| CrossBelow(Close, Swing1.SwingLow,1)
|| CrossBelow(Close, SMA1,1))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
But I get inconsistent results which trigger a close of the long in what seem like a random selection of one of the three programmed conditions and sometimes not even one of those. The Close crosses below SMA1, but is not triggered until later when Close is below PSAR1 which is not the max for example.
Any guidance on how to create a single stop variable that will be evaluated against Close and also if a symbol can be added to the chart is appreciated. Thanks!
Michael
Comment