Hi Lorentzos, finally got around to trying out your code and low and behold i again can't seem to get it to work again.. To be completely clear the exact code i am trying is below, and i am testing on EURUSD with 0.1 lot size and M1 bars as suggested.
Would you mind trying the code yourself and seeing if it produces trades? At this point i'm starting to think there is a configuration setting wrong in my MT5 as i just cant see how it would not work.. *weep*
and , if you choose to edit instead of copy pasting , change Lot to cLot , the variable , there must be a cache thing issue in that too as the codes where identical and one was not trading.
(i assume because the tester cached the version that had the char input as a char)
Cheers
#property version"1.00"#include <Trade/Trade.mqh>
CTrade trade;
inputdouble Lot=0.01;
bool isThisTimeInMyTimeWindow(datetime this_time,//the first thing you need which time is checked int from_hours,//we are keeping it simple here 24 h format thoint from_minutes,//int to_hours,//hour to , 24 h format againint to_minutes){
bool example_prints=false;
if(example_prints)
{
Print("------");
Print("Received Time "+TimeToString(this_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
Print("---to be tested from ("+IntegerToString(from_hours)+":"+IntegerToString(from_minutes)+":00)");
Print("------------------to ("+IntegerToString(to_hours)+":"+IntegerToString(to_minutes)+":00)");
}
int days_in_time=(int)MathFloor(((double)this_time)/86400.0);
if(example_prints){Print("Days in time : "+IntegerToString(days_in_time));}
int seconds_in_this_time=((int)this_time)-(days_in_time*86400);
if(example_prints){Print("Left seconds in this time : "+IntegerToString(seconds_in_this_time));}
//you turn the from into seconds too int seconds_from=from_hours*3600+from_minutes*60;//easy right ?int seconds_to=to_hours*3600+to_minutes*60;//if(example_prints)
{
Print("Seconds From : "+IntegerToString(seconds_from));
Print("Seconds To : "+IntegerToString(seconds_to));
}
//if normal second comparisonif(seconds_to>=seconds_from){
if(example_prints){Print("Normal Comparison Used");}
//just being in between is enough if(seconds_in_this_time>=seconds_from&&seconds_in_this_time<=seconds_to){
if(example_prints){Print("Valid");}
return(true);//that part is done
}
}
//and the hard partelse{//so if seconds_to is smaller than seconds from if(example_prints){Print("Weird Comparison Used");}
if((seconds_in_this_time>=seconds_from&&seconds_in_this_time<=86400)||(seconds_in_this_time>=0&&seconds_in_this_time<=seconds_to)){
//so if at the end of the day portion or start of the day portion , return valid if(example_prints){Print("Valid");}
return(true);
}}
//anything else return false . done now you just call it with the TimeLocal and see what it saysif(example_prints){Print("NOT Valid");}
return(false);
}
intOnInit()
{
return(INIT_SUCCEEDED);
}
voidOnDeinit(constint reason)
{}
voidOnTick()
{
int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double SL=bid-5000*point;
double TP=bid+5000*point;
bool Buy_Condition_1 = isThisTimeInMyTimeWindow(TimeCurrent(),9,30,9,45); //checks trading timebool Buy_Condition_2 = (PositionSelect(_Symbol) == false); //check theres no open positionsif(Buy_Condition_1) // && Buy_Condition_2 && Buy_Condition_3)
{
if(Buy_Condition_2)
{
trade.Buy(Lot,_Symbol,ask,SL,TP,"");
}
}
}
and , if you choose to edit instead of copy pasting , change Lot to cLot , the variable , there must be a cache thing issue in that too as the codes where identical and one was not trading.
(i assume because the tester cached the version that had the char input as a char)
Cheers
Ok so i deleted my last comment.. it was 100% user error at the end there because... I got it working! Praise the lord name Lorentzos. You are indeed a legend. I'd love to repay the help some day but i have a strong feeling any help i can offer wont be much help at all :)
Ok so i deleted my last comment.. it was 100% user error at the end there because... I got it working! Praise the lord name Lorentzos. You are indeed a legend. I'd love to repay the help some day but i have a strong feeling any help i can offer wont be much help at all :)
Hi Lorentzos, finally got around to trying out your code and low and behold i again can't seem to get it to work again.. To be completely clear the exact code i am trying is below, and i am testing on EURUSD with 0.1 lot size and M1 bars as suggested.
Would you mind trying the code yourself and seeing if it produces trades? At this point i'm starting to think there is a configuration setting wrong in my MT5 as i just cant see how it would not work.. *weep*
Hello , sure i'll pop it in real quick.
The lot was a char it should be a double
replaced symbol with _Symbol
replaced 0.0 price with ask price
and , if you choose to edit instead of copy pasting , change Lot to cLot , the variable , there must be a cache thing issue in that too as the codes where identical and one was not trading.
(i assume because the tester cached the version that had the char input as a char)
Cheers
The lot was a char it should be a double
replaced symbol with _Symbol
replaced 0.0 price with ask price
and , if you choose to edit instead of copy pasting , change Lot to cLot , the variable , there must be a cache thing issue in that too as the codes where identical and one was not trading.
(i assume because the tester cached the version that had the char input as a char)
Cheers
Ok so i deleted my last comment.. it was 100% user error at the end there because... I got it working! Praise the lord name Lorentzos. You are indeed a legend. I'd love to repay the help some day but i have a strong feeling any help i can offer wont be much help at all :)
Cheers fella!
Ok so i deleted my last comment.. it was 100% user error at the end there because... I got it working! Praise the lord name Lorentzos. You are indeed a legend. I'd love to repay the help some day but i have a strong feeling any help i can offer wont be much help at all :)
Cheers fella!
Awesome :)