Programming an EA with indicators built from different timeframes
PW
No problemo...
Try something like this...
extern int MAShift = 0; extern int MAMode = 2; // 0=SMA 1=EMA 2=Smoothed 3=Linear Weighted extern int MAPeriodFast = 5; extern int MAPeriodMedium = 20; string strSymbol; // start() { strSymbol=Symbol(); //============================ INFO FROM OTHER PERIODS/INSTRUMENTS ======================================= double MA_D5_1 = iMA(strSymbol,PERIOD_D1,MAPeriodFast,MAShift,MAMode,PRICE_CLOSE,1); double MA_D5_0 = iMA(strSymbol,PERIOD_D1,MAPeriodFast,MAShift,MAMode,PRICE_CLOSE,0); double MA_D20_0 = iMA(strSymbol,PERIOD_D1,MAPeriodMedium,MAShift,MAMode,PRICE_CLOSE,0); double MA_H4_5_1 = iMA(strSymbol,PERIOD_H4,MAPeriodFast,MAShift,MAMode,PRICE_CLOSE,1); double MA_H4_5_0 = iMA(strSymbol,PERIOD_H4,MAPeriodFast,MAShift,MAMode,PRICE_CLOSE,0); double MA_H4_20_0 = iMA(strSymbol,PERIOD_H4,MAPeriodMedium,MAShift,MAMode,PRICE_CLOSE,0); //============================ INFO FROM OTHER PERIODS/INSTRUMENTS ======================================= // Do stuff here based on values collected above return(0); }
Note that using externs allows easier experimentation & optimization, plus making it easier to port blocks of code between EA's
Good Luck
-BB-
PW
No problemo...
Try something like this...
Note that using externs allows easier experimentation & optimization, plus making it easier to port blocks of code between EA's
Good Luck
-BB-
Thanks for the answer. I couldn't see the forest for the trees. I have always "0" in the PERIOD field, so I didn't realize what was it there for.
Thanks!
Hi all,
This is my first message in the forum and first of all I want to thank everyone colaborating here from the help you provide.
I'm programming an EA I want to triger orders with a doube MA cross in two different timeframes. The pseudocode looks like this:
if ( Cross(FastMA, SlowMA, last 5 bars, Timeframe1) AND Cross(FastMA, SlowMA, last5 bars, Timeframe2))
Buy
Does anyone know how to code it (in an easy way)?
Thanks in advance.