jackee1234:
You are not cleaning up (setting to empty value) the CrossedUP and CrossedDown buffers before assigning values to them in the indicator. That can cause you a classical case of repainting and that, in return, can cause the issues you have from the eaWhen I use the custom indicator, it shows the graph as follows
When I use the Expert Advisor with the custom indicator, it shows the following
It also repeated opened a lot of custom indicator when I am doing backtesting.
How should I change the EA such that
It only opened a custom indicator;
It plot the same graph as the custom indicator?
Below is the code for custom indicator (HitBollingerBand1.mq4)
Below is the code of EA makes use of the custom indicator (only the essential parts - the code is runnable) (HitBollingerBandEA.mq4)
Thanks, how do I make sure that it only opens an instance of indicator rather than opened huge amount instances of indicators after each call of start() in EA?
jackee1234: how do I make sure that it only opens an instance of indicator rather than opened huge amount instances of indicators after each call of start() in EA?
|
|
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register

When I use the custom indicator, it shows the graph as follows
When I use the Expert Advisor with the custom indicator, it shows the following
It also repeated opened a lot of custom indicator when I am doing backtesting.
How should I change the EA such that
It only opened a custom indicator;
It plot the same graph as the custom indicator?
Below is the code for custom indicator (HitBollingerBand1.mq4)
#property indicator_chart_window #property indicator_buffers 2 sinput string s_ = " Bolinger Bands "; // ind#1 input int InpBandsPeriod = 20; //period input double InpBandsDeviation = 2.0; //deviation double CrossedUp[]; double CrossedDown[]; int limit, x; double POINT; int init() { SetIndexStyle(0, DRAW_ARROW, 1, 2,clrRed); SetIndexBuffer(0,CrossedUp); SetIndexStyle(1, DRAW_ARROW, 1, 2,clrRed); SetIndexBuffer(1,CrossedDown); POINT=0.0001; return(0); } int start() { int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=limit; i>=0; i--) { isHitBollingerBand(i); } return(0); } void isHitBollingerBand(int candleIdx){ int dir[]={1,-1}; bool setUp=false; bool setDown=false; for (int j=0;j<ArraySize(dir);j++){ double bands = iBands(_Symbol,0,InpBandsPeriod,InpBandsDeviation,0,PRICE_CLOSE,dir[j]<0?MODE_LOWER:MODE_UPPER,candleIdx); double _peak = dir[j]<0 ? iLow(_Symbol,0,candleIdx): iHigh(_Symbol,0,candleIdx); if(dir[j] * (_peak-NormalizeDouble(bands,Digits) ) >= 0){ double result=_peak+ dir[j]*3*POINT; if(dir[j]==1) CrossedUp[candleIdx]=result; else CrossedDown[candleIdx]=result; } } }Below is the code of EA makes use of the custom indicator (only the essential parts - the code is runnable) (HitBollingerBandEA.mq4)
int init() {start(); return(0); } sinput string s_ = " Bolinger Bands "; // ind#1 input int InpBandsPeriod = 20; //period input double InpBandsDeviation = 2.0; //deviation int start() { double HitBollingerBandUp=iCustom(NULL, 0, "HitBollingerBand1", InpBandsPeriod,InpBandsDeviation,0,1); double HitBollingerBandDown=iCustom(NULL, 0, "HitBollingerBand1", InpBandsPeriod,InpBandsDeviation,1,1); if(HitBollingerBandUp!=EMPTY_VALUE){ printf("%i%s [%s]",__LINE__,__FUNCTION__,TimeToStr(Time[1],TIME_DATE|TIME_MINUTES)); } return(0); }