Page 1 of 1

Bar Size MT4 programming help!

Posted: Tue Jan 05, 2010 10:38 pm
by ajaymein
Hello, I am trying to modify an indicator so that it only goes off if the previous bar size is greater then 20 pips. Here is the code that I thought would do the trick but the indicator still goes off if the previous bar is less then 20 pips.

if (iClose(NULL, p, 2) - iOpen(NULL, p, 2) > .002) continue;

Please let me know!
Thanks

P.S. I am editing Blubb's DOUBLE ALERT indi if that helps any.

Posted: Tue Jan 05, 2010 11:32 pm
by blubbb
First: I don't know if this is the problem, but "continue" only works inside of a loop.

Second: Use 20 * Point instead of .002 (think of the XXXJPY symbols).

Third: I don't know the context, but maybe you should negate the comparison? < instead of >

Posted: Thu Jan 07, 2010 12:35 am
by ajaymein
Hey blubbb, thanks for replying! I am not extremely savvy in MT4 programming but I know a little bit. I believe I the continue statement was inside of the proper loop. Here is the piece of code I am inserting it into:

-------------------------------------------

if (Close[0] == iHigh(NULL, p, 0)) {
if (iClose(NULL, p, i+1) > iOpen(NULL, p, i+1)) continue;
if (Close[0] <= z) continue;
if (Old > z) continue;
if (iOpen(NULL, p, 2) - iClose(NULL, p, 2) > 20*Point) continue;
DisplayAlert("Look for a "+Symbol()+" SHORT on "+PeriodNice(p)+" (wick)");
t = iTime(NULL, p, 0);
return(0);
}

if (Close[0] == iLow(NULL, p, 0)) {
if (iClose(NULL, p, i+1) < iOpen(NULL, p, i+1)) continue;
if (Close[0] >= z) continue;
if (Old < z) continue;
if (iClose(NULL, p, 2) - iOpen(NULL, p, 2) > 20*Point) continue;
DisplayAlert("Look for a "+Symbol()+" LONG on "+PeriodNice(p)+" (wick)");
t = iTime(NULL, p, 0);
return(0);
}
}

-------------------------------------

Posted: Thu Jan 07, 2010 12:55 am
by blubbb
continue makes the loop continue i.e. beginning the next cycle omitting the rest of the lines. So in fact you make your alert pop up only when bar 2 is NOT > 20 pips.

My suggestion (some lines further up rewritten, based on the current version in my thread):

Code: Select all

  if (MinFactorWicking > 0) for(int i = 0; i < MaxBars; i++) {
    double b2 = MathAbs(iClose(NULL, p, i+2) - iOpen(NULL, p, i+2));
    if (b2 < 20 * Point) continue;
    double b1 = MathAbs(iClose(NULL, p, i+1) - iOpen(NULL, p, i+1));
    if (b1 < b2 * MinFactorWicking) continue;

    double z = (iClose(NULL, p, i+1) + iOpen(NULL, p, i+1)) / 2;

Posted: Thu Jan 07, 2010 1:09 am
by ajaymein
blubbb wrote:continue makes the loop continue i.e. beginning the next cycle omitting the rest of the lines. So in fact you make your alert pop up only when bar 2 is NOT > 20 pips.

My suggestion (some lines further up rewritten, based on the current version in my thread):

Code: Select all

  if (MinFactorWicking > 0) for(int i = 0; i < MaxBars; i++) {
    double b2 = MathAbs(iClose(NULL, p, i+2) - iOpen(NULL, p, i+2));
    if (b2 < 20 * Point) continue;
    double b1 = MathAbs(iClose(NULL, p, i+1) - iOpen(NULL, p, i+1));
    if (b1 < b2 * MinFactorWicking) continue;

    double z = (iClose(NULL, p, i+1) + iOpen(NULL, p, i+1)) / 2;


Ok, Let me give it a try. Does this look right to you?

-------------------------------------

void Check(int p, datetime& t) {
if (iTime(NULL, p, 0) == t) return(0);

if (MinFactorWicking > 0) for(int i = 0; i < MaxBars; i++) {
double b2 = MathAbs(iClose(NULL, p, i+2) - iOpen(NULL, p, i+2));
if (b2 < 20 * Point) continue;
double b1 = MathAbs(iClose(NULL, p, i+1) - iOpen(NULL, p, i+1));
if (b1 < b2 * MinFactorWicking) continue;

double z = (iClose(NULL, p, i+1) + iOpen(NULL, p, i+1)) / 2;

if (Close[0] == iHigh(NULL, p, 0)) {
if (iClose(NULL, p, i+1) > iOpen(NULL, p, i+1)) continue;
if (Close[0] <= z) continue;
if (Old > z) continue;
//if (iOpen(NULL, p, 2) - iClose(NULL, p, 2) > 20*Point) continue;
DisplayAlert("Look for a "+Symbol()+" SHORT on "+PeriodNice(p)+" (wick)");
t = iTime(NULL, p, 0);
return(0);
}

if (Close[0] == iLow(NULL, p, 0)) {
if (iClose(NULL, p, i+1) < iOpen(NULL, p, i+1)) continue;
if (Close[0] >= z) continue;
if (Old < z) continue;
//if (iClose(NULL, p, 2) - iOpen(NULL, p, 2) > 20*Point) continue;
DisplayAlert("Look for a "+Symbol()+" LONG on "+PeriodNice(p)+" (wick)");
t = iTime(NULL, p, 0);
return(0);
}
}

--------------------------------

Posted: Thu Jan 07, 2010 1:29 am
by blubbb
Sure. Try it. And remember: On 3/5 digit brokers 20 * Point are actually only 2 pips.

Posted: Thu Jan 07, 2010 1:59 am
by newschool
Well... you are just missing parentheses... because you compare the complete math operation, not just the number on the right...

if ( [highlight=red]([/highlight] iClose(NULL, p, 2) - iOpen(NULL, p, 2) [highlight=red])[/highlight] > 20*Point) continue;

Posted: Thu Jan 07, 2010 2:05 am
by newschool
Also what do you if the the candle is red (negative)?