Can anyone figure out why this will not work right??

 

if (UseHourTrade)

{

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 || b==1 || c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

return(0);

}

}

It compiles ok, but even if the program is active during one of the sessions, it displays the PROGRAM IN SLEEP message. I do not know what to do to correct this??

 

Try this...

Hello,

I've seen MT4 be really funky in how it reads multiple if conditions, with !'s in there, etc. So, give this a try. I basically changed the logic to "positive" logic and spread out the If's a bit to make sure they are really ballanced. You also needed to zero out the comment when your conditions aren't met, else it stays there.

HAHA! It could be as simple as your original logic works, but the comment just needed to be zeroed out when the condition wasn't met.

Anyway, I also removed the "return (0)" since its not a function, so you don't need to "return" anything... Its probably left over from the rest of your code, so you'll probably need to add it back in.

Seems to work fine for me now.

If any of the hours inclusive of the range in the From and To variables are met, there is no comment.

Outside of those hours, the comment is there.

I'm assuming that's what you wanted?

Cheers,

Cubesteak

if (UseHourTrade)

{

int now = Hour();

if (

( (now>=FromHourTrade1) ) &&

( (now<=ToHourTrade1) )

) a=1;

if (

( (now>=FromHourTrade2) ) &&

( (now<=ToHourTrade2) )

) b=1;

if (

( (now>=FromHourTrade3) ) &&

( (now<=ToHourTrade3) )

) c=1;

if (

(a!=1) &&

(b!=1) &&

(c!=1)

)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

}

else Comment("");

}

 

Some more goodies...

I've been meaning to make something like this for quite some time, and your question gave me the impetus.

Here's an indicator based on the above code. Hours can be set in the code, or by the indicator settings window.

I tried to make one that would use a separate window, but I forgot that comments only work on the main charts.

If people are interested in that, I can make one that uses objects, rather than comments.

Enjoy!

-Cubesteak

Files:
 

A Friend coded this for me - Works great!!!

if (UseHourTrade)

{

int a=0;

int b=0;

int c=0;

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 && b==1 && c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

return(0);

}

}

Note: Unfortunately, the solarwind indicator is useless to write an EA from - It repaints itself! All indicators that have ++ used in the logic loop are virtually useless to try to write an EA for, because they all repaint themselves and that messes up the EA timing and optimization. They may be ok visually, but they don't work well in an EA. Most indicators do repaint themselves. You must use an indicator that has -- in the logic loop, and even then other conditions can mess up a EA. This is why so many EA's end up not working!!!

Dave

<<<

 

Hmm.. You'll still need to do the Comment (""); or else the comment will never go away, unless you've reset it somewhere else.

iscuba11:
if (UseHourTrade)

{

int a=0;

int b=0;

int c=0;

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 && b==1 && c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

return(0);

}

}

Note: Unfortunately, the solarwind indicator is useless to write an EA from - It repaints itself! All indicators that have ++ used in the logic loop are virtually useless to try to write an EA for, because they all repaint themselves and that messes up the EA timing and optimization. They may be ok visually, but they don't work well in an EA. Most indicators do repaint themselves. You must use an indicator that has -- in the logic loop, and even then other conditions can mess up a EA. This is why so many EA's end up not working!!!

Dave

<<<
Reason: