how to buy/sell one hour after previous buy/sell

 
my ea doesnt work good on straight ups or downs.So I want it to buy at least one hour, for example,later the last buy.
 
Set a datetime LastBuyTime when the Buy happens, check if an hours has elapsed since LastBuyTime before you place the next Buy, when you place the next Buy reset LastBuyTime = CurrentTime()
 
RaptorUK:
Set a datetime LastBuyTime when the Buy happens, check if an hours has elapsed since LastBuyTime before you place the next Buy, when you place the next Buy reset LastBuyTime = CurrentTime()

Thank you.Could you write as a code,pls.I think its easier for you.
 
vieri3225:

Thank you.Could you write as a code,pls.I think its easier for you.
Nope, unless you want to test my code for me while I write your code ? how do you expect to learn if you don't try ?
 

I dont know how to identify LastbuyTime.I tried (datetime orderopentime) and print it but it gives unrelated digits.

if(TimeCurrent()>Last_Trade_Time + TimeHour()*4){...Its OK now to place a new order;}

something like here.

 

All you need to do is set it when you place a Buy trade . . . LastBuyTime = CurrentTime();

datetimes are counted in seconds since 1 Jan 1970 : https://docs.mql4.com/dateandtime

TimeHour() gives an int for a given datetime : https://docs.mql4.com/dateandtime/TimeHour

Instead of TimeHour use PERIOD_H1 : https://docs.mql4.com/constants/timeframes and multiply it by 4 ( for 4 hours ) and then by 60 ( convert to seconds )

 
vieri3225:
I dont know how to identify LastbuyTime.
static datetime lastTradeOpen;
:
if( decision ){
   int ticket = OrderSend(...
   if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
   else lastTradeOpen = TimeCurrent();
}
 

 

 

 static datetime lastTradeOpen;



//+------------------------------------------------------------------+

//| expert initialization function                                   |

//+------------------------------------------------------------------+

int init()

  {

//---- 

Crepeat=Repeat;    

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit()

  {

//---- 

   

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| expert start function                                            |

//+------------------------------------------------------------------+

int start()

  {

 .

.

. 

if(TimeCurrent()>lastTradeOpen  + PERIOD_H1){double xxx=0;}

 
 if(xxx==0  ){orderparameter}

.

.

.

 if(ticket<=0) {

    Write("Error Occured : "+ErrorDescription(GetLastError()));

} else {

  lastTradeOpen = TimeCurrent();

    
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 it didnt work.
 

 

 
vieri3225:

It didn't work . . really ?

if(TimeCurrent()>lastTradeOpen  + PERIOD_H1){double xxx=0;}

PRIOD_H1 = 60 . . . . so your code says, if the current time > last trade open + 60 seconds . . .

RaptorUK:

Instead of TimeHour use PERIOD_H1 : https://docs.mql4.com/constants/timeframes and multiply it by 4 ( for 4 hours ) and then by 60 ( convert to seconds )


 
RaptorUK:

It didn't work . . really ?

PRIOD_H1 = 60 . . . . so your code says, if the current time > last trade open + 60 seconds . . .

RaptorUK:

Instead of TimeHour use PERIOD_H1 : https://docs.mql4.com/constants/timeframes and multiply it by 4 ( for 4 hours ) and then by 60 ( convert to seconds )



PRIOD_H1 = 60 . . . . so your code says, if the current time > last trade open + 60 seconds . . .

Am I going to multiply it by 60 to make an hour?

 
As I already said . . . . "datetimes are counted in seconds since 1 Jan 1970 : https://docs.mql4.com/dateandtime " so you have to convert to seconds, hence PERIOD_H1 * 60 = 60 * 60 = number of seconds in an hour.
Reason: