سلام عليكم اانا استخدم اكسبرت مستردولار لكن وجدة فيه مشكل مزعج جدا وهو دئما اول امر هو بيع ديما بيع لا يفتح شراء ابدا
اريد اعرف اين كود لي فيه مشكل بحيث برنامج يصبح يفتح شراء وبيع حسب اختيار
وكذلك اريد اضافة امر حيث اذا كانت صفقه مفتوحه بيع عند غلق يفتح عكسها شراء وهكذا
اريد اعرف اين كود لي فيه مشكل بحيث برنامج يصبح يفتح شراء وبيع حسب اختيار
وكذلك اريد اضافة امر حيث اذا كانت صفقه مفتوحه بيع عند غلق يفتح عكسها شراء وهكذا
كود:
//+------------------------------------------------------------------+ //| www.arabictrader.com | //| MR.dollar | //+------------------------------------------------------------------+ #property copyright "MR.dollarEA" #property link "mrdollar.cs@gmail.com" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum order { SELL,BUY }; input bool EnableTimeFilter=false; input string Start_Hour="00:00"; input string End_Hour="23:00"; input string info_1=" Multiplier Settings "; input order FirstOrder= SELECT_BY_POS; input int Step=20; input int TakeProfit=20; input int StopLoss=0; input double Multiplier=2; input int TradesNumberForTakeProfit2=4; input int TakeProfit2=20; input bool EnableProfitUSD=false; input double TotalProfitUSD=0; input string info_2="Custom Lot Multiplier Settings"; input bool EnableCustomLot=false; input double Lots_1=0.1; input double Lots_2=0.1; input double Lots_3=0.1; input double Lots_4=0.1; input double Lots_5=0.1; input double Lots_6=0.1; input double Lots_7=0.1; input double Lots_8=0.1; input double Lots_9=0.1; input double Lots_10=0.1; input double Lots_11=0.1; input double Lots_12=0.1; input double Lots_13=0.1; input double Lots_14=0.1; input double Lots_15=0.1; input double Lots_16=0.1; input double Lots_17=0.1; input double Lots_18=0.1; input double Lots_19=0.1; input double Lots_20=0.1; input string MM_Parameters=" Money Management "; input double Lots=0.1; input bool MoneyManagement=false; input double Risk=1; input int MagicNumber=2035; double point; int digits,P; int lot_digits; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { if(MarketInfo(Symbol(),MODE_MINLOT)<0.1)lot_digits=2; else lot_digits=1; if(Digits==5 || Digits==3)P=10; else P=1; if(Digits<4) { point=0.01; digits=2; } else { point=0.0001; digits=4; } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| FUNCTION DEFINITIONS deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int orderscnt(int type=-1) { int cnt=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && MagicNumber==OrderMagicNumber() && (OrderType()==type || type==-1)) { cnt++; } } } return(cnt); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool TimeFilter(string StartH,string EndH) { datetime Start=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+StartH); datetime End=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+EndH); if(!(Time[0]>=Start && Time[0]<=End)) { return(false); } return(true); } //+------------------------------------------------------------------+ //| FUNCTION DEFINITIONS Start function | //+------------------------------------------------------------------+ void OnTick() { Comment("Programmed By MR.dollar\n"+"www.ArabicTrader.com"); if(EnableProfitUSD) { if(TotalProfit()>=TotalProfitUSD) { CloseAll(); } } double newLot,TP,SL,price,multiplier=Multiplier; int ticket; if(orderscnt(OP_BUY)>0 && orderscnt(OP_SELL)==0) { if(LastClosedOrderInfo("Time",OP_SELL)>LastCurrentOrderInfo("Time")) { CloseAll(); } } if(orderscnt(OP_SELL)>0 && orderscnt(OP_BUY)==0) { if(LastClosedOrderInfo("Time",OP_BUY)>LastCurrentOrderInfo("Time")) { CloseAll(); } } if((orderscnt(OP_SELL)==0 && orderscnt(OP_BUYSTOP)>0) || (orderscnt(OP_BUY)==0 && orderscnt(OP_SELLSTOP)>0)) { CloseAll(); } ModifyAllOrdersTP(OP_SELL); ModifyAllOrdersTP(OP_BUY); if(orderscnt()>0) { if(LastCurrentOrderInfo("Type")==OP_BUY && orderscnt(OP_SELLSTOP)==0) { price=LastCurrentOrderInfo("Price")-Step*point; if(TakeProfit!=0)TP=price-TakeProfit*point; if(orderscnt()>=TradesNumberForTakeProfit2)TP=price-TakeProfit2*point; if(StopLoss!=0)SL=price+StopLoss*point; newLot=NormalizeDouble(LastCurrentOrderInfo("Lots",OP_BUY)*multiplier,lot_digits); if(EnableCustomLot) { int order_num=int(LastCurrentOrderInfo("Comment",OP_BUY)); newLot=GetNextLot(order_num); } ticket=OrderSend(Symbol(),OP_SELLSTOP,newLot,NormalizeDouble(price,Digits),3*P,SL,TP,string(order_num+1),MagicNumber,0,Red); if(ticket<0)Print("Open Sell Stop Error: "+GetLastError()); } if(LastCurrentOrderInfo("Type")==OP_SELL && orderscnt(OP_BUYSTOP)==0) { price=LastCurrentOrderInfo("Price")+Step*point; if(TakeProfit!=0)TP=price+TakeProfit*point; if(orderscnt()>=TradesNumberForTakeProfit2)TP=price+TakeProfit2*point; if(StopLoss!=0)SL=price-StopLoss*point; newLot=NormalizeDouble(LastCurrentOrderInfo("Lots",OP_SELL)*multiplier,lot_digits); if(EnableCustomLot) { order_num=int(LastCurrentOrderInfo("Comment",OP_SELL)); newLot=GetNextLot(order_num); } ticket=OrderSend(Symbol(),OP_BUYSTOP,newLot,NormalizeDouble(price,Digits),3*P,SL,TP,string(order_num+1),MagicNumber,0,Blue); if(ticket<0)Print("Open Buy Stop Error: "+GetLastError()); } } //////////////////////////////////////////////////// if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)return; if(MoneyManagement) newLot=LotManage(); else newLot=Lots; //////////////////////////////// if(orderscnt()<1) { if(LastClosedOrderInfo("Type")==OP_SELL || (FirstOrder==BUY && LastClosedOrderInfo("Type")==-1)) { if(TakeProfit==0){TP=0;}else{TP=Ask+TakeProfit*point;} if(StopLoss!=0)SL=Ask-StopLoss*point; ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeDouble(Ask,Digits),3*P,SL,TP,"1",MagicNumber,0,Blue); } else { if(TakeProfit==0){TP=0;}else{TP=Bid-TakeProfit*point;} if(StopLoss!=0)SL=Bid+StopLoss*point; ticket=OrderSend(Symbol(),OP_SELL,newLot,NormalizeDouble(Bid,Digits),3*P,SL,TP,"1",MagicNumber,0,Red); } if(ticket<0)Print("Open Buy Error: "+GetLastError()); PlaySound("Alert.wav"); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetNextLot(int cnt) { switch(cnt) { case 1:return(Lots_2); case 2:return(Lots_3); case 3:return(Lots_4); case 4:return(Lots_5); case 5:return(Lots_6); case 6:return(Lots_7); case 7:return(Lots_8); case 8:return(Lots_9); case 9:return(Lots_10); case 10:return(Lots_11); case 11:return(Lots_12); case 12:return(Lots_13); case 13:return(Lots_14); case 14:return(Lots_15); case 15:return(Lots_16); case 16:return(Lots_17); case 17:return(Lots_18); case 18:return(Lots_19); case 19:return(Lots_20); default:return(Lots_20); } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double TotalProfit() { double profit; for(int i=0;i<OrdersTotal();i++) { bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { profit+=OrderProfit(); } } return(profit); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double LastClosedOrderInfo(string info,int type=-1) { for(int i=OrdersHistoryTotal()-1;i>=0;i--) { bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type || type==-1)) { if(info=="Type")return(OrderType()); else if(info=="Lots")return(OrderLots()); else if(info=="Price")return(OrderOpenPrice()); else if(info=="TP")return(OrderTakeProfit()); else if(info=="SL")return(OrderStopLoss()); else if(info=="Profit")return(OrderProfit()); else if(info=="Time")return(OrderCloseTime()); else if(info=="Comment")return(StringToDouble(OrderComment())); } } return(-1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double LastCurrentOrderInfo(string info,int type=-1) { for(int i=OrdersTotal()-1;i>=0;i--) { bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type || type==-1)) { if(info=="Type")return(OrderType()); else if(info=="Lots")return(OrderLots()); else if(info=="Price")return(OrderOpenPrice()); else if(info=="TP")return(OrderTakeProfit()); else if(info=="SL")return(OrderStopLoss()); else if(info=="Profit")return(OrderProfit()); else if(info=="Time")return(OrderOpenTime()); else if(info=="Comment")return(StringToDouble(OrderComment())); } } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ModifyAllOrdersTP(int type) { double TP=LastCurrentOrderInfo("TP",type); for(int i=OrdersTotal()-1;i>=0;i--) { bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderType()==type || type==-1)) { if(OrderTakeProfit()!=TP) { bool modify=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TP,0); } } } } //+------------------------------------------------------------------+ //| FUNCTION DEFINITIONS Money Managment | //+------------------------------------------------------------------+ double LotManage() { double lot=MathCeil(AccountFreeMargin() *Risk/1000)/100; if(lot<MarketInfo(Symbol(),MODE_MINLOT))lot=MarketInfo(Symbol(),MODE_MINLOT); if(lot>MarketInfo(Symbol(),MODE_MAXLOT))lot=MarketInfo(Symbol(),MODE_MAXLOT); return (NormalizeDouble(lot,2)); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CloseAll() { for(int i=OrdersTotal()-1;i>=0;i--) { bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) { bool close_b=OrderClose(OrderTicket(),OrderLots(),Bid,3*P); } else if(OrderType()==OP_SELL) { bool close_s=OrderClose(OrderTicket(),OrderLots(),Ask,3*P); } else { bool del=OrderDelete(OrderTicket()); } } } } //+---------------------------------------------------------------------------------+