Hey guys, hope you're doing well.
I'm trying to test a sell rule where as longer moving averages move above my buy price - I change my sell strategy to a close below them. So starts on a fast moving average and then a slow one.
I've tried to code this condition using the IIF statements as my understanding is they are used for arrays instead of if else statements.
I have done this in two separate ways, both seem to not work and I'm not sure where I am going wrong. I can successfully code this strategy using two moving averages and the one if statement. However, when I try to include more than one if statement it gets messy and not sure why.
Any help would be appreciated,
The two different coding methods below I have tried.
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);
Condition1 C>=HHV(250);
MA10sell = C < MA(C,10);
MA20sell = C < EMA(C,20);
MA50sell = C < MA(C,50);
MA200Sell =C < MA(C,200);
Buy = Condition1 ;
Sellarray3 = IIf(EMA(C,20)>=Buy,MA20Sell,MA10Sell);
Sellarray2 = IIf(MA(C,50)>=Buy,MA50Sell,Sellarray3);
Sellarray1 = IIf(MA(C,200)>=Buy,MA200Sell,sellarray2);
Sell = Sellarray1;
2nd style below,
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);
Condition1 = C >= HHV(C,250);
MA10sell = C < MA(C,10);
MA20sell = C < MA(C,20);
MA50sell = C < MA(C,50);
MA200Sell = C < MA(C,200);
Buy = Condition1 ;
Sell = iif(MA(C,200)>=Buy,MA200sell,iif(MA(C,50)>=Buy,MA50Sell,iif(MA(C,20)>=Buy,MA20Sell,MA200sell)));