المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : الرجاء المساعده في حل الاخطاء التاليه عند عمل Compile



أبو عمر جلال
07-02-2021, 01:53 AM
السلام عليكم ورحمة الله وبركاته
هلا وغلا

يظهر لي الاخطاء التاليه عند محاولة اضافه #property strict

الرجاء المساعده وشكرا لك



Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());

Alert("Open Buy Error: "+GetLastError()+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else

Alert("Open Sell Error: "+GetLastError()+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else

close=OrderClose(ticket,lot_to_close,Ask,3*P);
}

ClosedNumber++;

if(ClosedNumber>2)

return(ClosedNumber);
}

close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}

Price+=OrderOpenPrice()*OrderLots();

lots+=OrderLots();

if(lots!=0)
return(Price/lots);
else

return(Price/lots);
else
return(0);

return(OrderComment());

modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}

modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}

action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}



25803

Nadia Mohamed
07-02-2021, 01:57 AM
اظن اول اخطاء ممكن اضافه ,

أبو عمر جلال
07-02-2021, 01:59 AM
اظن اول اخطاء ممكن اضافه ,

عذرا لم تصلني الفكره
اشكرك علي كل حال

أبو عمر جلال
07-02-2021, 02:00 AM
السلام عليكم ورحمة الله وبركاته
هلا وغلا

يظهر لي الاخطاء التاليه عند محاولة اضافه #property strict

الرجاء المساعده وشكرا لك



Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());

Alert("Open Buy Error: "+GetLastError()+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else

Alert("Open Sell Error: "+GetLastError()+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else

close=OrderClose(ticket,lot_to_close,Ask,3*P);
}

ClosedNumber++;

if(ClosedNumber>2)

return(ClosedNumber);
}

close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}

Price+=OrderOpenPrice()*OrderLots();

lots+=OrderLots();

if(lots!=0)
return(Price/lots);
else

return(Price/lots);
else
return(0);

return(OrderComment());

modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}

modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}

action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}



25803


بعتذر عن فتح الموضوع مره تانيه بس حدث خطا في تحميل الموضوع بالمره الاولي

kira-h
07-02-2021, 04:38 PM
وعليكم السلام
الكود مبعثر بالصفحة، فضلا اضغط على "الانتقال للوضع المتطور" للمشاركة، وارفق الكود بملف mq4 او ادرجه ضمن مجال CODE (انظر الصورة)

25807

أبو عمر جلال
07-02-2021, 05:39 PM
وعليكم السلام
الكود مبعثر بالصفحة، فضلا اضغط على "الانتقال للوضع المتطور" للمشاركة، وارفق الكود بملف mq4 او ادرجه ضمن مجال CODE (انظر الصورة)

25807


Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Sell Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());
Print("Open Buy Error: "+GetLastError());


Alert("Open Buy Error: "+GetLastError()+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else


Alert("Open Sell Error: "+GetLastError()+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else


close=OrderClose(ticket,lot_to_close,Ask,3*P);
}


ClosedNumber++;


if(ClosedNumber>2)

return(ClosedNumber);
}


close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}


Price+=OrderOpenPrice()*OrderLots();

lots+=OrderLots();


if(lots!=0)
return(Price/lots);
else


return(Price/lots);
else
return(0);


return(OrderComment());


modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}


modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}


action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}


تفضل اخي الكريم

انا جمعت اسطر الاكواد الي بها المشكله
واسكرين باسفل لنص الاخطاء بنفس ترتيبها

25812

kira-h
07-02-2021, 10:33 PM
اخي لا يمكن معرفة سبب الاخطاء بجزء من الكود! فضلا ارفق الكود كاملا

أبو عمر جلال
07-02-2021, 11:42 PM
اخي لا يمكن معرفة سبب الاخطاء بجزء من الكود! فضلا ارفق الكود كاملا

تفضل اخي الكريم


//+------------------------------------------------------------------+//| Expert |
//| Copyright 2021, |
//| |
//+------------------------------------------------------------------+
#property copyright "L.t"
#property link "https://t.me/test"
#property version "1.00"
#property strict
input int MaxTrades=0;
input bool EnableTimeFilter=false;
input string Start_Hour="00:00";
input string End_Hour="23:00";


input bool CloseInReverse=true;
input string info1=" Money Management ";
input double Lots=0.1;
input bool MoneyManagement=false;
input double Risk=1;


input string info4=" Stochastic Settings ";
input bool EnableStochasticFilter=true;
input int Stoch_K=5;
input int Stoch_D=2;
input int Stoch_Slowing=2;
input ENUM_MA_METHOD Stoch_Method=MODE_SMA;
input ENUM_STO_PRICE Stoch_PriceField =STO_LOWHIGH;
input int Stoch_OverSold_Level=20;
input int Stoch_OverBought_Level=80;
input string info5=" Moving Average Settings ";
input bool EnableMAFilter=true;
input ENUM_TIMEFRAMES MA_TimeFrame_1=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_2=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_3=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_4=PERIOD_CURRENT;


input int MA_Period=200;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE MA_ApplyTo=PRICE_CLOSE;


input string info6=" Ichimoku Settings ";


input bool EnableIchimokuFilter=true;
input ENUM_TIMEFRAMES Ichimoku_TimeFrame=PERIOD_CURRENT;
input int Tenkan_Sen=9;
input int Kijun_Sen=26;
input int Senkou_Span_B=52;


input string info7=" MACD Settings ";
input bool EnableMACDFilter=true;
input int Fast_EMA=12;
input int Slow_EMA=26;
input int MACD_SMA=9;
input ENUM_APPLIED_PRICE Macd_ApplyTo=PRICE_CLOSE;




input string info8=" Multiplier Settings ";
input bool Enable_Multiplier=true;
input double Multiplier=2;
input int Step=50;
input bool UseAverageTP=true;
input int Av_TP=70;
input int StopLoss=0;
input int TakeProfit=0;
input int TrailingStop=0;
input int BreakEven=30;
input int BreakEvenPips=1;
input int MagicNumber=55555;


input bool EnableAlert=true;
input bool EnablePushNotification=true;
input bool EnableEmailNotification=true;
double point;
int digits,P;
datetime Time0;
datetime InitializedTime;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
InitializedTime=TimeCurrent();
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int orderscnt(int type)
{
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)
{
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
AlertClosedOrders();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)
return;


if(TrailingStop>0)
MoveTrailingStop();
if(BreakEven>0)
MoveBreakEven();


ParitalClose();


double newLot=0,TP=0,SL=0,TP1=0;
int ticket;




{
if(orderscnt(OP_SELL)==1&&orderscnt(OP_BUY)==0)
{


{
newLot=LastCurrentOrderInfo("Lots",OP_SELL);


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,0,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+GetLastError());
}
}
if(orderscnt(OP_BUY)>=1&&orderscnt(OP_SELL)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY);


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,0,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+GetLastError());
}
}
}


if(Enable_Multiplier)
{
if(orderscnt(OP_SELL)>=1)
{
if(Bid-LastCurrentOrderInfo("Price",OP_SELL)>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_SELL);


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,TP,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+GetLastError());


if(UseAverageTP)
ModifyOrders(OP_SELL);


}
}
if(orderscnt(OP_BUY)>=1)
{
if(LastCurrentOrderInfo("Price",OP_BUY)-Ask>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_BUY);


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,TP,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+GetLastError());


if(UseAverageTP)
ModifyOrders(OP_BUY);


}
}
}






int Macd_Signal=0,Stoch_Signal=0,MA_Signal_1=0,MA_Sign al_2=0,MA_Signal_3=0,MA_Signal_4=0,Ichimoku_Signal =0,Filters_Buy_Signal=0,Filters_Sell_Signal=0,Main _Signal_1=0,Main_Signal_2=0;


if(MACD(MODE_MAIN,1)>0)
Macd_Signal=1;
if(MACD(MODE_MAIN,1)<0)
Macd_Signal=-1;


if(Stoch(MODE_MAIN,1)<=Stoch_OverSold_Level||Stoch(MODE_MAIN,1)>Stoch(MODE_SIGNAL,1))
Stoch_Signal=1;
if(Stoch(MODE_MAIN,1)>=Stoch_OverBought_Level||Stoch(MODE_MAIN,1)<Stoch(MODE_SIGNAL,1))
Stoch_Signal=-1;


double ichimoku_upper_span=MathMax(Ichimoku(3,1),Ichimoku (4,1));
double ichimoku_lower_span=MathMin(Ichimoku(3,1),Ichimoku (4,1));


if(Close[1]>ichimoku_upper_span)
Ichimoku_Signal=1;
if(Close[1]<ichimoku_lower_span)
Ichimoku_Signal=-1;




if((Macd_Signal==1||!EnableMACDFilter)&&(Stoch_Signal==1||!EnableStochasticFilter)&&((MA_Signal_1==1&&MA_Signal_2==1&&MA_Signal_3==1&&MA_Signal_4==1)||!EnableMAFilter)&&(Ichimoku_Signal==1||!EnableIchimokuFilter))
Filters_Buy_Signal=1;
if((Macd_Signal==-1||!EnableMACDFilter)&&(Stoch_Signal==-1||!EnableStochasticFilter)&&((MA_Signal_1==-1&&MA_Signal_2==-1&&MA_Signal_3==-1&&MA_Signal_4==-1)||!EnableMAFilter)&&(Ichimoku_Signal==-1||!EnableIchimokuFilter))
Filters_Sell_Signal=1;






if(MoneyManagement)
newLot=LotManage();
else
newLot=Lots;


{
if(CloseInReverse)
CloseOrders(OP_SELL);


if(orderscnt(OP_BUY)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Ask-StopLoss*point;
if(TakeProfit!=0)
TP=Ask+TakeProfit*point;






ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,SL,NormalizeDouble(TP,Digits ),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Blue);
if(ticket<0)
Alert("Open Buy Error: "+GetLastError()+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Buy Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Ask,Digits));
Time0=Time[0];
}
}


{
if(CloseInReverse)
CloseOrders(OP_BUY);




if(orderscnt(OP_SELL)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Bid+StopLoss*point;
if(TakeProfit!=0)
TP=Bid-TakeProfit*point;




ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,SL,NormalizeDouble(TP,Digit s),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Red);
if(ticket<0)
Alert("Open Sell Error: "+GetLastError()+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Sell Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Bid,Digits));
Time0=Time[0];
}
}
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Direction(int signal)
{
if(signal==1)
return "UP";
if(signal==-1)
return "DOWN";
return "NA";
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestBottom()
{
for(int i=2; i<Bars-3; i++)
{
if(Low[i]<Low[i+1]&&Low[i]<Low[i-1]&&Low[i]<Bid)
return Low[i];
}
return 0;
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestTop()
{
for(int i=2; i<Bars-3; i++)
{
if(High[i]>High[i+1]&&High[i]>High[i-1]&&High[i]>Ask)
return High[i];
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ParitalClose()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
int ticket=OrderTicket();
int type=OrderType();
string result[];
StringSplit(OrderComment(),StringGetCharacter("_",0),result);
double lot_to_close=NormalizeDouble(OrderLots()/2,2);




if(ArraySize(result)>1&&StringToDouble(result[1])!=0&&lot_to_close>0&&searchClosedNumber(DoubleToStr(OrderTicket(),0))== 0)
{


double tp1=StringToDouble(result[1]);


if(type==OP_BUY&&Bid>=tp1)
{
bool close=OrderClose(ticket,lot_to_close,Bid,3*P);
}
else
if(type==OP_SELL&&Ask<=tp1)
{
close=OrderClose(ticket,lot_to_close,Ask,3*P);
}
}
}
}
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertClosedOrders()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderCloseTime()>=InitializedTime)
{
if(OrderType()==OP_BUY)
{
AlertOptions("Close Buy Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
else
if(OrderType()==OP_SELL)
{
AlertOptions("Close Sell Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
}
else
{


break;
}
}
}
InitializedTime=TimeCurrent();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int searchClosedNumber(string text)
{
int ClosedNumber;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
string comment=OrderComment();
int ticket=OrderTicket();
if(StringFind(comment,text,0)!=-1)
{
ClosedNumber++;
text=DoubleToStr(ticket,0);
}
if(ClosedNumber>2)
return(ClosedNumber);
}
return(ClosedNumber);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseOrders(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(OrderType()==OP_BUY)
{
bool close=OrderClose(OrderTicket(),OrderLots(),Bid,3*P );
}
else
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MA(int shift,ENUM_TIMEFRAMES timeframe)
{
double ma=iMA(Symbol(),timeframe,MA_Period,0,MA_Method,MA _ApplyTo,shift);
return ma;
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Stoch(int mode,int shift)
{
double stoch=iStochastic(Symbol(),0,Stoch_K,Stoch_D,Stoch _Slowing,Stoch_Method,Stoch_PriceField,mode,shift) ;
return stoch;
}




enum ichimoku_mode
{
SENKOUSPANA=3,
SENKOUSPANB=4
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Ichimoku(int mode,int shift)
{
double ichimoku=iIchimoku(Symbol(),Ichimoku_TimeFrame,Ten kan_Sen,Kijun_Sen,Senkou_Span_B,mode,shift);
return ichimoku;
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MACD(int mode,int shift)
{
double macd=iMACD(Symbol(),0,Fast_EMA,Slow_EMA,MACD_SMA,M acd_ApplyTo,mode,shift);
return macd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvTP(int type)
{
double Price;
double lots;
for(int i=0; i<OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
Price+=OrderOpenPrice()*OrderLots();
lots+=OrderLots();
}
}


if(lots!=0)
return(Price/lots);
else
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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=="Comment")
return(OrderComment());
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TotalProfit(int type=-1)
{
double profit=0;
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))
{
profit+=OrderProfit();
}
}
return(profit);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0 && NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*poin t,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blu e);
}
}
}
else
{
if(TrailingStop>0 && NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits))) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()<OrderOpenPrice()+BreakEvenPips*point)
{


bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+BreakEvenPips*poi nt,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-BreakEvenPips*point)
{


modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 ModifyOrders(int type)
{
for(int i=0; i<=OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
double take=OrderTakeProfit();
int ticket=OrderTicket();
int ordertype=OrderType();


if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==MagicNumber)
{


if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)+Av_TP*point,Digits) && ordertype==OP_BUY)
bool action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)+Av_TP*point,0);


if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)-Av_TP*point,Digits) && ordertype==OP_SELL)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertOptions(string text)
{
if(EnableAlert)
Alert(text);
if(EnableEmailNotification)
SendMail(text,text);
if(EnablePushNotification)
SendNotification(text);
}
//+---------------------------------------------------------------------------------+

kira-h
08-02-2021, 12:11 AM
تم التصحيح بالكود التالي :


//+------------------------------------------------------------------+//| Expert |
//| Copyright 2021, |
//| |
//+------------------------------------------------------------------+
#property copyright "L.t"
#property link "https://t.me/test"
#property version "1.00"
#property strict


input int MaxTrades=0;
input bool EnableTimeFilter=false;
input string Start_Hour="00:00";
input string End_Hour="23:00";
input bool CloseInReverse=true;


input string info1=" Money Management ";
input double Lots=0.1;
input bool MoneyManagement=false;
input double Risk=1;


input string info4=" Stochastic Settings ";
input bool EnableStochasticFilter=true;
input int Stoch_K=5;
input int Stoch_D=2;
input int Stoch_Slowing=2;
input ENUM_MA_METHOD Stoch_Method=MODE_SMA;
input ENUM_STO_PRICE Stoch_PriceField =STO_LOWHIGH;
input int Stoch_OverSold_Level=20;
input int Stoch_OverBought_Level=80;


input string info5=" Moving Average Settings ";
input bool EnableMAFilter=true;
input ENUM_TIMEFRAMES MA_TimeFrame_1=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_2=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_3=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_4=PERIOD_CURRENT;
input int MA_Period=200;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE MA_ApplyTo=PRICE_CLOSE;


input string info6=" Ichimoku Settings ";
input bool EnableIchimokuFilter=true;
input ENUM_TIMEFRAMES Ichimoku_TimeFrame=PERIOD_CURRENT;
input int Tenkan_Sen=9;
input int Kijun_Sen=26;
input int Senkou_Span_B=52;


input string info7=" MACD Settings ";
input bool EnableMACDFilter=true;
input int Fast_EMA=12;
input int Slow_EMA=26;
input int MACD_SMA=9;
input ENUM_APPLIED_PRICE Macd_ApplyTo=PRICE_CLOSE;


input string info8=" Multiplier Settings ";
input bool Enable_Multiplier=true;
input double Multiplier=2;
input int Step=50;
input bool UseAverageTP=true;
input int Av_TP=70;
input int StopLoss=0;
input int TakeProfit=0;
input int TrailingStop=0;
input int BreakEven=30;
input int BreakEvenPips=1;
input int MagicNumber=55555;
input bool EnableAlert=true;
input bool EnablePushNotification=true;
input bool EnableEmailNotification=true;


double point;
int digits,P;
datetime Time0;
datetime InitializedTime;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
InitializedTime=TimeCurrent();
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int orderscnt(int type)
{
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)
{
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
AlertClosedOrders();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)
return;


if(TrailingStop>0)
MoveTrailingStop();
if(BreakEven>0)
MoveBreakEven();


ParitalClose();


double newLot=0,TP=0,SL=0,TP1=0;
int ticket;

//if()
{
if(orderscnt(OP_SELL)==1&&orderscnt(OP_BUY)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL);
ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,0,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
}
}
if(orderscnt(OP_BUY)>=1&&orderscnt(OP_SELL)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY);
ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,0,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));
}
}
}


if(Enable_Multiplier)
{
if(orderscnt(OP_SELL)>=1)
{
if(Bid-LastCurrentOrderInfo("Price",OP_SELL)>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_SELL);




ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,TP,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
if(UseAverageTP)
ModifyOrders(OP_SELL);
}
}
if(orderscnt(OP_BUY)>=1)
{
if(LastCurrentOrderInfo("Price",OP_BUY)-Ask>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_BUY);




ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,TP,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));


if(UseAverageTP)
ModifyOrders(OP_BUY);
}
}
}

int Macd_Signal=0,Stoch_Signal=0,MA_Signal_1=0,MA_Sign al_2=0,MA_Signal_3=0,MA_Signal_4=0,Ichimoku_Signal =0,Filters_Buy_Signal=0,Filters_Sell_Signal=0,Main _Signal_1=0,Main_Signal_2=0;


if(MACD(MODE_MAIN,1)>0)
Macd_Signal=1;
if(MACD(MODE_MAIN,1)<0)
Macd_Signal=-1;


if(Stoch(MODE_MAIN,1)<=Stoch_OverSold_Level||Stoch(MODE_MAIN,1)>Stoch(MODE_SIGNAL,1))
Stoch_Signal=1;
if(Stoch(MODE_MAIN,1)>=Stoch_OverBought_Level||Stoch(MODE_MAIN,1)<Stoch(MODE_SIGNAL,1))
Stoch_Signal=-1;


double ichimoku_upper_span=MathMax(Ichimoku(3,1),Ichimoku (4,1));
double ichimoku_lower_span=MathMin(Ichimoku(3,1),Ichimoku (4,1));


if(Close[1]>ichimoku_upper_span)
Ichimoku_Signal=1;
if(Close[1]<ichimoku_lower_span)
Ichimoku_Signal=-1;


if((Macd_Signal==1||!EnableMACDFilter)&&(Stoch_Signal==1||!EnableStochasticFilter)&&((MA_Signal_1==1&&MA_Signal_2==1&&MA_Signal_3==1&&MA_Signal_4==1)||!EnableMAFilter)&&(Ichimoku_Signal==1||!EnableIchimokuFilter))
Filters_Buy_Signal=1;
if((Macd_Signal==-1||!EnableMACDFilter)&&(Stoch_Signal==-1||!EnableStochasticFilter)&&((MA_Signal_1==-1&&MA_Signal_2==-1&&MA_Signal_3==-1&&MA_Signal_4==-1)||!EnableMAFilter)&&(Ichimoku_Signal==-1||!EnableIchimokuFilter))
Filters_Sell_Signal=1;


if(MoneyManagement)
newLot=LotManage();
else
newLot=Lots;

//if()
{
if(CloseInReverse)
CloseOrders(OP_SELL);


if(orderscnt(OP_BUY)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Ask-StopLoss*point;
if(TakeProfit!=0)
TP=Ask+TakeProfit*point;


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,SL,NormalizeDouble(TP,Digits ),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Blue);
if(ticket<0)
Alert("Open Buy Error: "+string(GetLastError())+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Buy Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Ask,Digits));
Time0=Time[0];
}
}


////if()
{
if(CloseInReverse)
CloseOrders(OP_BUY);


if(orderscnt(OP_SELL)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Bid+StopLoss*point;
if(TakeProfit!=0)
TP=Bid-TakeProfit*point;


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,SL,NormalizeDouble(TP,Digit s),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Red);
if(ticket<0)
Alert("Open Sell Error: "+string(GetLastError())+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Sell Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Bid,Digits));
Time0=Time[0];
}
}
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Direction(int signal)
{
if(signal==1)
return "UP";
if(signal==-1)
return "DOWN";
return "NA";
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestBottom()
{
for(int i=2; i<Bars-3; i++)
{
if(Low[i]<Low[i+1]&&Low[i]<Low[i-1]&&Low[i]<Bid)
return Low[i];
}
return 0;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestTop()
{
for(int i=2; i<Bars-3; i++)
{
if(High[i]>High[i+1]&&High[i]>High[i-1]&&High[i]>Ask)
return High[i];
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ParitalClose()
{
bool close;
for(int i=OrdersTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
int ticket=OrderTicket();
int type=OrderType();
string result[];
StringSplit(OrderComment(),StringGetCharacter("_",0),result);
double lot_to_close=NormalizeDouble(OrderLots()/2,2);
if(ArraySize(result)>1&&StringToDouble(result[1])!=0&&lot_to_close>0&&searchClosedNumber(DoubleToStr(OrderTicket(),0))== 0)
{
double tp1=StringToDouble(result[1]);
if(type==OP_BUY&&Bid>=tp1)
{
close=OrderClose(ticket,lot_to_close,Bid,3*P);
}
else
if(type==OP_SELL&&Ask<=tp1)
{
close=OrderClose(ticket,lot_to_close,Ask,3*P);
}
}
}
}
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertClosedOrders()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderCloseTime()>=InitializedTime)
{
if(OrderType()==OP_BUY)
{
AlertOptions("Close Buy Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
else
if(OrderType()==OP_SELL)
{
AlertOptions("Close Sell Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
}
else
{




break;
}
}
}
InitializedTime=TimeCurrent();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int searchClosedNumber(string text)
{
int ClosedNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
string comment=OrderComment();
int ticket=OrderTicket();
if(StringFind(comment,text,0)!=-1)
{
ClosedNumber++;
text=DoubleToStr(ticket,0);
}
if(ClosedNumber>2)
return(ClosedNumber);
}
return(ClosedNumber);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseOrders(int type=-1)
{
bool close;
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(OrderType()==OP_BUY)
{
close=OrderClose(OrderTicket(),OrderLots(),Bid,3*P );
}
else
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MA(int shift,ENUM_TIMEFRAMES timeframe)
{
double ma=iMA(Symbol(),timeframe,MA_Period,0,MA_Method,MA _ApplyTo,shift);
return ma;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Stoch(int mode,int shift)
{
double stoch=iStochastic(Symbol(),0,Stoch_K,Stoch_D,Stoch _Slowing,Stoch_Method,Stoch_PriceField,mode,shift) ;
return stoch;
}








enum ichimoku_mode
{
SENKOUSPANA=3,
SENKOUSPANB=4
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Ichimoku(int mode,int shift)
{
double ichimoku=iIchimoku(Symbol(),Ichimoku_TimeFrame,Ten kan_Sen,Kijun_Sen,Senkou_Span_B,mode,shift);
return ichimoku;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MACD(int mode,int shift)
{
double macd=iMACD(Symbol(),0,Fast_EMA,Slow_EMA,MACD_SMA,M acd_ApplyTo,mode,shift);
return macd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvTP(int type)
{
double Price=0;
double lots=0;
for(int i=0; i<OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
Price+=OrderOpenPrice()*OrderLots();
lots+=OrderLots();
}
}




if(lots!=0)
return(Price/lots);
else
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TotalProfit(int type=-1)
{
double profit=0;
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))
{
profit+=OrderProfit();
}
}
return(profit);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0 && NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*poin t,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blu e);
}
}
}
else
{
if(TrailingStop>0 && NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits))) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()<OrderOpenPrice()+BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+BreakEvenPips*poi nt,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 ModifyOrders(int type)
{
bool action;
for(int i=0; i<=OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
double take=OrderTakeProfit();
int ticket=OrderTicket();
int ordertype=OrderType();




if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==MagicNumber)
{




if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)+Av_TP*point,Digits) && ordertype==OP_BUY)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)+Av_TP*point,0);




if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)-Av_TP*point,Digits) && ordertype==OP_SELL)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertOptions(string text)
{
if(EnableAlert)
Alert(text);
if(EnableEmailNotification)
SendMail(text,text);
if(EnablePushNotification)
SendNotification(text);
}
//+---------------------------------------------------------------------------------+

أبو عمر جلال
08-02-2021, 12:13 AM
لك كل التحيه والتقدير
اشكرك اخي الكريم

kira-h
08-02-2021, 07:17 PM
العفو وبالتوفيق إن شاء الله

أبو عمر جلال
12-02-2021, 01:28 AM
العفو وبالتوفيق إن شاء الله
ايانا واياكم يارب
جزاك الله كل خير

أبو عمر جلال
20-04-2021, 03:03 AM
تم التصحيح بالكود التالي :


//+------------------------------------------------------------------+//| Expert |
//| Copyright 2021, |
//| |
//+------------------------------------------------------------------+
#property copyright "L.t"
#property link "https://t.me/test"
#property version "1.00"
#property strict


input int MaxTrades=0;
input bool EnableTimeFilter=false;
input string Start_Hour="00:00";
input string End_Hour="23:00";
input bool CloseInReverse=true;


input string info1=" Money Management ";
input double Lots=0.1;
input bool MoneyManagement=false;
input double Risk=1;


input string info4=" Stochastic Settings ";
input bool EnableStochasticFilter=true;
input int Stoch_K=5;
input int Stoch_D=2;
input int Stoch_Slowing=2;
input ENUM_MA_METHOD Stoch_Method=MODE_SMA;
input ENUM_STO_PRICE Stoch_PriceField =STO_LOWHIGH;
input int Stoch_OverSold_Level=20;
input int Stoch_OverBought_Level=80;


input string info5=" Moving Average Settings ";
input bool EnableMAFilter=true;
input ENUM_TIMEFRAMES MA_TimeFrame_1=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_2=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_3=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_4=PERIOD_CURRENT;
input int MA_Period=200;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE MA_ApplyTo=PRICE_CLOSE;


input string info6=" Ichimoku Settings ";
input bool EnableIchimokuFilter=true;
input ENUM_TIMEFRAMES Ichimoku_TimeFrame=PERIOD_CURRENT;
input int Tenkan_Sen=9;
input int Kijun_Sen=26;
input int Senkou_Span_B=52;


input string info7=" MACD Settings ";
input bool EnableMACDFilter=true;
input int Fast_EMA=12;
input int Slow_EMA=26;
input int MACD_SMA=9;
input ENUM_APPLIED_PRICE Macd_ApplyTo=PRICE_CLOSE;


input string info8=" Multiplier Settings ";
input bool Enable_Multiplier=true;
input double Multiplier=2;
input int Step=50;
input bool UseAverageTP=true;
input int Av_TP=70;
input int StopLoss=0;
input int TakeProfit=0;
input int TrailingStop=0;
input int BreakEven=30;
input int BreakEvenPips=1;
input int MagicNumber=55555;
input bool EnableAlert=true;
input bool EnablePushNotification=true;
input bool EnableEmailNotification=true;


double point;
int digits,P;
datetime Time0;
datetime InitializedTime;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
InitializedTime=TimeCurrent();
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int orderscnt(int type)
{
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)
{
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);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
AlertClosedOrders();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)
return;


if(TrailingStop>0)
MoveTrailingStop();
if(BreakEven>0)
MoveBreakEven();


ParitalClose();


double newLot=0,TP=0,SL=0,TP1=0;
int ticket;

//if()
{
if(orderscnt(OP_SELL)==1&&orderscnt(OP_BUY)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL);
ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,0,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
}
}
if(orderscnt(OP_BUY)>=1&&orderscnt(OP_SELL)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY);
ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,0,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));
}
}
}


if(Enable_Multiplier)
{
if(orderscnt(OP_SELL)>=1)
{
if(Bid-LastCurrentOrderInfo("Price",OP_SELL)>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_SELL);




ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,TP,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
if(UseAverageTP)
ModifyOrders(OP_SELL);
}
}
if(orderscnt(OP_BUY)>=1)
{
if(LastCurrentOrderInfo("Price",OP_BUY)-Ask>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY)*Multiplier;
TP=LastCurrentOrderInfo("TP",OP_BUY);




ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,TP,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));


if(UseAverageTP)
ModifyOrders(OP_BUY);
}
}
}

int Macd_Signal=0,Stoch_Signal=0,MA_Signal_1=0,MA_Sign al_2=0,MA_Signal_3=0,MA_Signal_4=0,Ichimoku_Signal =0,Filters_Buy_Signal=0,Filters_Sell_Signal=0,Main _Signal_1=0,Main_Signal_2=0;


if(MACD(MODE_MAIN,1)>0)
Macd_Signal=1;
if(MACD(MODE_MAIN,1)<0)
Macd_Signal=-1;


if(Stoch(MODE_MAIN,1)<=Stoch_OverSold_Level||Stoch(MODE_MAIN,1)>Stoch(MODE_SIGNAL,1))
Stoch_Signal=1;
if(Stoch(MODE_MAIN,1)>=Stoch_OverBought_Level||Stoch(MODE_MAIN,1)<Stoch(MODE_SIGNAL,1))
Stoch_Signal=-1;


double ichimoku_upper_span=MathMax(Ichimoku(3,1),Ichimoku (4,1));
double ichimoku_lower_span=MathMin(Ichimoku(3,1),Ichimoku (4,1));


if(Close[1]>ichimoku_upper_span)
Ichimoku_Signal=1;
if(Close[1]<ichimoku_lower_span)
Ichimoku_Signal=-1;


if((Macd_Signal==1||!EnableMACDFilter)&&(Stoch_Signal==1||!EnableStochasticFilter)&&((MA_Signal_1==1&&MA_Signal_2==1&&MA_Signal_3==1&&MA_Signal_4==1)||!EnableMAFilter)&&(Ichimoku_Signal==1||!EnableIchimokuFilter))
Filters_Buy_Signal=1;
if((Macd_Signal==-1||!EnableMACDFilter)&&(Stoch_Signal==-1||!EnableStochasticFilter)&&((MA_Signal_1==-1&&MA_Signal_2==-1&&MA_Signal_3==-1&&MA_Signal_4==-1)||!EnableMAFilter)&&(Ichimoku_Signal==-1||!EnableIchimokuFilter))
Filters_Sell_Signal=1;


if(MoneyManagement)
newLot=LotManage();
else
newLot=Lots;

//if()
{
if(CloseInReverse)
CloseOrders(OP_SELL);


if(orderscnt(OP_BUY)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Ask-StopLoss*point;
if(TakeProfit!=0)
TP=Ask+TakeProfit*point;


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,SL,NormalizeDouble(TP,Digits ),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Blue);
if(ticket<0)
Alert("Open Buy Error: "+string(GetLastError())+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Buy Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Ask,Digits));
Time0=Time[0];
}
}


////if()
{
if(CloseInReverse)
CloseOrders(OP_BUY);


if(orderscnt(OP_SELL)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Bid+StopLoss*point;
if(TakeProfit!=0)
TP=Bid-TakeProfit*point;


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,SL,NormalizeDouble(TP,Digit s),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Red);
if(ticket<0)
Alert("Open Sell Error: "+string(GetLastError())+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Sell Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Bid,Digits));
Time0=Time[0];
}
}
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Direction(int signal)
{
if(signal==1)
return "UP";
if(signal==-1)
return "DOWN";
return "NA";
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestBottom()
{
for(int i=2; i<Bars-3; i++)
{
if(Low[i]<Low[i+1]&&Low[i]<Low[i-1]&&Low[i]<Bid)
return Low[i];
}
return 0;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestTop()
{
for(int i=2; i<Bars-3; i++)
{
if(High[i]>High[i+1]&&High[i]>High[i-1]&&High[i]>Ask)
return High[i];
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ParitalClose()
{
bool close;
for(int i=OrdersTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
int ticket=OrderTicket();
int type=OrderType();
string result[];
StringSplit(OrderComment(),StringGetCharacter("_",0),result);
double lot_to_close=NormalizeDouble(OrderLots()/2,2);
if(ArraySize(result)>1&&StringToDouble(result[1])!=0&&lot_to_close>0&&searchClosedNumber(DoubleToStr(OrderTicket(),0))== 0)
{
double tp1=StringToDouble(result[1]);
if(type==OP_BUY&&Bid>=tp1)
{
close=OrderClose(ticket,lot_to_close,Bid,3*P);
}
else
if(type==OP_SELL&&Ask<=tp1)
{
close=OrderClose(ticket,lot_to_close,Ask,3*P);
}
}
}
}
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertClosedOrders()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderCloseTime()>=InitializedTime)
{
if(OrderType()==OP_BUY)
{
AlertOptions("Close Buy Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
else
if(OrderType()==OP_SELL)
{
AlertOptions("Close Sell Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
}
else
{




break;
}
}
}
InitializedTime=TimeCurrent();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int searchClosedNumber(string text)
{
int ClosedNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
string comment=OrderComment();
int ticket=OrderTicket();
if(StringFind(comment,text,0)!=-1)
{
ClosedNumber++;
text=DoubleToStr(ticket,0);
}
if(ClosedNumber>2)
return(ClosedNumber);
}
return(ClosedNumber);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseOrders(int type=-1)
{
bool close;
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(OrderType()==OP_BUY)
{
close=OrderClose(OrderTicket(),OrderLots(),Bid,3*P );
}
else
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MA(int shift,ENUM_TIMEFRAMES timeframe)
{
double ma=iMA(Symbol(),timeframe,MA_Period,0,MA_Method,MA _ApplyTo,shift);
return ma;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Stoch(int mode,int shift)
{
double stoch=iStochastic(Symbol(),0,Stoch_K,Stoch_D,Stoch _Slowing,Stoch_Method,Stoch_PriceField,mode,shift) ;
return stoch;
}








enum ichimoku_mode
{
SENKOUSPANA=3,
SENKOUSPANB=4
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Ichimoku(int mode,int shift)
{
double ichimoku=iIchimoku(Symbol(),Ichimoku_TimeFrame,Ten kan_Sen,Kijun_Sen,Senkou_Span_B,mode,shift);
return ichimoku;
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MACD(int mode,int shift)
{
double macd=iMACD(Symbol(),0,Fast_EMA,Slow_EMA,MACD_SMA,M acd_ApplyTo,mode,shift);
return macd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvTP(int type)
{
double Price=0;
double lots=0;
for(int i=0; i<OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
Price+=OrderOpenPrice()*OrderLots();
lots+=OrderLots();
}
}




if(lots!=0)
return(Price/lots);
else
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TotalProfit(int type=-1)
{
double profit=0;
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))
{
profit+=OrderProfit();
}
}
return(profit);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0 && NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*poin t,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blu e);
}
}
}
else
{
if(TrailingStop>0 && NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits))) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()<OrderOpenPrice()+BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+BreakEvenPips*poi nt,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 ModifyOrders(int type)
{
bool action;
for(int i=0; i<=OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
double take=OrderTakeProfit();
int ticket=OrderTicket();
int ordertype=OrderType();




if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==MagicNumber)
{




if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)+Av_TP*point,Digits) && ordertype==OP_BUY)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)+Av_TP*point,0);




if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)-Av_TP*point,Digits) && ordertype==OP_SELL)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertOptions(string text)
{
if(EnableAlert)
Alert(text);
if(EnableEmailNotification)
SendMail(text,text);
if(EnablePushNotification)
SendNotification(text);
}
//+---------------------------------------------------------------------------------+


عزيزي الغالي الكريم باش مهندس حسن
استاذنك كنت عاوز اضيف خاصيه MaxLot للاكسبرت المرفق
ولك التحيه والتقدير

kira-h
20-04-2021, 07:55 PM
عزيزي الغالي الكريم باش مهندس حسن
استاذنك كنت عاوز اضيف خاصيه MaxLot للاكسبرت المرفق
ولك التحيه والتقدير
مرحبا اخي الكريم
مرفق الكود



//+------------------------------------------------------------------+//| Expert |
//| Copyright 2021, |
//| |
//+------------------------------------------------------------------+
#property copyright "L.t"
#property link "https://t.me/test"
#property version "1.00"
#property strict




input int MaxTrades=0;
input bool EnableTimeFilter=false;
input string Start_Hour="00:00";
input string End_Hour="23:00";
input bool CloseInReverse=true;




input string info1=" Money Management ";
input double Lots=0.01,
Multiplier=2,
MaxLots=0,
Risk=0,
MaxRisk=0;


input string info4=" Stochastic Settings ";
input bool EnableStochasticFilter=true;
input int Stoch_K=5;
input int Stoch_D=2;
input int Stoch_Slowing=2;
input ENUM_MA_METHOD Stoch_Method=MODE_SMA;
input ENUM_STO_PRICE Stoch_PriceField =STO_LOWHIGH;
input int Stoch_OverSold_Level=20;
input int Stoch_OverBought_Level=80;




input string info5=" Moving Average Settings ";
input bool EnableMAFilter=true;
input ENUM_TIMEFRAMES MA_TimeFrame_1=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_2=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_3=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_4=PERIOD_CURRENT;
input int MA_Period=200;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE MA_ApplyTo=PRICE_CLOSE;




input string info6=" Ichimoku Settings ";
input bool EnableIchimokuFilter=true;
input ENUM_TIMEFRAMES Ichimoku_TimeFrame=PERIOD_CURRENT;
input int Tenkan_Sen=9;
input int Kijun_Sen=26;
input int Senkou_Span_B=52;




input string info7=" MACD Settings ";
input bool EnableMACDFilter=true;
input int Fast_EMA=12;
input int Slow_EMA=26;
input int MACD_SMA=9;
input ENUM_APPLIED_PRICE Macd_ApplyTo=PRICE_CLOSE;




input string info8=" Orders Management ";
input int Step=50;
input bool UseAverageTP=true;
input int Av_TP=70;
input int StopLoss=0;
input int TakeProfit=0;
input int TrailingStop=0;
input int BreakEven=30;
input int BreakEvenPips=1;
input int MagicNumber=55555;
input bool EnableAlert=true;
input bool EnablePushNotification=true;
input bool EnableEmailNotification=true;




double point;
int digits,P;
datetime Time0;
datetime InitializedTime;




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
InitializedTime=TimeCurrent();
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);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int orderscnt(int type)
{
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)
{
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);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
AlertClosedOrders();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)
return;




if(TrailingStop>0)
MoveTrailingStop();
if(BreakEven>0)
MoveBreakEven();




ParitalClose();




double newLot=0,TP=0,SL=0,TP1=0;
int ticket=0;

//if()
{
if(orderscnt(OP_SELL)==1&&orderscnt(OP_BUY)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL);
ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,0,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
}
}
if(orderscnt(OP_BUY)>=1&&orderscnt(OP_SELL)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY);
ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,0,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));
}
}
}




if(Multiplier>0)
{
if(orderscnt(OP_SELL)>=1)
{
if(Bid-LastCurrentOrderInfo("Price",OP_SELL)>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL)*Multiplier;
if(MaxLots>0&&newLot>=MaxLots)newLot=Lots;
if(MaxRisk>0&&Risk>0&&newLot>=LotManage(MaxRisk))newLot=LotManage(Risk);

TP=LastCurrentOrderInfo("TP",OP_SELL);


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,TP,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
if(UseAverageTP)
ModifyOrders(OP_SELL);
}
}
if(orderscnt(OP_BUY)>=1)
{
if(LastCurrentOrderInfo("Price",OP_BUY)-Ask>=Step*point)
{
if(Multiplier>0)newLot=LastCurrentOrderInfo("Lots",OP_BUY)*Multiplier;
if(MaxLots>0&&newLot>=MaxLots)newLot=Lots;
if(MaxRisk>0&&Risk>0&&newLot>=LotManage(MaxRisk))newLot=LotManage(Risk);
TP=LastCurrentOrderInfo("TP",OP_BUY);


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,TP,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));


if(UseAverageTP)
ModifyOrders(OP_BUY);
}
}
}

int Macd_Signal=0,Stoch_Signal=0,MA_Signal_1=0,MA_Sign al_2=0,MA_Signal_3=0,MA_Signal_4=0,Ichimoku_Signal =0,Filters_Buy_Signal=0,Filters_Sell_Signal=0,Main _Signal_1=0,Main_Signal_2=0;




if(MACD(MODE_MAIN,1)>0)
Macd_Signal=1;
if(MACD(MODE_MAIN,1)<0)
Macd_Signal=-1;




if(Stoch(MODE_MAIN,1)<=Stoch_OverSold_Level||Stoch(MODE_MAIN,1)>Stoch(MODE_SIGNAL,1))
Stoch_Signal=1;
if(Stoch(MODE_MAIN,1)>=Stoch_OverBought_Level||Stoch(MODE_MAIN,1)<Stoch(MODE_SIGNAL,1))
Stoch_Signal=-1;




double ichimoku_upper_span=MathMax(Ichimoku(3,1),Ichimoku (4,1));
double ichimoku_lower_span=MathMin(Ichimoku(3,1),Ichimoku (4,1));




if(Close[1]>ichimoku_upper_span)
Ichimoku_Signal=1;
if(Close[1]<ichimoku_lower_span)
Ichimoku_Signal=-1;




if((Macd_Signal==1||!EnableMACDFilter)&&(Stoch_Signal==1||!EnableStochasticFilter)&&((MA_Signal_1==1&&MA_Signal_2==1&&MA_Signal_3==1&&MA_Signal_4==1)||!EnableMAFilter)&&(Ichimoku_Signal==1||!EnableIchimokuFilter))
Filters_Buy_Signal=1;
if((Macd_Signal==-1||!EnableMACDFilter)&&(Stoch_Signal==-1||!EnableStochasticFilter)&&((MA_Signal_1==-1&&MA_Signal_2==-1&&MA_Signal_3==-1&&MA_Signal_4==-1)||!EnableMAFilter)&&(Ichimoku_Signal==-1||!EnableIchimokuFilter))
Filters_Sell_Signal=1;




if(Risk>0)
newLot=LotManage(Risk);
else
newLot=Lots;

//if()
{
if(CloseInReverse)
CloseOrders(OP_SELL);




if(orderscnt(OP_BUY)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Ask-StopLoss*point;
if(TakeProfit!=0)
TP=Ask+TakeProfit*point;




ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,SL,NormalizeDouble(TP,Digits ),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Blue);
if(ticket<0)
Alert("Open Buy Error: "+string(GetLastError())+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Buy Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Ask,Digits));
Time0=Time[0];
}
}




////if()
{
if(CloseInReverse)
CloseOrders(OP_BUY);




if(orderscnt(OP_SELL)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Bid+StopLoss*point;
if(TakeProfit!=0)
TP=Bid-TakeProfit*point;




ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,SL,NormalizeDouble(TP,Digit s),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Red);
if(ticket<0)
Alert("Open Sell Error: "+string(GetLastError())+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Sell Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Bid,Digits));
Time0=Time[0];
}
}
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Direction(int signal)
{
if(signal==1)
return "UP";
if(signal==-1)
return "DOWN";
return "NA";
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestBottom()
{
for(int i=2; i<Bars-3; i++)
{
if(Low[i]<Low[i+1]&&Low[i]<Low[i-1]&&Low[i]<Bid)
return Low[i];
}
return 0;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestTop()
{
for(int i=2; i<Bars-3; i++)
{
if(High[i]>High[i+1]&&High[i]>High[i-1]&&High[i]>Ask)
return High[i];
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ParitalClose()
{
bool close;
for(int i=OrdersTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
int ticket=OrderTicket();
int type=OrderType();
string result[];
StringSplit(OrderComment(),StringGetCharacter("_",0),result);
double lot_to_close=NormalizeDouble(OrderLots()/2,2);
if(ArraySize(result)>1&&StringToDouble(result[1])!=0&&lot_to_close>0&&searchClosedNumber(DoubleToStr(OrderTicket(),0))== 0)
{
double tp1=StringToDouble(result[1]);
if(type==OP_BUY&&Bid>=tp1)
{
close=OrderClose(ticket,lot_to_close,Bid,3*P);
}
else
if(type==OP_SELL&&Ask<=tp1)
{
close=OrderClose(ticket,lot_to_close,Ask,3*P);
}
}
}
}
}
















//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertClosedOrders()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderCloseTime()>=InitializedTime)
{
if(OrderType()==OP_BUY)
{
AlertOptions("Close Buy Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
else
if(OrderType()==OP_SELL)
{
AlertOptions("Close Sell Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
}
else
{








break;
}
}
}
InitializedTime=TimeCurrent();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int searchClosedNumber(string text)
{
int ClosedNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
string comment=OrderComment();
int ticket=OrderTicket();
if(StringFind(comment,text,0)!=-1)
{
ClosedNumber++;
text=DoubleToStr(ticket,0);
}
if(ClosedNumber>2)
return(ClosedNumber);
}
return(ClosedNumber);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseOrders(int type=-1)
{
bool close;
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(OrderType()==OP_BUY)
{
close=OrderClose(OrderTicket(),OrderLots(),Bid,3*P );
}
else
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MA(int shift,ENUM_TIMEFRAMES timeframe)
{
double ma=iMA(Symbol(),timeframe,MA_Period,0,MA_Method,MA _ApplyTo,shift);
return ma;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Stoch(int mode,int shift)
{
double stoch=iStochastic(Symbol(),0,Stoch_K,Stoch_D,Stoch _Slowing,Stoch_Method,Stoch_PriceField,mode,shift) ;
return stoch;
}
















enum ichimoku_mode
{
SENKOUSPANA=3,
SENKOUSPANB=4
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Ichimoku(int mode,int shift)
{
double ichimoku=iIchimoku(Symbol(),Ichimoku_TimeFrame,Ten kan_Sen,Kijun_Sen,Senkou_Span_B,mode,shift);
return ichimoku;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MACD(int mode,int shift)
{
double macd=iMACD(Symbol(),0,Fast_EMA,Slow_EMA,MACD_SMA,M acd_ApplyTo,mode,shift);
return macd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvTP(int type)
{
double Price=0;
double lots=0;
for(int i=0; i<OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
Price+=OrderOpenPrice()*OrderLots();
lots+=OrderLots();
}
}








if(lots!=0)
return(Price/lots);
else
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TotalProfit(int type=-1)
{
double profit=0;
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))
{
profit+=OrderProfit();
}
}
return(profit);
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0 && NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*poin t,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blu e);
}
}
}
else
{
if(TrailingStop>0 && NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits))) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()<OrderOpenPrice()+BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+BreakEvenPips*poi nt,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LotManage(double risk)
{
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 ModifyOrders(int type)
{
bool action;
for(int i=0; i<=OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
double take=OrderTakeProfit();
int ticket=OrderTicket();
int ordertype=OrderType();








if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==MagicNumber)
{








if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)+Av_TP*point,Digits) && ordertype==OP_BUY)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)+Av_TP*point,0);








if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)-Av_TP*point,Digits) && ordertype==OP_SELL)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
















//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertOptions(string text)
{
if(EnableAlert)
Alert(text);
if(EnableEmailNotification)
SendMail(text,text);
if(EnablePushNotification)
SendNotification(text);
}

أبو عمر جلال
21-04-2021, 03:45 AM
مرحبا اخي الكريم
مرفق الكود



//+------------------------------------------------------------------+//| Expert |
//| Copyright 2021, |
//| |
//+------------------------------------------------------------------+
#property copyright "L.t"
#property link "https://t.me/test"
#property version "1.00"
#property strict




input int MaxTrades=0;
input bool EnableTimeFilter=false;
input string Start_Hour="00:00";
input string End_Hour="23:00";
input bool CloseInReverse=true;




input string info1=" Money Management ";
input double Lots=0.01,
Multiplier=2,
MaxLots=0,
Risk=0,
MaxRisk=0;


input string info4=" Stochastic Settings ";
input bool EnableStochasticFilter=true;
input int Stoch_K=5;
input int Stoch_D=2;
input int Stoch_Slowing=2;
input ENUM_MA_METHOD Stoch_Method=MODE_SMA;
input ENUM_STO_PRICE Stoch_PriceField =STO_LOWHIGH;
input int Stoch_OverSold_Level=20;
input int Stoch_OverBought_Level=80;




input string info5=" Moving Average Settings ";
input bool EnableMAFilter=true;
input ENUM_TIMEFRAMES MA_TimeFrame_1=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_2=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_3=PERIOD_CURRENT;
input ENUM_TIMEFRAMES MA_TimeFrame_4=PERIOD_CURRENT;
input int MA_Period=200;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE MA_ApplyTo=PRICE_CLOSE;




input string info6=" Ichimoku Settings ";
input bool EnableIchimokuFilter=true;
input ENUM_TIMEFRAMES Ichimoku_TimeFrame=PERIOD_CURRENT;
input int Tenkan_Sen=9;
input int Kijun_Sen=26;
input int Senkou_Span_B=52;




input string info7=" MACD Settings ";
input bool EnableMACDFilter=true;
input int Fast_EMA=12;
input int Slow_EMA=26;
input int MACD_SMA=9;
input ENUM_APPLIED_PRICE Macd_ApplyTo=PRICE_CLOSE;




input string info8=" Orders Management ";
input int Step=50;
input bool UseAverageTP=true;
input int Av_TP=70;
input int StopLoss=0;
input int TakeProfit=0;
input int TrailingStop=0;
input int BreakEven=30;
input int BreakEvenPips=1;
input int MagicNumber=55555;
input bool EnableAlert=true;
input bool EnablePushNotification=true;
input bool EnableEmailNotification=true;




double point;
int digits,P;
datetime Time0;
datetime InitializedTime;




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
InitializedTime=TimeCurrent();
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);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int orderscnt(int type)
{
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)
{
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);
}




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
AlertClosedOrders();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)
return;




if(TrailingStop>0)
MoveTrailingStop();
if(BreakEven>0)
MoveBreakEven();




ParitalClose();




double newLot=0,TP=0,SL=0,TP1=0;
int ticket=0;

//if()
{
if(orderscnt(OP_SELL)==1&&orderscnt(OP_BUY)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL);
ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,0,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
}
}
if(orderscnt(OP_BUY)>=1&&orderscnt(OP_SELL)==0)
{
{
newLot=LastCurrentOrderInfo("Lots",OP_BUY);
ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,0,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));
}
}
}




if(Multiplier>0)
{
if(orderscnt(OP_SELL)>=1)
{
if(Bid-LastCurrentOrderInfo("Price",OP_SELL)>=Step*point)
{
newLot=LastCurrentOrderInfo("Lots",OP_SELL)*Multiplier;
if(MaxLots>0&&newLot>=MaxLots)newLot=Lots;
if(MaxRisk>0&&Risk>0&&newLot>=LotManage(MaxRisk))newLot=LotManage(Risk);

TP=LastCurrentOrderInfo("TP",OP_SELL);


ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,0,TP,"EA",MagicNumber,0,Red);
if(ticket<0)
Print("Open Sell Error: "+string(GetLastError()));
if(UseAverageTP)
ModifyOrders(OP_SELL);
}
}
if(orderscnt(OP_BUY)>=1)
{
if(LastCurrentOrderInfo("Price",OP_BUY)-Ask>=Step*point)
{
if(Multiplier>0)newLot=LastCurrentOrderInfo("Lots",OP_BUY)*Multiplier;
if(MaxLots>0&&newLot>=MaxLots)newLot=Lots;
if(MaxRisk>0&&Risk>0&&newLot>=LotManage(MaxRisk))newLot=LotManage(Risk);
TP=LastCurrentOrderInfo("TP",OP_BUY);


ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,0,TP,"EA",MagicNumber,0,Blue);
if(ticket<0)
Print("Open Buy Error: "+string(GetLastError()));


if(UseAverageTP)
ModifyOrders(OP_BUY);
}
}
}

int Macd_Signal=0,Stoch_Signal=0,MA_Signal_1=0,MA_Sign al_2=0,MA_Signal_3=0,MA_Signal_4=0,Ichimoku_Signal =0,Filters_Buy_Signal=0,Filters_Sell_Signal=0,Main _Signal_1=0,Main_Signal_2=0;




if(MACD(MODE_MAIN,1)>0)
Macd_Signal=1;
if(MACD(MODE_MAIN,1)<0)
Macd_Signal=-1;




if(Stoch(MODE_MAIN,1)<=Stoch_OverSold_Level||Stoch(MODE_MAIN,1)>Stoch(MODE_SIGNAL,1))
Stoch_Signal=1;
if(Stoch(MODE_MAIN,1)>=Stoch_OverBought_Level||Stoch(MODE_MAIN,1)<Stoch(MODE_SIGNAL,1))
Stoch_Signal=-1;




double ichimoku_upper_span=MathMax(Ichimoku(3,1),Ichimoku (4,1));
double ichimoku_lower_span=MathMin(Ichimoku(3,1),Ichimoku (4,1));




if(Close[1]>ichimoku_upper_span)
Ichimoku_Signal=1;
if(Close[1]<ichimoku_lower_span)
Ichimoku_Signal=-1;




if((Macd_Signal==1||!EnableMACDFilter)&&(Stoch_Signal==1||!EnableStochasticFilter)&&((MA_Signal_1==1&&MA_Signal_2==1&&MA_Signal_3==1&&MA_Signal_4==1)||!EnableMAFilter)&&(Ichimoku_Signal==1||!EnableIchimokuFilter))
Filters_Buy_Signal=1;
if((Macd_Signal==-1||!EnableMACDFilter)&&(Stoch_Signal==-1||!EnableStochasticFilter)&&((MA_Signal_1==-1&&MA_Signal_2==-1&&MA_Signal_3==-1&&MA_Signal_4==-1)||!EnableMAFilter)&&(Ichimoku_Signal==-1||!EnableIchimokuFilter))
Filters_Sell_Signal=1;




if(Risk>0)
newLot=LotManage(Risk);
else
newLot=Lots;

//if()
{
if(CloseInReverse)
CloseOrders(OP_SELL);




if(orderscnt(OP_BUY)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Ask-StopLoss*point;
if(TakeProfit!=0)
TP=Ask+TakeProfit*point;




ticket=OrderSend(Symbol(),OP_BUY,newLot,NormalizeD ouble(Ask,Digits),3*P,SL,NormalizeDouble(TP,Digits ),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Blue);
if(ticket<0)
Alert("Open Buy Error: "+string(GetLastError())+" Ask: "+string(Ask)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Buy Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Ask,Digits));
Time0=Time[0];
}
}




////if()
{
if(CloseInReverse)
CloseOrders(OP_BUY);




if(orderscnt(OP_SELL)<MaxTrades||MaxTrades==0)
{
if(StopLoss!=0)
SL=Bid+StopLoss*point;
if(TakeProfit!=0)
TP=Bid-TakeProfit*point;




ticket=OrderSend(Symbol(),OP_SELL,newLot,Normalize Double(Bid,Digits),3*P,SL,NormalizeDouble(TP,Digit s),"EA_"+DoubleToStr(TP1,Digits),MagicNumber,0,Red);
if(ticket<0)
Alert("Open Sell Error: "+string(GetLastError())+" Bid: "+string(Bid)+" TP: "+string(TP)+" SL: "+string(SL));
else
AlertOptions("Open Sell Order Ticket #"+string(ticket)+"Symbol: "+Symbol()+" @"+DoubleToStr(Bid,Digits));
Time0=Time[0];
}
}
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Direction(int signal)
{
if(signal==1)
return "UP";
if(signal==-1)
return "DOWN";
return "NA";
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestBottom()
{
for(int i=2; i<Bars-3; i++)
{
if(Low[i]<Low[i+1]&&Low[i]<Low[i-1]&&Low[i]<Bid)
return Low[i];
}
return 0;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetNearestTop()
{
for(int i=2; i<Bars-3; i++)
{
if(High[i]>High[i+1]&&High[i]>High[i-1]&&High[i]>Ask)
return High[i];
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ParitalClose()
{
bool close;
for(int i=OrdersTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
int ticket=OrderTicket();
int type=OrderType();
string result[];
StringSplit(OrderComment(),StringGetCharacter("_",0),result);
double lot_to_close=NormalizeDouble(OrderLots()/2,2);
if(ArraySize(result)>1&&StringToDouble(result[1])!=0&&lot_to_close>0&&searchClosedNumber(DoubleToStr(OrderTicket(),0))== 0)
{
double tp1=StringToDouble(result[1]);
if(type==OP_BUY&&Bid>=tp1)
{
close=OrderClose(ticket,lot_to_close,Bid,3*P);
}
else
if(type==OP_SELL&&Ask<=tp1)
{
close=OrderClose(ticket,lot_to_close,Ask,3*P);
}
}
}
}
}
















//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertClosedOrders()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderCloseTime()>=InitializedTime)
{
if(OrderType()==OP_BUY)
{
AlertOptions("Close Buy Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
else
if(OrderType()==OP_SELL)
{
AlertOptions("Close Sell Order Ticket #"+string(OrderTicket())+" on TP1 "+Symbol()+" @"+DoubleToStr(OrderClosePrice(),Digits)+" Profit: "+string(OrderProfit()));
}
}
else
{








break;
}
}
}
InitializedTime=TimeCurrent();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int searchClosedNumber(string text)
{
int ClosedNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
string comment=OrderComment();
int ticket=OrderTicket();
if(StringFind(comment,text,0)!=-1)
{
ClosedNumber++;
text=DoubleToStr(ticket,0);
}
if(ClosedNumber>2)
return(ClosedNumber);
}
return(ClosedNumber);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseOrders(int type=-1)
{
bool close;
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(OrderType()==OP_BUY)
{
close=OrderClose(OrderTicket(),OrderLots(),Bid,3*P );
}
else
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),Ask,3*P );
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MA(int shift,ENUM_TIMEFRAMES timeframe)
{
double ma=iMA(Symbol(),timeframe,MA_Period,0,MA_Method,MA _ApplyTo,shift);
return ma;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Stoch(int mode,int shift)
{
double stoch=iStochastic(Symbol(),0,Stoch_K,Stoch_D,Stoch _Slowing,Stoch_Method,Stoch_PriceField,mode,shift) ;
return stoch;
}
















enum ichimoku_mode
{
SENKOUSPANA=3,
SENKOUSPANB=4
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Ichimoku(int mode,int shift)
{
double ichimoku=iIchimoku(Symbol(),Ichimoku_TimeFrame,Ten kan_Sen,Kijun_Sen,Senkou_Span_B,mode,shift);
return ichimoku;
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MACD(int mode,int shift)
{
double macd=iMACD(Symbol(),0,Fast_EMA,Slow_EMA,MACD_SMA,M acd_ApplyTo,mode,shift);
return macd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AvTP(int type)
{
double Price=0;
double lots=0;
for(int i=0; i<OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
Price+=OrderOpenPrice()*OrderLots();
lots+=OrderLots();
}
}








if(lots!=0)
return(Price/lots);
else
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TotalProfit(int type=-1)
{
double profit=0;
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))
{
profit+=OrderProfit();
}
}
return(profit);
}








//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0 && NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*poin t,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blu e);
}
}
}
else
{
if(TrailingStop>0 && NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits))) || (OrderStopLoss()==0))
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits),Ord erTakeProfit(),0,Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
bool modify;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()<OrderOpenPrice()+BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+BreakEvenPips*poi nt,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-BreakEvenPips*point)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Re d);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LotManage(double risk)
{
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 ModifyOrders(int type)
{
bool action;
for(int i=0; i<=OrdersTotal(); i++)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
double take=OrderTakeProfit();
int ticket=OrderTicket();
int ordertype=OrderType();








if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==MagicNumber)
{








if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)+Av_TP*point,Digits) && ordertype==OP_BUY)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)+Av_TP*point,0);








if(NormalizeDouble(take,Digits)!=NormalizeDouble(A vTP(type)-Av_TP*point,Digits) && ordertype==OP_SELL)
action=OrderModify(ticket,OrderOpenPrice(),OrderSt opLoss(),AvTP(type)-Av_TP*point,0);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
















//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void AlertOptions(string text)
{
if(EnableAlert)
Alert(text);
if(EnableEmailNotification)
SendMail(text,text);
if(EnablePushNotification)
SendNotification(text);
}


تسلم ايديك حبيبنا

kira-h
21-04-2021, 06:04 PM
العفو وبالتوفيق إن شاء الله