Metatrader 4 coding problem

 

Hi everyone,

I hope you are all well and I'll jump straight to my problem.

I have the following line of coding that is giving me issues:

bool TradeTimeOK=true;

if(DayOfWeek()==5 && Hour()>15 || DayOfWeek()==6||DayOfWeek()==0 && Hour()<14)

TradeTimeOK=false;

And it is this part of the code that seems to be the issue:

DayOfWeek()==0 && Hour()<14

If I take out '&& Hour()<14', I don't open a trade after 15:00 on a Friday, but if I include it, it does open a trade.

Can anyone tell me where I am going wrong?

Thanks!

 

With these things you need to make sure that the sequence of evaluation is as you intend it and don't leave it up to the compiler to use its default evaluation setting.

You do this by using brackets

if( (DayOfWeek()==5 && Hour()>15) || ( DayOfWeek()==6) || (DayOfWeek()==0 && Hour()<14) )

Now if any of the bracketed conditions is true then the if statement results in true.

 
Re4ctor:

I have the following line of coding that is giving me issues:

bool TradeTimeOK=true;

if(DayOfWeek()==5 && Hour()>15 || DayOfWeek()==6||DayOfWeek()==0 && Hour()<14)

TradeTimeOK=false;

And it is this part of the code that seems to be the issue:

DayOfWeek()==0 && Hour()<14

If I take out '&& Hour()<14', I don't open a trade after 15:00 on a Friday, but if I include it, it does open a trade.

Can anyone tell me where I am going wrong?

if (! IsTradeAllowed()) {
   return(0);
}

if ((DayOfWeek() > 4) && (Hour() > 15)) {
   return(0);
}
 
Ickyrus:

With these things you need to make sure that the sequence of evaluation is as you intend it and don't leave it up to the compiler to use its default evaluation setting.

You do this by using brackets

if( (DayOfWeek()==5 && Hour()>15) || ( DayOfWeek()==6) || (DayOfWeek()==0 && Hour()<14) )

Now if any of the bracketed conditions is true then the if statement results in true.


Thanks Ickyrus for spotting my school-boy error. It now works as intended.
 

Please, can somebody help me with this?

HaRed = iCustom(NULL, 0, "Heiken Ashi",1,PRICE_CLOSE,0);

HaWhite = iCustom(NULL, 0, "Heiken Ashi",2,PRICE_CLOSE,0);

I want to declare heiken ashi candle colours of the last bar using the close price.

Red colour for bear candle and White colour for bull candle.

Please your help will be highly appreciated.

Thanks in advance.

Oladapo

 
  1. Don't hijack other peoples posts, open your own with an explanatory title
  2. My Heiken Ashi has 4 parameters (color1..color4) so the iCustom call must be iCustom(Null,0,"Heiken Ashi", Red, White, Red, White, buffer, shift) you posted nonsense.
  3. Color is determined by the values set. if buffer zero price > buffer one price you get red.
 
WHRoeder:
  1. Don't hijack other peoples posts, open your own with an explanatory title
  2. My Heiken Ashi has 4 parameters (color1..color4) so the iCustom call must be iCustom(Null,0,"Heiken Ashi", Red, White, Red, White, buffer, shift) you posted nonsense.
  3. Color is determined by the values set. if buffer zero price > buffer one price you get red.

Sorry for using this post, I don't know how to open one.

Thank you so much for the assistance. The code now works.

You are blesses in Jesus name.

Reason: