Hello,
I want to add a gap-detection to my EA (MetaTrader 4) and am not sure how to exactly do it. The EA is very simply and compared prices X minutes ago with the current price and then trades. However, after weekend there are of course gaps in the chart, but my EA thinks it´s a breakout and opens a trade. Also, if the server of my broker loses connection for a few minutes, those gaps can also occure and my EA again thinks, when re-connected, a breakout has occured. How can I stop that? Would really like to see some code posted. My idea was something like comparing the current (Server) minute with the previous (Server) minute and if there is a difference of the current (Server) minute and previous (Server) minute +1, return(0). However, when the hour changes, this won´t work (59 to 00). Thanks in advance for any help.
datetime current_time=iTime(Symbol(), 1, 0); datetime past_time=iTime(Symbol(),1,1); if((current_time-past_time)>.......){return(0);}
those gaps can also occure and my EA again thinks, when re-connected, a breakout has occured. How can I stop that?
extern int Gap.Min.Pips = 10; int init(){ OnInitGapDetect(); : } int start(){ int iGap = iBarShift(NULL,0, OnTickGapDetect()); : } #define GD_LOOK_BACK 1 int GDbarsCounted; void OnInitGapDetect(){ GDbarsCounted = GD_LOOK_BACK; } datetime OnTickGapDetect(){ double gapMin = Gap.Min.Pips * pips2dbl; static datetime timeLastGap; for(int iBar = Bars - 1 - GDbarsCounted; iBar >= 0; iBar--){ double gapSize = MathAbs( Close[iBar+GD_LOOK_BACK] - Open[iBar] ); if (gapSize >= gapMin){ timeLastGap = Time[iBar]; } } GDbarsCounted = Bars; // Looked at all return(timeLastGap); }Typed, not compiled, not tested.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I want to add a gap-detection to my EA (MetaTrader 4) and am not sure how to exactly do it. The EA is very simply and compared prices X minutes ago with the current price and then trades. However, after weekend there are of course gaps in the chart, but my EA thinks it´s a breakout and opens a trade. Also, if the server of my broker loses connection for a few minutes, those gaps can also occure and my EA again thinks, when re-connected, a breakout has occured. How can I stop that? Would really like to see some code posted. My idea was something like comparing the current (Server) minute with the previous (Server) minute and if there is a difference of the current (Server) minute and previous (Server) minute +1, return(0). However, when the hour changes, this won´t work (59 to 00). Thanks in advance for any help.