Trade 15 min from last trade

 

Hi, I'm trying to figure out how to open next trade at least 15 min from last trade ... Current code I have tried doesn't seem to work... Any help would be greatly apprecited

if ( EnableTrading ){
if ( openTrades < maxOpenOrders && TradeTime < TradeTime+(15*60) ){

.... OrderSend...

TimeTrade = TimeCurrent(); // doesn't work

TimeTrade = iTime(Symbol(),NULL,0); // doesn't work

TimeTrade = Time[0]; // works only is i'm trading on 15 min chart and i set the TradeTime != Time[0] above, but when I switch to lets say 30 min chart, it will open new position immeidately

}}

 

BTW there is example in TimeCurrent() and TimeLocal() .

Your logic of TradeTime < TradeTime+(15*60) is always true. Ever think of that ?

   Trade_Time = TimeCurrent();
   
   if (TimeCurrent() >= Trade_Time*15*60)
      {
      int M15 = (TimeCurrent()  - Trade_Time)/60 ;
      Print (TimeToStr(M15|TIME_SECONDS));
      // Trade
      }

I don't compile all of these nor check the logic too

:D

GetTickCount()

   Trade_Time = GetTickCount();
   
   if (GetTickCount() >= Trade_Time*15*60*1000)
      {
      double M15 = (GetTickCount() - Trade_Time)/1000/60 ;
      Print (M15);
      // Trade
      }
 
mharoon:

Hi, I'm trying to figure out how to open next trade at least 15 min from last trade ... Current code I have tried doesn't seem to work... Any help would be greatly apprecited

if ( EnableTrading ){
if ( openTrades < maxOpenOrders && TradeTime < TradeTime+(15*60) ){

.... OrderSend...

TimeTrade = TimeCurrent(); // doesn't work

TimeTrade = iTime(Symbol(),NULL,0); // doesn't work

TimeTrade = Time[0]; // works only is i'm trading on 15 min chart and i set the TradeTime != Time[0] above, but when I switch to lets say 30 min chart, it will open new position immeidately

}}

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 
onewithzachy:

BTW there is example in TimeCurrent() and TimeLocal() .

Your logic of TradeTime < TradeTime+(15*60) is always true. Ever think of that ?

I don't compile all of these nor check the logic too

:D

GetTickCount()


thanks onewithzachy for qiock response. I did try your Timecurrent() logic but it still opens positions within the same timeframe.. within same second!

datetime TradeTime; 
int tradeTimeWaitINmin = 1; // test for 1 min wait
if ( EnableTrading ){
if ( openTrades < maxOpenOrders && TimeCurrent() >= TradeTime * ( tradeTimeWaitINmin * 60) ){
trade logic...
if trade successfull...)
  TradeTime=TimeCurrent();

if ( EnableTrading ){
if ( openTrades < maxOpenOrders && GetTickCount() >= TradeTime * tradeTimeWaitINmin * 60 *1000 
      /* TimeCurrent() >= TradeTime * ( tradeTimeWaitINmin * 60) */ ){
  trade logic ...
  if ( trade successfull... )
   TradeTime=GetTickCount();
 
mharoon:

Hi, I'm trying to figure out how to open next trade at least 15 min from last trade ...

From the last trade being opened or from the last trade being closed ?
 
RaptorUK:
From the last trade being opened or from the last trade being closed ?

from last trade being open... so lets say t0 pos 1 opens... at t15 (assuming trend is still holding) open pos 2
 

you could do an OrderSelect() loop to find the newest open trade and then do

int ibar = iBarShift(NULL,PERIOD_M1,OrderOpenTime());
if(ibar>15)  // ....  it was more than 15 minutes ago
 
mharoon:

from last trade being open... so lets say t0 pos 1 opens... at t15 (assuming trend is still holding) open pos 2

not sure why my code didn't show up...

if ( EnableTrading ){
if ( openTrades < maxOpenOrders && TradeTime != Time[0] ){
  trade();  
  if ( trade_successful ){
      TradeTime = Time[0];}}}      
 
mharoon:


Time[0] seem to work as long as I'm on 15 chart, change to another or reload opens another pos
 
mharoon:
not sure why my code didn't show up...
After you paste your code into the SRC box you have to click Insert, bottom right
 
mharoon:
if ( EnableTrading ){
if ( openTrades < maxOpenOrders && TradeTime != Time[0] ){
  trade();  
  if ( trade_successful ){
      TradeTime = Time[0];}}}      

This code won't recover from being restarted . . . you need to look at the open orders and order History to find when the last one was opened . . . as SDC said.
Reason: