Expert Advisor problem

 

Hi, I have this problem with my new EA, with it i`m going for the squeeze strategy with BB, i have set some code and after checking up everything and using the tester it doesn`t trade,why that happens to me so often :D . 

double BBmain[];
double BBlow[];
double BBhigh[];
double BBwidth[];
ArrayResize(BBmain,size); 
ArrayResize(BBlow,size); 
ArrayResize(BBhigh,size); 
ArrayResize(BBwidth,size); 

for(int ii = 0; ii<size;ii++)
{
BBmain[ii] = iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_MAIN,ii);
BBlow[ii] = iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_LOWER,ii);
BBhigh[ii] = iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_UPPER,ii);
BBwidth[ii] = (BBhigh[ii]-BBlow[ii])/BBmain[ii];
}
int MinimumWidthIndex = ArrayMinimum(BBwidth,size-1,1);
double MinimumWidth = BBwidth[MinimumWidthIndex];
double breakT = MinimumWidth + ((ToleranceBBminimum/100)*MinimumWidth); // this is the breakthrough point bellow which the band`s
                                                                        // width is considered really low and there is a possibility
                                                                        // for the squeeze

 

input int ToleranceBBminimum = 5; //  Tolerance in percent from the BBwidth 
this is a percent tolerance from the lowest point in the array
      if(Bid>BBhigh[0] && Close[1]<BBhigh[1] && BBwidth[1]<breakT &&  BBwidth[0]>BBwidth[1] )

this is my buy rule , i just wonder what isn`t right, i tried printing the values of the upper arrays, they seem to be calculated correctly. I can`t  figure out why it doesn`t trade, can u help me?

 Thanks in advance

:) 

 
BBwidth[ii] = (BBhigh[ii]-BBlow[ii])/BBmain[ii];

I don't get the logic behind dividing the width by the main, although I don't see that it is causing your problem.

Is the EA attempting to open trades? If so, what is the errror?

Is the EA recognising when conditions are met?


Please don't use very long single lines in the posted code. It makes the page very wide and difficult to read. I have edited your posted code to put your long comment on more than 1 line

 

If you are looking for a bb-squeeze you have to compare the actual difference bbHigh-bbLow against a (longer|| shorter) sma or ema of your BBwidth buffer.

Use iMAOnArray() - read about its use in the editors reference!

Or you use you own ema function:

bbEma = ema(bbHigh-Low, bbEma,const);

...

double ema (double prevEma, double newVal, double coeff) {
     if (coeff > 0.99) return(newVal);
     return( (newVal-prevEma)*coeff + prevEma );
}
But make sure it's called only at new bar. It shouldn't be called at any new tick! If you are not sure use iMaOnArray()!!
 
How can i make sure it is called at a new bar, i`ve been wondering `bout that for a while?
 
Stan4o1:
How can i make sure it is called at a new bar, i`ve been wondering `bout that for a while?

int PrevBars;

 

if(PrevBars==Bars) return;

PrevBars=Bars; 

 
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
 
WHRoeder:
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum

You are wrong. Do not use time.

Read clever people and do not thing that you know all.

 

 https://forum.mql4.com/ru/65066/page4#1015965

 https://www.mql5.com/en/users/mql5

 

(translation)

Once again I will try to explain (on fingers):
  1. I run a terminal after X amount of time after the last run
  2. Initiate injection history, which is missing (terminal was not working X minutes)
  3. Called OnCalculate indicator on an existing story prevtime = last known time in history, the size of the indicator buffer N bars
  4. While the story is pumped from the server comes teak
  5. Called OnCalculate indicator, where Time [0] tick time its indicator remembers how prevtime, the size of the indicator buffer N + 1 bar (between the bars N and N + 1 there is a hole in the story)
  6. After resuming stories again called OnCalculate indicator, but this time, the hole in the history of no, but prevtime has tighter date as the Time [0] - a new bar is not (or is not vanishing buffers in the indicator), and the buffer size indicator N + X / Timeframe bars and IndBuffer [0] is not the one that was in step 5
 

evviil:

- I don't understand the English of your transaltion  :(

- I don't understand the problem of that discussion that has lead to that post - may be it's not related?

- Stan4o1 asked about how to make sure that a new bar appeared and an new bar has to start after the new tick appears at least _Period*sec seconds after the opening time of the most recent bar. This works even when there was a time-gap due to no ticks or a disconnect!

 
Thanks for the answers guys, I think what gooly has said will work and i`ll try it
 

The translation appears to be how history gets filled and how indicators must use prev_calculated or IndicatorCounted() in OnCalculate.

eevviill No one ever said to use new bar code in indicators. That is only to be used in EA's OnStart.

 
WHRoeder:

The translation appears to be how history gets filled and how indicators must use prev_calculated or IndicatorCounted() in OnCalculate.

eevviill No one ever said to use new bar code in indicators. That is only to be used in EA's OnStart.

If you calc. an ema yourself in an indicator you might need to do this only if a new bar appears with the values of the previous bar (index=1).

But I realized that in indicators once and a while everything is re-calculated and that could 'double' certain static or global values.

Therefore In the branch to check whether prev.-counted bars = 0 I reset all those variables!

Reason: