## Bar Size MT4 programming help!

everything that doesn't belong elsewhere cometh here

Moderator: moderators

ajaymein
rank: 500+ posts
Posts: 885
Joined: Sun Nov 09, 2008 6:34 am
Reputation: 0
Gender:

### Bar Size MT4 programming help!

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;

Thanks

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

blubbb
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender:
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 >

ajaymein
rank: 500+ posts
Posts: 885
Joined: Sun Nov 09, 2008 6:34 am
Reputation: 0
Gender:
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);
}
}

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

blubbb
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender:
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;`

ajaymein
rank: 500+ posts
Posts: 885
Joined: Sun Nov 09, 2008 6:34 am
Reputation: 0
Gender:
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);
}
}

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

blubbb
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender:
Sure. Try it. And remember: On 3/5 digit brokers 20 * Point are actually only 2 pips.

newschool
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender:
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;

newschool
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender:
Also what do you if the the candle is red (negative)?