Hi all,
apologies if this is a basic question that was answered before, but I am trying to create a strategy that enters long/short depending on Fib retracement crossings and MA and am struggling to find the right code.
Basically, I am defining 20 conditions (10 for long, 10 for short). 1 and 11 are conditions that I always want to be met (c1 for long, c11 for short). For long entry, I want c1 AND either of c2-c10 met, for short c11 AND either of c12-20. I have tried everything from using OR, ELSIF or separate IF ENDIF statements but nothing works.
Does anyone know how to write this?
Thanks a lot in advance! 🙂
You would need to post your code else we all be guessing what / how you have coded.
Absolutely, makes sense! I found my mistake myself, the answer is to include the AND statement in the condition definition itself before starting IF statement. At least it works for me now. Example below:
// Conditions to enter long positions
indicator1 = Average[100](close)
c1 = (close > indicator1)
// c2 as indicator2 AND c1
indicator2 = (((DHigh(1) + DLow(1) + DClose(1))/3 – (DHigh(1)-DLow(1)))+((DHigh(1) + DLow(1) + DClose(1))/3 – (.618 * (DHigh(1)-DLow(1))))) /2
c2 = (close CROSSES OVER indicator2 AND c1)
Make sure you test your strategy on Demo Account ONLY until you are happy it makes money on a regular basis / over 50 to 100 trades at least!
There you go (you may also add Not Onmarket + Trading hours and Days to General Conditionms):
GeneralConditions = c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 AND c9 AND c10
LongConditions = GeneralConditions AND c1
ShortConditions = GeneralConditions AND c11
IF LongConditions THEN
BUY 1 Contract at Market
ELSIF ShortConditions THEN
SELLSHORT 1 Contract at Market
ENDIF