What is best code for taking trades only in first 5 seconds of current/new candle
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(); }
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) { }
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.