2 مرفق
مساعدة في تصحيح اكسبيرت موشرات EMA و CCI
السلام عليكم ورحمة الله
اخواني اعضاء المنتدى قد قمت بدمج اكسبرتين 2 في واحد و الهدف منه هو العمل بالتوافق مع مؤشرين EMA واحد مع مؤشرين (2) CCI
EMA = 34
ِِCCI1 period 25
CCI2 period 50
يكون Buy حين تنغلق شمع فوق خط EMA + صعود قيمة المؤشرين CC1 و CC2 اعلى من 0 كما هو موضح اسفله
كما يكون SELL حين تنغلق شمع تحت خط EMA + نزول قيمة المؤشرين CC1 و CC2 اسفل من 0 كما هو موضح لاحقا
كتبت هذا الكود ولم استطع افضل من ذلك
كود PHP:
#property copyright "MR.dollar "
#property link "[email protected]"
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 int Entry_Candle=1;
input string info1="Money Management";
input double Lots = 1;
input bool MoneyManagement=false;
input double Risk=10;
input string info2="CCI1 Settings";
input int CCI1period=14;
input ENUM_APPLIED_PRICE ApplyTo=PRICE_CLOSE;
input double OverSold=-100;
input double OverBought=100;
input string info3="CCI2 Settings";
input int CCI2period=14;
input ENUM_APPLIED_PRICE ApplyTo2=PRICE_CLOSE;
input double OverSold2=-100;
input double OverBought2=100;
input string info4="Fast MA Settings";
input int MAPeriod=100;
input ENUM_MA_METHOD MAType=MODE_SMA;
input int MAShift=0;
input ENUM_APPLIED_PRICE MAapplyTo=PRICE_CLOSE;
input int TakeProfit=0;
input int StopLoss=0;
input int TrailingStop=0;
input int BreakEven=0;
input int BreakEvenPips=1;
input int MagicNumber=55555;
datetime Timee;
double point;
int P;
int Lot_Digits;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
if(MarketInfo(Symbol(),MODE_MINLOT)<0.1)Lot_Digits=2;
else Lot_Digits=1;
if(_Digits==5 || _Digits==3)P=10;
else P=1;
if(_Digits<4)
{
point=0.01;
}
else
{
point=0.0001;
}
CreatePanel("Panel_Info_Info1",OBJ_EDIT,"www.ArabicTrader.com",10,25,190,20,DodgerBlue,White,DodgerBlue,11,true,false,0,ALIGN_CENTER);
return(INIT_SUCCEEDED);
}
double MA(int shift)
{
double ma=iMA(Symbol(),0,MAPeriod,MAShift,MAType,MAapplyTo,shift);
return(ma);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"Panel_Info_Info1");
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS deinitialization function |
//+------------------------------------------------------------------+
int TotalOrders(int type)
{
int cnt=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==type)
{
cnt++;
}
}
}
return(cnt);
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS Start function |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double CCI(int shift)
{
double cc=iCCI(Symbol(),0,CCI1period,ApplyTo,shift);
return(cc);
double cc2=iCCI(Symbol(),0,CCI2period,ApplyTo2,shift);
return(cc2);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick(void)
{
if(TrailingStop>0)MoveTrailingStop();
if(BreakEven>0)MoveBreakEven();
if(EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==false)return;
double NewLots;
if(MoneyManagement) NewLots=LotManage();
else NewLots=Lots;
double SL,TP;
if(Close[1]>MA(1) && Close[2]<=MA(2) && Timee!=Time[0])
if(CCI(1+Entry_Candle)>OverSold && CCI(0+Entry_Candle)<=OverSold && Timee!=Time[0])
if(CCI(1+Entry_Candle)>OverSold2 && CCI(0+Entry_Candle)<=OverSold2 && Timee!=Time[0])
{
if(CloseInReverse)
CloseOrders(OP_SELL);
if(TotalOrders(OP_BUY)<MaxTrades || MaxTrades==0)
{
if(StopLoss==0){SL=0;}else{SL=Ask-StopLoss*point;}
if(TakeProfit==0){TP=0;}else{TP=Ask+TakeProfit*point;}
int ticket=OrderSend(Symbol(),OP_BUY,NewLots,NormalizeDouble(Ask,Digits),3*P,SL,TP,"EA",MagicNumber,0,Blue);
PlaySound("Alert.wav");
Timee=Time[0];
}
}
if(Close[1]<MA(1) && Close[2]>=MA(2) && Timee!=Time[0])
if(CCI(1+Entry_Candle)<OverBought && CCI(0+Entry_Candle)>=OverBought && Timee!=Time[0])
if(CCI(1+Entry_Candle)<OverBought2 && CCI(0+Entry_Candle)>=OverBought2 && Timee!=Time[0])
{
if(CloseInReverse)
CloseOrders(OP_BUY);
if(TotalOrders(OP_SELL)<MaxTrades || MaxTrades==0)
{
if(StopLoss==0){SL=0;}else{SL=Bid+StopLoss*point;}
if(TakeProfit==0){TP=0;}else{TP=Bid-TakeProfit*point;}
ticket=OrderSend(Symbol(),OP_SELL,NewLots,NormalizeDouble(Bid,Digits),3*P,SL,TP,"EA",MagicNumber,0,Red);
PlaySound("Alert.wav");
Timee=Time[0];
}
}
}
//+------------------------------------------------------------------+
void CloseOrders(int type)
{
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==type)
{
if(OrderType()==OP_BUY)
{
bool close=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,_Digits),3*P);
}
if(OrderType()==OP_SELL)
{
close=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,_Digits),3*P);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits)) || (OrderStopLoss()==0))
{
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
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),OrderTakeProfit(),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(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
{
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+BreakEvenPips*point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
{
modify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-BreakEvenPips*point,Digits),OrderTakeProfit(),0,Red);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,Lot_Digits));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreatePanel(string name,ENUM_OBJECT Type,string text,int XDistance,int YDistance,int Width,int Hight,
color BGColor_,color InfoColor,color boarderColor,int fontsize,bool readonly=false,bool Obj_Selectable=false,int Corner=0,ENUM_ALIGN_MODE Align=ALIGN_LEFT)
{
if(ObjectFind(0,name)==-1)
{
ObjectCreate(0,name,Type,0,0,0);
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,XDistance);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,YDistance);
ObjectSetInteger(0,name,OBJPROP_XSIZE,Width);
ObjectSetInteger(0,name,OBJPROP_YSIZE,Hight);
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetString(0,name,OBJPROP_FONT,"Arial Bold");
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
ObjectSetInteger(0,name,OBJPROP_CORNER,Corner);
ObjectSetInteger(0,name,OBJPROP_COLOR,InfoColor);
ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,boarderColor);
ObjectSetInteger(0,name,OBJPROP_BGCOLOR,BGColor_);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,Obj_Selectable);
if(Type==OBJ_EDIT)
{
ObjectSetInteger(0,name,OBJPROP_ALIGN,Align);
ObjectSetInteger(0,name,OBJPROP_READONLY,readonly);
}
}
if(ObjectDescription(name)!=text && readonly==true)
{
ObjectSetString(0,name,OBJPROP_TEXT,text);
}
}
//+---------------------------------------------------------------------------------+