else if(OrdersTotal()==2)
That's what you wrote.if(OrderSelect(0,SELECT_BY_POS)==true)
Using OrdersTotal directly and/or a specific position index, means your EA in incompatible with every other, including itself on other charts and manual trading. No filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum- You call OrderType but haven't selected a order.
Hi
I understand that using OrdersTotal directly could cause problems, I will try and keep the format correct.
I have managed to get the EA working placing initial market order and subsequent retracement orders using OrdersTotal as shown (which I believe could cause problems), how would you suggest using OrdersTotal in this situation?
Cheers
if(OrdersTotal()==1){ if(OrderOpenPrice() > buyRetracement) EnterTrade(OP_BUY); } else if(OrdersTotal()==2){ if(OrderOpenPrice() > buyRetracement2 ) EnterTrade(OP_BUY); } else if(OrdersTotal()==3){ if(OrderOpenPrice() > buyRetracement3 ) EnterTrade(OP_BUY); } else if(OrdersTotal()==4){ if(OrderOpenPrice() > buyRetracement4 ) EnterTrade(OP_BUY); }
Please can someone tell me how I could put this above into a loop so i dont use (ordersTotal()== , as i believe it is incorrect, bad coding. i have tried but failed as it keeps adding multiple trades on first new order, my attempt shown below, all im trying to do is open additional BUY orders when the price moves "retracementRisk" away from the OrderOpenPrice of each new order..
hope someone can assist
cheers Craig
double retracementRisk = risk*pips; int total=OrdersTotal(); for(int i = total-1; i >= 0; i--) { Comment("retracementtimes risk is: ",(string)retracementRisk+"\ntotal orders: ",(string)OrdersTotal()+"\nPips: ",(string)pips+"\nopen price : ",(string)OrderOpenPrice()+"\nAsk :" ,Ask); if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()==magic) if(OrderSymbol() != Symbol())continue; if(OrderType()==OP_BUY) if(OrderOpenPrice() -Ask > retracementRisk) { if(OrderOpenPrice()>Ask) EnterTrade(OP_BUY); } //else if(OrderType()==OP_SELL) //{ // if(Bid-OrderOpenPrice() > retracementRisk*pips) // if(OrderOpenPrice()<Bid) // EnterTrade(OP_SELL); //} }
double retracementRisk=risk*pips; int total=OrdersTotal(); double lowest_buy_entry=0; double highest_sell_entry=0; for(int i=total-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()==magic) if(OrderSymbol()!=Symbol())continue; if(OrderType()==OP_BUY) { if(lowest_buy_entry==0 || OrderOpenPrice()<lowest_buy_entry) lowest_buy_entry=OrderOpenPrice(); } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()>highest_sell_entry) highest_sell_entry=OrderOpenPrice(); } } } if(lowest_buy_entry -Ask>=retracementRisk) { EnterTrade(OP_BUY); } if(highest_sell_entry!=0 && Bid-highest_sell_entry>=retracementRisk) { EnterTrade(OP_SELL); }
Not compiled or tested
Thank you GumRai
Ill study what you have written, try and understand step by step.
Appreciate your time to help
Cheers Craig
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
Please can someone help me with my code..
I am very new as you will notice with my question so please go easy on me...
I am slowly writing an EA to open a market order when i place the EA on the chart (have managed this :)) then as price retraces 'R' pips the EA will add another position (have managed this..:)) but my problem is my code does not add any more positions, only initial and second position.
I have attached the part of the code in question ..
Hope some can steer me in right direction,
Cheers
Craig