//+------------------------------------------------------------------+ //| | //| Copyright © 2008 Marcelo Marques, programmed by www.aptrafx.com | //| http://www.aptrafx.com | //+------------------------------------------------------------------+ // m5 chart #property copyright "Copyright © 2008 Marcelo Marques, programmed by www.aptrafx.com" #property link "www.aptrafx.com" #define DgOneMinute 60 #define DgOneHour 3600 #define DgOneDay 86400 string HorarioAgora; int lock,ApenasSegunda,myBars,Total,i,Tipo; double macdmH1,macdsH1,macdmM15,macdsM15,ema1_13,ema1_131,ema2_13,ema2_131,ema132,macdm,macds,ema13,ema131,sma50,ema_clientalterarabarra,ema50,ema100,macd,macd3,lots,DgGMTTime,Mn,Mx,sl,tp; int OrdemBS=3; int Ftime=1; bool AllowDemoAccount = true; bool JustoneDemoAccount = false; int AutAcc = 2055068; string Dta = "2008.10.20"; //final string DtaInicial = "2008.08.01"; //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- Settings //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- extern double Lot5Value_1 = 0.1; int Lot5StopLoss_1 = 0; extern int Lot5TakeProfit_1 = 25; extern bool TrailingStopEnable_1 = false; extern int Lot5TrailingStopPips_1 = 15; int PipsValueSL = 2; //extern int Ema_Bar = 1;// where "0" is the current candle int EMAPeriod1 = 5; int EMAPeriod2 = 10; extern bool IsIBFXMiniAccount = false; // If you Use InterbankFX Broker ( MiniAccount ) extern int MagicNumber = 112211; // Magic Number - A dif. number for each Pair extern string EAName = "ElijahExp1"; // Name to show into comments Orders //--------- //--------- //-----Nao Estao Usando ---- //--------- //--------- //--------- //--------- //--------- string UseLot2_Settings="---------------------------------------------------------------------"; bool UseLot2 = false; double Lot5Value_2 = 0.2; int Lot5TakeProfit_2 = 100; // bool TrailingStopEnable_2 = true; int Lot5TrailingStopPips_2 = 15; int TrailingStep = 1; //extern bool SendEmail = true; double PercentRisk = 0 ; // If 0 lots size will be same of Lots Variable bool UseTimePeriod = false; string StartHour1 = "00:00"; string StopHour1 = "23:59"; //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- Final Settings //--------- //--------- //--------- //--------- //--------- //--------- //--------- //--------- bool debug =true; string TodosPares[20]={"GBPUSD","EURUSD","USDJPY","USDCHF","EURCHF","AUDUSD","USDCAD","NZDUSD","EURCAD","EURJPY","GBPJPY","CHFJPY","GBPCHF","AUDNZD","EURGBP","AUDCAD","AUDJPY","NZDJPY","EURAUD"}; string TodosParesm[20]={"GBPUSDm","EURUSDm","USDJPYm","USDCHFm","EURCHFm","AUDUSDm","USDCADm","NZDUSDm","EURCADm","EURJPYm","GBPJPYm","CHFJPYm","GBPCHFm","AUDNZDm","EURGBPm","AUDCADm","AUDJPYm","NZDJPYm","EURAUDm"}; //+------------------------------------------------------------------+ //| expert initialization function | //+----------------------------------------------- -------------------+ int init() { if (IsIBFXMiniAccount==true)ArrayCopy(TodosPares,TodosParesm,0,0,WHOLE_ARRAY ); return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit(){ return(0);} //+------------------------------------------------------------------+ //| expert start function //+------------------------------------------------------------------+ int start(){ if (CheckV()) return(0); if (debug==true)comentarios(); if(isNewBar()){ HorarioAgora=TimeToStr(TimeCurrent(),TIME_MINUTES); if (( HorarioAgora>StartHour1 && HorarioAgora<StopHour1) || (!UseTimePeriod) ) CheckEntry(); } if (TrailingStopEnable_1 && OrdensEmAndamento(001,MagicNumber,2)==1 ) TrailingStopCheck_Parameters(EAName,Lot5TrailingStopPips_1,Lot5StopLoss_1+PipsValueSL); return(0); } //----------- Inicio das VOIDS -------------------------------------------------------------------------------------- void CheckExit(int bs){ } void CheckEntry(){ double sll,tpp; ema1_13 = NormalizeDouble(iMA(NULL, 15,EMAPeriod1, 0,MODE_SMA,PRICE_CLOSE,1),Digits); ema1_131 = NormalizeDouble(iMA(NULL, 15,EMAPeriod2, 0,MODE_SMA,PRICE_CLOSE,2 ),Digits); //ema2_13 = NormalizeDouble(iMA(NULL, 5,EMAPeriod1, 0,MODE_SMA,PRICE_CLOSE,2),Digits); //ema2_131 = NormalizeDouble(iMA(NULL, 5,EMAPeriod2, 0,MODE_SMA,PRICE_CLOSE,3 ),Digits); //ema132 = NormalizeDouble(iMA(NULL, 0,13, 0,MODE_EMA,PRICE_CLOSE,2 ),Digits); //sma50 = NormalizeDouble(iMA(NULL, 0,50, 0,MODE_SMA,PRICE_CLOSE,0 ),Digits); macdmH1 = iMACD(NULL,60,12,26,9,PRICE_CLOSE,MODE_MAIN,1); macdsH1 = iMACD(NULL,60,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //linha tracejada macdmM15 = iMACD(NULL,240,12,26,9,PRICE_CLOSE,MODE_MAIN,1); macdsM15 = iMACD(NULL,240,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //linha tracejada if ( macdmH1>macdsH1 && macdmM15>macdsM15 && ema1_13>ema1_131 /*&& ema2_13<ema2_131 &&(OrdemBS==1 || OrdemBS==3)*/ ){ if (Ftime==1){OrdemBS=0;Ftime=0;return;} if (OrdensEmAndamento(001,MagicNumber,2)==0) SendOrder(0); if (OrdensEmAndamento(001,MagicNumber,1)==1) closeall(1); } if ( macdmH1<macdsH1 && macdmM15<macdsM15 && ema1_13<ema1_131 /*&& ema2_13>ema2_131 /*&& (OrdemBS==0 || OrdemBS==3) */ ){ if (Ftime==1){OrdemBS=1;Ftime=0;return;} if (OrdensEmAndamento(001,MagicNumber,2)==0) SendOrder(1); if (OrdensEmAndamento(001,MagicNumber,0)==1) closeall(0); } }//void bool CheckMacd(int bs){ int menor,maior; double macdm1,macds1; if(bs==0){ for (i=0;i<20;i++) { //macdm = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i); macdm = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i); macds = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i); //linha tracejada macdm1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1); macds1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i+1); //linha tracejada if (macdm>macds && macdm1<macds1)return(true); } } if(bs==1){ for (i=0;i<5;i++) { //macdm = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i); macdm = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i); macds = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i); //linha tracejada macdm1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1); macds1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i+1); //linha tracejada if (macdm<macds && macdm1>macds1)return(true); } } return(false); } void SendOrder(int bs) { double lt,texto,price,t; int erro; if (PercentRisk!=0)lt=GetLots(Lot5StopLoss_1+PipsValueSL);else lt=Lot5Value_1; if (bs==0){ int count=0; int Ticket=-99; if (Lot5StopLoss_1==0) sl=0;else sl=Ask-(Lot5StopLoss_1*Point); if (Lot5TakeProfit_1==0)tp=0;else tp=Ask+(Lot5TakeProfit_1*Point); //Initial stop set at five-bar low from entry. //o target sera 2 x o nosso risco = stoploss em pips x 2 while(Ticket<0) { RefreshRates(); Ticket=OrderSend(Symbol(),OP_BUY,lt,Ask,5,sl,tp,EAName,MagicNumber,0,Blue); if(Ticket<0){ Print("erro buy = ",erro," sl= ",sl," tp = ",tp," lt = ",lt," texto = ",texto," ask = ",Ask," GetLastError = ",GetLastError()); count++; } OrdemBS=0; while (IsTradeContextBusy()) Sleep(250); if (count>10)return(0); }//while } if (bs==1) { Ticket=-1; count=0; if (Lot5StopLoss_1==0) sl=0;else sl=Bid+(Lot5StopLoss_1*Point); if (Lot5TakeProfit_1==0)tp=0;else tp=Bid-(Lot5TakeProfit_1*Point); while(Ticket<0) { RefreshRates(); Ticket=OrderSend(Symbol(),OP_SELL,lt,Bid,5,sl,tp,EAName,MagicNumber,0,Red); if(Ticket<0){ Print("erro buy = ",erro," sl= ",sl," tp = ",tp," lt = ",lt," texto = ",texto," ask = ",Ask," GetLastError = ",GetLastError()); count++; } while (IsTradeContextBusy()) Sleep(250); OrdemBS=1; if (count>10)return(0); } } }//void void comentarios() { Comment ("----Trabalhando... ","\n", "ema1_13 = ",ema1_13,"\n", "ema1_131 = ",ema1_131,"\n", "macdmH1 = ",macdmH1,"\n", "macdsH1 = ",macdsH1,"\n", "macdmM15 = ",macdmM15,"\n", "macdsM15 = ",macdsM15,"\n", "HorarioAgora = ",HorarioAgora,"\n", "control = ",i,"\n"); } //int tipo 0=buy 1=sell 2=qualqueruma int OrdensEmAndamento(int Magic,int Magic2,int tipo) { ApenasSegunda=0; //OP_BUY==0 OP_SELL==1 Tipo=111; int Estado=0; Total = OrdersTotal(); for (i=0;i<Total;i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); //aqui Tipo so ta retornando certo pq esse Ea nao aceita ordens inversas abertas,logo so tera sell ou buy. Se fosse um Ea q aceitava tem de mudar isso pq da primeira passada ele pode achar o sell mas na 2 pode achar um buy e retornar o buy por final if (tipo==0 || tipo==1) if (OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic ||OrderMagicNumber()==Magic2) && tipo==OrderType()){ Estado=1; Tipo=OrderType(); break; } if (tipo==2) if (OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic ||OrderMagicNumber()==Magic2)) { Estado=1; Tipo=OrderType(); if (OrderComment()=="1st")ApenasSegunda++; break; } } return(Estado); } void TrailingStopCheck_Parameters(string comentario,int tsp,int Lot5sl) { for (int i = 0; i < OrdersTotal(); i ++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol() == Symbol() && OrderMagicNumber()==MagicNumber && OrderComment()==comentario) { if(OrderType() == OP_BUY) { if(tsp > 0) { if(Bid >= Point * (tsp+Lot5sl+TrailingStep)+OrderStopLoss()) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * Lot5sl, OrderTakeProfit(), 0, MediumSeaGreen); continue; } } } if(OrderType() == OP_SELL) { if(tsp > 0) { if(Ask <=OrderStopLoss()-Point * (tsp+Lot5sl+TrailingStep)) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * Lot5sl, OrderTakeProfit(), 0, DarkOrange); continue; } } } } } } double GetLots(double StopLoss) { double lotsl; double TamLote=(AccountEquity()*PercentRisk)/100; double RiskPerAverage=TamLote/(StopLoss); //2,0 if ((MarketInfo(Symbol(),MODE_LOTSIZE))==100000) lotsl=(RiskPerAverage*0.10);//0,2 if ((MarketInfo(Symbol(),MODE_LOTSIZE))==10000) lotsl=(RiskPerAverage*1.00);//0,2 return(lotsl); } int closeall(int bs) { int Ticket,Total; int count=0; int OK=0; Total = OrdersTotal(); if (OrdersTotal()!=0) while (OK!=1) { for( i=Total-1;i>=0;i--) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); Ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,Yellow); if (Ticket==true)OK=1;else while (IsTradeContextBusy()) Sleep(250); } count++; if (count>10){OK=1;Print("OrderClose Failure Tic = ",OrderTicket());} } } bool isNewBar() { bool res=false; if (myBars!=Bars) { myBars=Bars; res=true; } return(res); } bool CheckV(){ datetime TodayT=CurTime(); datetime Venc=StrToTime(Dta); datetime Venc2=StrToTime(DtaInicial); if (TodayT>=Venc ||TodayT<=Venc2 ){ Comment(" Just the FULL Version you can test all EA. Please check just the functionality of same, after conclude the Logic, we`ll send you the FULL EA"); ObjectsDeleteAll(); return(True); } if ( (!AllowDemoAccount) && (IsDemo()) && (JustoneDemoAccount==false) ){ Comment("F1"); return(True);} if ( (!IsDemo()) && (AccountNumber()!=AutAcc)) { Comment("F2"); return(True);} if ( (IsDemo()) && (AccountNumber()!=AutAcc) && (JustoneDemoAccount==true) ) { Comment("F3"); return(True);} //Comment("T"); return(False); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Moving average indicator
MACD Histogram
Custom Indicators Used:
Order Management characteristics:
It automatically opens orders when conditions are reached
Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It Closes Orders by itself
Other Features: