shure, go trough you orderhistory, select the last one. and
if OrderOpenTime()>Time[5] //do nothing
else //Open order
shure, go trough you orderhistory, select the last one. and
if OrderOpenTime()>Time[5] //do nothing
else //Open order
Awesome...
Thank you...
I searched the mq4 book but only didn't look in that section....
Thank you & Regards,
Rohit
didn't checked
Thank you
Or simply remember the Bar in an variable or file or what you prefer when you was opening the last order and dont make new order before 5 Bars was passing.
if (lastbar>Bars-5)
{
lastbar=Bars;
OrderSend(....)
}
int hstTotal=OrdersHistoryTotal();
for(int a=0;a<hstTotal;a++) { if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY) && OrderOpenTime()<Time[10] && OrderType()==OP_BUY) { return(0); } } Ordersend() command and for sell for(int j=0;j<hstTotal;j++) { if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY) && OrderOpenTime()<Time[10] && OrderType()==OP_SELL) { return(0); } Ordersend() command
I tried the above code. But it doesn't work as expected. It opened sell orders within 10 bars.
I also tried using iTime(NULL,0,10) in place of Time[10], but still same result.
What could be wrong in this?
Regards,
Rohit
P.S: I don't know y the text is appearing in such bars. SRC button is not selecte.
Or simply remember the Bar in an variable or file or what you prefer when you was opening the last order and dont make new order before 5 Bars was passing.
if (lastbar>Bars-5)
{
lastbar=Bars;
OrderSend(....)
}
Thank you. I tried doing that earlier. But maybe something wasn't correct. I'll give it a try once again.
Regards,
Rohit
if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY) && OrderOpenTime()<Time[10] && OrderType()==OP_SELL) return(0);
I also tried using iTime(NULL,0,10) in place of Time[10], but still same result.Of course, since those are always identical.
I placed the EA on demo account and found out that it checks every order in the account history, that leads to delay and on a couple of occasions the order wasn't place at all.
How to select just the previous order and one before that(only 2 orders)?
Using the following code:
int buybar,sellbar; if(FMA>SMA && PFMA<PSMA && buycond==true) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Gold); for(int a=0;a<hstTotal;a++) { if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY) && buybar>iTime(NULL,0,0) && sellbar>iTime(NULL,0,0)) { Comment("here"); break; } else Alert("error",GetLastError()); OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",_MagicNumber,0,Red); // open new BUY Order buybar=iTime(NULL,0,0); buycond=false; sellcond=true; first=true; if(OrderTicket()>0) { if(OrderSelect(OrderTicket(),SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); Alert("BUY"); } else Print("Error opening BUY order : ",GetLastError()); } //--------------------------------------------SELL Open--------------------------------------------------------------- if(FMA<SMA && PFMA>PSMA && sellcond==true) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Snow); for(int j=0;j<hstTotal;j++) { if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY) && sellbar>iTime(NULL,0,0) && buybar>iTime(NULL,0,0)) { Comment("sell here"); // return(0); break; } else Alert("error",GetLastError()); } OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",_MagicNumber,0,Blue); //open new Sell Order sellbar=iTime(NULL,0,0); buycond=true; sellcond=false; first=true; if(OrderTicket()>0) { if(OrderSelect(OrderTicket(),SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); Alert("SELL"); } else Print("Error opening SELL order : ",GetLastError()); }//sell if close bracket
Regards,
Rohit
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How can we put this into a code statement:
if the previous BUY/SELL order was inside last 5bars, then do not open BUY/SELL respectively.
I've been searching and trying various logic but it's not giving any desired results.
Thank you.
Regards,
Rohit.