Having a problem with NFA antihedging rule, Please help

 

Hi, I am having problem with this new rule. My EA cannot make pending orders.

It is a simple EA, if 1 open order, delete the unused pending, and make 2 new pending orders (buylimit and selllimit)

here is my code, the rest is in the attachment :

if (TotalMikuOrders()==2 && TotalMikuOrders_Mode(OP_BUY)+TotalMikuOrders_Mode(OP_SELL)==1){
for (int j=0;j<OrdersTotal();j++){
OrderSelect(j,SELECT_BY_POS);
if (OrderType()==OP_BUY){
if (OrderMagicNumber()==Magic_Miku_B){
deleteMikuPending();
sendMikuPending(OrderOpenPrice(),Magic_Miku_S,Magic_Miku_B+1,XFactor*CoA,XFactor*CoB,com+"XA",com+"XB",sl1,sl2,r1,r1,sp,sp0,tp1,tp2);
return(0);
}

}
if (OrderType()==OP_SELL){
if (OrderMagicNumber()==Magic_Miku_S){
deleteMikuPending();
sendMikuPending(OrderOpenPrice(),Magic_Miku_S+1,Magic_Miku_B,XFactor*CoB,XFactor*CoA,com+"XB",com+"XA",sl2,sl1,r1,r1,sp0,sp,tp2,tp1);
return(0);
}

} }}

void sendMikuPending(double price, int ms,int mb,double lots,double lotb,string coms,string comb,double sls,double slb,double rs,double rb,double sps,double spb,double tps,double tpb){
double SL=0,TP=0;
int i;
if (StopLoss>0) {SL=NormalizeDouble(NormalizeDouble(OrderOpenPrice()-Range*rb*Point+spb*Point,Digits)-StopLoss*slb*Point,Digits);}else{SL=0;}
if (TakeProfit>0) {TP=NormalizeDouble(NormalizeDouble(OrderOpenPrice()-Range*rb*Point+spb*Point,Digits)+TakeProfit*tpb*Point,Digits);}else{TP=0;}
if (OrderSend(Symbol(),OP_BUYLIMIT,lotb,NormalizeDouble(OrderOpenPrice()-Range*rb*Point+spb*Point,Digits),Slippage,SL,TP,comb,mb,0,Blue)==-1) {
i=GetLastError();
if (i!=1 && i!=0) Print("Buy limit Error :"+error(i)+" at "+Symbol()+" "+Period());
}
if (StopLoss>0) {SL=NormalizeDouble(NormalizeDouble(OrderOpenPrice()+Range*rs*Point-sps*Point,Digits)+StopLoss*sls*Point,Digits);}else{SL=0;}
if (TakeProfit>0) {TP=NormalizeDouble(NormalizeDouble(OrderOpenPrice()+Range*rs*Point-sps*Point,Digits)-TakeProfit*tps*Point,Digits);}else{TP=0;}
if (OrderSend(Symbol(),OP_SELLLIMIT,lots,NormalizeDouble(OrderOpenPrice()+Range*rs*Point-sps*Point,Digits),Slippage,SL,TP,coms,ms,0,Red)==-1) {
i=GetLastError();
if (i!=1 && i!=0) Print("Sell limit Error :"+error(i)+" at "+Symbol()+" "+Period());
}
}

I think the EA must read the closed order, and make 1 new open order directly, but i didn't had a clue. How to read only the last closed order, their Magic number, their close price, etc ??

Please help anyone. Thank you so much.

Files:
mikultest.mq4  15 kb
 

could someone help me how to define the last closed order? how to check its magic number?

Thanks in advance

 
Change Brokers!! Trade the way you want. FXDD has been a very good broker, is in the US and allows Hedging all day long....
Reason: