Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?) General rules and best pratices of the Forum. - General - MQL5 programming forum - It's not a line of code. OrderSelect loop looking for magic number zero and the symbol being the same as the chart's symbol.
Using OrdersTotal directly and/or no Magic number 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 and MetaTrader 4 - MQL4 programming forum
First Of all Very Sorry For Posting In Wrong Section.
As I Told That I Am Not A programmer.
I Am Using MT4's Moving Average Ea
Can You Please Tell me the Code And Where Should I Enter It In EA So That It May Work Exactly I Need.
I Will be Very Thankful To You For This....
ziaalhassan: As I Told That I Am Not A programmer.
|
|
|
|
Thanks Sir. But As i Told Before I am Not A Programmer And I Need Help From Senior Programmers If Possible.
To Start Learning And Then Writing My Own Code Will Take A Lot Of Time For Me As I have No Experience In Programming.
Please Provide Direct Help If Possible,
Thank You Very Much
Here Is My Code.
extern int TrailingStop = 30; extern int StopLoss = 70; extern int TakeProfit = 100; extern bool MM = FALSE; extern double Risk = 1; extern double LotManual = 0.1; extern int MovingPeriod = 12; extern int MovingShift = 0; extern int Diffrence = 10; extern int Magic = 2008; void MoveTrailingStop() { int cnt,total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if( TrailingStop > 0 ) { if(Bid - OrderOpenPrice() > Point * TrailingStop) { if(OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen); continue; } } } } else { //Trailing stop if( TrailingStop > 0 ) { if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) { if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange); continue; } } } } } }} /****************************************-*/ int start() { double ticket; double SL,TP; int i,Total; int Dig=MarketInfo(Symbol(),MODE_DIGITS); double Ld_16 = 10.0 * Point; double Ld_24 = 5.0 * Point; /*****************************************************************************/ double ma; ma=iMA(Symbol(),0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); /*---------------------------------------------------------------------------*/ if (MyOrdersTotal(Magic)==0 ) { if ( Bid - ma > Diffrence * Point ) { ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",Magic,0,Green); }} if (MyOrdersTotal(Magic)==0 ) { if ( ma - Ask > Diffrence*Point ) { ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",Magic,0,Red); }} if(TrailingStop>0)MoveTrailingStop(); /////////////////////////////////// Total=OrdersTotal(); if(Total>0) { for(i=Total-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderStopLoss()==0 && OrderTakeProfit()==0) { if(StopLoss>0)SL=OrderOpenPrice()+StopLoss*Point;else SL=0; if(TakeProfit>0)TP=OrderOpenPrice()-TakeProfit*Point;else TP=0; OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL,Dig),NormalizeDouble(TP,Dig),OrderExpiration(),CLR_NONE); } if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderStopLoss()==0 && OrderTakeProfit()==0) { if(StopLoss>0)SL=OrderOpenPrice()-StopLoss*Point;else SL=0; if(TakeProfit>0)TP=OrderOpenPrice()+TakeProfit*Point;else TP=0; OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL,Dig),NormalizeDouble(TP,Dig),OrderExpiration(),CLR_NONE); } } } } ///////////////////////////////////// return(0); } int CloseOrders(int Magic) { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >= 0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) { if (OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),Bid,3); } if (OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Ask,3); } } } /////////////////////////////// ////////////////////////////// return(0); } int MyOrdersTotal(int Magic) { int c=0; int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) { c++; } } return(c); } double LotsOptimized() { double margin=MarketInfo(Symbol(), MODE_MARGINREQUIRED); double lot=0; if (MM==true){ lot=NormalizeDouble((AccountBalance()*Risk/10000), 2) ;} else lot=LotManual; if (lot>MarketInfo(Symbol(),MODE_MAXLOT)) { lot=MarketInfo(Symbol(),MODE_MAXLOT); } if (lot<MarketInfo(Symbol(),MODE_MINLOT)) { lot=MarketInfo(Symbol(),MODE_MINLOT); } return (lot); }
ziaalhassan:
But As i Told Before I am Not A Programmer And I Need Help From Senior Programmers If Possible. To Start Learning And Then Writing My Own Code Will Take A Lot Of Time For Me As I have No Experience In Programming. Please Provide Direct Help If Possible, |
|
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Friends, I Am Not A Mql4 Programmer But I Am Stuck In a Situation. I Have A Simple Moving Average Robot. Only I Want Is That If I Have Placed A Order manually Then My Robot Should Wait For The Order To Close Before It Start Trading.
What Line Of Code I Should Add In My Ea So That It Only Places A New Order After The Order Which i Have Placed manually Is Closed Either By hitting TP/Sl Or Closed By Me Manually.
I Hope I Have Clearly Explained My Question.
I Will Be Very thankful To You All For Your Quick Replies