Download MetaTrader 5
To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
digisoft
538
digisoft 2015.06.25 11:50 

Can anyone tell what is the best coding for taking trades only in the first 5 (or x) seconds of the current/new candle?


Any help aprreciated!


Thanks.

whroeder1
13596
whroeder1 2015.06.25 12:20  
  1. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. What will you do if there are no ticks during the first x seconds? "Free-of-Holes" Charts - MQL4 Articles
digisoft
538
digisoft 2015.06.25 21:04  

I try to learn, spent always every free hour I have to learn more.

Paying a coder is not a problem but I prefer learning myself by getting good tips from developers who have past my stadium ;-)


Nature problem: when Indi give signal after first x seconds of new bar, signal must be ignored.


I read different things about it. Possibility of use OnTimer and also that it is not possible.

Could I continue with the sample source or is that not gonna work?


Thank you for your time.

#property strict
#define magicnumber 123

input double lots=1; // Lot:
input int sleep=30000; // Sleep, in milliseconds:

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   static datetime LastBar=0;
   if(Time[0]!=LastBar)
     {
      LastBar=Time[0];
      int tmeLeft=PeriodSeconds()-1 -(int)(TimeCurrent()-Time[0]);
      EventSetTimer(tmeLeft);
     }
  }

void OnTimer()
  {
   int order;
   double customindarrow0 = iCustom(Symbol(),0,"cia",0,0);
   double customindarrow1 = iCustom(Symbol(),0,"cia1",1,0);

   if(customindarrow0!=0.0)
     {
      order=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"custom buy arrow",magicnumber,0,Blue);
      Sleep(sleep);
      if(order==0)
        {
         Print("Error Opening Buy Order: ",GetLastError());
        }
      else if(order>0)
        {
         Print("Buy Order Opened");
        }
     }
   if(customindarrow1!=0.0)
     {
      order=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"custom sell arrow",magicnumber,0,Red);
      Sleep(sleep);
      if(order==0)
        {
         Print("Error Opening Sell Order: ",GetLastError());
        }
      else if(order>0)
        {
         Print("Sell Order Opened");
        }
     }
   EventKillTimer();
  }
whroeder1
13596
whroeder1 2015.06.25 23:51  
 order=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"custom buy arrow",magicnumber,0,Blue);
      Sleep(sleep);
      if(order==0)
        {
         Print("Error Opening Buy Order: ",GetLastError());
What does OrderSend return when it fails?
DeanDeV
330
DeanDeV 2015.06.26 16:24  
digisoft:

Can anyone tell what is the best coding for taking trades only in the first 5 (or x) seconds of the current/new candle?


Any help aprreciated!


Thanks.

Maybe:

if(TimeCurrent()<=Time[0]+X)
 {

 }
JD4
1101
JD4 2015.06.27 04:52  
If you are trying to guarantee that the broker will fill the placed order in the first 5 seconds of the new bar, you are fighting a losing battle.  From what I have heard, that is hit or miss in the best of situations.  If you are only trying to send the order within the first 5 seconds of the new bar, this could possibly work.
/
To add comments, please log in or register