Set a delay timer between trades

To add comments, please log in or register
trader88888
138
trader88888  

Im wondering if its possible to set a delay timer between trades? I'm working on automating a strategy, but there are some times when conditions are met that trades will open and close faster then you can blink. I'm wondering if we can say "For the next 10 bars, do not open any new trades", or "For the next 60 minutes do not open any new trades"

Would really like someone's assistance if possible... thx

qjol
3196
qjol  

first u can use sleep()

second u can use timing for example (something like this)

int WaitTime = 10;  // 10 Min.
static int TimeSent;
if (TimeCurrent() >= TimeSent + (WaitTime * 60))
   {
   OrderSend(.....);
   TimeSent = TimeCurrent();
   }
else
   return(0);

or u can use bars option for example (something like this)

int WaitBars = 10;  // 10 Bars.
static int TimeSent;
int shift = iBarShift(NULL,0,TimeSent);
if (shift >= WaitBars)
   {
   OrderSend(.....);
   TimeSent = Time[0];
   }
else
   return(0);

didn't checked

& there r a lot more options

trader88888
138
trader88888  
qjol:

first u can use sleep()

second u can use timing for example (something like this)

or u can use bars option for example (something like this)

didn't checked

& there r a lot more options


I love you. Thx ;)
[Deleted]
[Deleted]  

Ok...a new thought to add to this ...if you've got time it would be much appreciated.

> How would I pause trading after one bad trade for a period of say 1 'current' bars or 24hours for instance?

Thanks,

DAVID

Simon Gniadkowski
17725
Simon Gniadkowski  
Wooopa:

Ok...a new thought to add to this ...if you've got time it would be much appreciated.

> How would I pause trading after one bad trade for a period of say 1 'current' bars or 24hours for instance?

Thanks,

DAVID

Please don't double post . . .
micke81
12
micke81  

I have add the same code to my EA (very simple only for testing) but I am missing something please can someone guide me.

I am getting the error  'return' - 'void' function returns a value.

Thankyou so much

#include<Trade\Trade.mqh>
#include<Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>
#include <Math\Stat\Normal.mqh>
#include <Expert\Expert.mqh>

CTrade  trade;
CPositionInfo  m_position;                   // trade position object
COrderInfo     m_order;                      // trade order object
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;

void OnTick()
  {


    
//-----------------------------------------------------------------------------------------
  
       // get the ask price
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   
   int  NumberOfPositions=0; // number of positions
      
    

//+------------------------------------------------------------------+
//|   Information for the Buy Order                                  |
//+------------------------------------------------------------------+

int WaitTime = 10;  // 10 Min.
static int TimeSent;
if (TimeCurrent() >= TimeSent + (WaitTime * 60));
 
   if (NumberOfPositions<10)
       
      {
          trade.Buy(0.1,NULL,Ask,(0),(Ask+85*_Point),NULL);    
          TimeSent = TimeCurrent();
   }
else
   return(0);

      
//+------------------------------------------------------------------+
//| Sell if Ticket has Profit                                      |
//+------------------------------------------------------------------+
   {  

  for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
            if( m_position.Symbol() == Symbol())   
              if(m_position.Profit()>0.60)
                 m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
             
  }

   }
Kenneth Parling
5285
Kenneth Parling  
micke81:

I have add the same code to my EA (very simple only for testing) but I am missing something please can someone guide me.

I am getting the error  'return' - 'void' function returns a value.

Thankyou so much


#include<Trade\Trade.mqh>
#include<Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>
#include <Math\Stat\Normal.mqh>
#include <Expert\Expert.mqh>

CTrade  trade;
CPositionInfo  m_position;                   // trade position object
COrderInfo     m_order;                      // trade order object
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;

void OnTick()
  {


    
//-----------------------------------------------------------------------------------------
  
       // get the ask price
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   
   int  NumberOfPositions=0; // number of positions
      
    

//+------------------------------------------------------------------+
//|   Information for the Buy Order                                  |
//+------------------------------------------------------------------+

int WaitTime = 10;  // 10 Min.
static int TimeSent;
if (TimeCurrent() >= TimeSent + (WaitTime * 60));
 
   if (NumberOfPositions<10)
       
      {
          trade.Buy(0.1,NULL,Ask,(0),(Ask+85*_Point),NULL);    
          TimeSent = TimeCurrent();
   }
else
   return(0);//replace with only return;

      
//+------------------------------------------------------------------+
//| Sell if Ticket has Profit                                      |
//+------------------------------------------------------------------+
   {  

  for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
            if( m_position.Symbol() == Symbol())   
              if(m_position.Profit()>0.60)
                 m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
             
  }

   }
read about void function here
micke81
12
micke81  
Kenneth Parling:

read about void function here


Many thanks for your reply.

Have changed the code and the error has gone. Thank you, but it is still sending orders every 20 seconds instead of 10mins. What have a done wrong.

Sorry if this is a easy mistake I am very new to this

To add comments, please log in or register