Working Hours

 

I found some piece of code which I am using sometimes.

If I need to do some back/forward test in particular hours, or if I am not trading 24 hours per day I use the following code to be inserted in EA:

In the top of EA (where information about the lots, Take Profit etc are located) insert the following:

extern bool UseHourTrade = True;

extern int FromHourTrade = 9;

extern int ToHourTrade = 21;[/CODE]

After that look on the code and find the line

int start()[/CODE]

After this line there are some pieces of the code where something is checking (Bars, TakeProfit<10 etc).

If you see it you may insert the following code:

[CODE]if (UseHourTrade){

if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)){

Comment("Non-Trading Hours!");

return(0);

}

}

For example:

[CODE]int start(){

if(Bars<100){

Print("bars less than 100");

return(0);

}

if (UseHourTrade){

if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)){

Comment("Non-Trading Hours!");

return(0);

}

}

if(lStopLoss<10){

Print("StopLoss less than 10");

return(0);

}

if(lTakeProfit<10){

Print("TakeProfit less than 10");

return(0);

}

We can not do it with every EA. But in some EA we can. If I change something in the code I will mark it in the comments in the code (working hours was added by newdigital) and will re-name this EA. For example, I changed something in Ichimoku5 and I receive Ichimoku5_1. Why? If you post changed EA to the forum the other members will not be confused with the versions and will know exactly where the original version is and where is yours which you changed for yourself only.

Codersguru will correct me if I did mistake.

 

Great!

newdigital,

You are moving at the speed of the rock.

The code is 100% right. KEEP GOING MAN!

When I make changes to any code I rename it like that:

SuperTrend (This is the original)

SuperTrend_Alert (This is the new name. Added _Alert to the original name because I've added Alerts function to the original code)

I don't rename it to SuperTrend2 or SuperTrend_v2 because I didn't make a lot of improvements to consider it a new version. (Just an opinion)

 

maybe in the ea's that dont work you can use something like

if (Hour( ) >8 && Hour( ) <18)

I dont think u have to declare it

Reason: