Bar Size MT4 programming help!

everything that doesn't belong elsewhere cometh here

Moderator: moderators

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

Bar Size MT4 programming help!

Postby ajaymein » Tue Jan 05, 2010 10:38 pm

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.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
blubbb
rank: 150+ posts
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender: Male

Postby blubbb » Tue Jan 05, 2010 11:32 pm

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 >

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

Postby ajaymein » Thu Jan 07, 2010 12:35 am

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);
}
}

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

User avatar
blubbb
rank: 150+ posts
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender: Male

Postby blubbb » Thu Jan 07, 2010 12:55 am

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;

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

Postby ajaymein » Thu Jan 07, 2010 1:09 am

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);
}
}

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

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
blubbb
rank: 150+ posts
rank: 150+ posts
Posts: 219
Joined: Mon Sep 29, 2008 8:07 pm
Reputation: 0
Location: Europe
Gender: Male

Postby blubbb » Thu Jan 07, 2010 1:29 am

Sure. Try it. And remember: On 3/5 digit brokers 20 * Point are actually only 2 pips.

User avatar
newschool
rank: 150+ posts
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender: Male

Postby newschool » Thu Jan 07, 2010 1:59 am

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;

User avatar
newschool
rank: 150+ posts
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender: Male

Postby newschool » Thu Jan 07, 2010 2:05 am

Also what do you if the the candle is red (negative)?

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “general”