A testé ! sur du M30 et plus..
Tenez moi au courant.
Tenez moi au courant.
Code
//+------------------------------------------------------------------+
//| aRka3579 |
//+------------------------------------------------------------------+
//--- Inputs
input string IndicatorName="MyEA_Bk & Tk & WD";
extern bool EA_ON_Bk = true;
extern bool EA_ON_Tk = true;
extern bool EMA_200_Filter_ON = true;
input int Magic = 30;
extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||";
extern bool MICLOT_ON = true;
extern double MicLot = 0.01;
extern bool P_RISK_ON = true;
extern double Risk = 1;
extern double Martingale_X = 2;
extern string BP = "|||||||||| BASKET Profit ||||||||||";
extern bool UseProfitToClose = false;
extern double ProfitToClose = 2;
extern bool AllSymbols = false;
extern bool PendingOrders = false;
extern string BK = "|||||||||| Double BREAK OUT ||||||||||";
extern int BK_Turtle1 = 8;
extern int BK_Turtle2 = 20;
extern bool StrictEntry = true;
extern string Set1 = "|||||||||| M.A. Settings ||||||||||";
extern string MA_info = "0 = sma, 1 = ema, 2 = smma, 3 = lwma";
input int MA_Mode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
input int MA_Filter = 209;
extern string KUMO = "|||||||||| ICHIMOKU ||||||||||";
extern int TKS = 8;
extern int T = 8;
extern int K = 20;
extern int S = 52;
sinput ENUM_TIMEFRAMES TF_KIJUN_Open1 = PERIOD_M15;// Timeframe
sinput ENUM_TIMEFRAMES TF_KIJUN_Open2 = PERIOD_H1;// Timeframe
sinput ENUM_TIMEFRAMES TF_KIJUN_Exit = PERIOD_M15;// Timeframe
extern string TIME = "|||||||||| TIME & DAY TRADING ||||||||||";
extern int Start_Hour = 0;
extern int End_Hour = 24;
extern bool Monday = true;
extern bool Tuesday = true;
extern bool Wednesday = true;
extern bool Thursday = true;
extern bool Friday = true;
extern bool Sunday = false;
extern string TERM = "||||||||||||||||||||||| TERMINAL Comments ||||||||||||||||||||||||||||||";
input string Buy_Com_UT1 = __FILE__;
input string Sell_Com_UT1 = __FILE__;
input string Buy_Com_UT2 = __FILE__;
input string Sell_Com_UT2 = __FILE__;
//+------------------------------------------------------------------+
bool DaytoTrade(){
bool daytotrade = false;
if(DayOfWeek() == 0 && Sunday) daytotrade = true;
if(DayOfWeek() == 1 && Monday) daytotrade = true;
if(DayOfWeek() == 2 && Tuesday) daytotrade = true;
if(DayOfWeek() == 3 && Wednesday) daytotrade = true;
if(DayOfWeek() == 4 && Thursday) daytotrade = true;
if(DayOfWeek() == 5 && Friday) daytotrade = true;
return(daytotrade);}
int OrderOpRetry=5;
bool EAon1(){
bool eaon1 = false;
if(EA_ON_Bk) eaon1 = true;
return(eaon1);}
bool EAon2(){
bool eaon2 = false;
if(EA_ON_Tk) eaon2 = true;
return(eaon2);}
double slb,tpb,sls,tps,pt;
double last_profit, last_lot;
int last_tip;
bool clear;
double pips2dbl, pips2point, pipValue, profit, profitnow;
bool MICLot(){
bool micL = false;
if(MICLOT_ON) micL = true;
return(micL);}
bool PercentR(){
bool PersR = false;
if(P_RISK_ON) PersR = true;
return(PersR);}
bool Ema200Filter(){
bool Ema200F = false;
if(EMA_200_Filter_ON) Ema200F = true;
return(Ema200F);}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
double T_0=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_TENKANSEN, 0);
double T_1=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_TENKANSEN, 1);
double K_0=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_KIJUNSEN, 0);
double K_1=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_KIJUNSEN, 1);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if( T_1 > K_1 && T_0 <= K_0 )
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if( T_1 < K_1 && T_0 >= K_0 )
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//--- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
void CheckForOpen1()
{
// Martingale %R
double Lot1 = (AccountEquity()/100*Risk/100);
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot1 = (AccountEquity()/100*Risk/100);
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot1 = Martingale_X*last_lot;
if( last_profit > 0 ) Lot1 = (AccountEquity()/100*Risk/100);
// Martingale MicLot
double Lot2 = MicLot;
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot2 = MicLot;
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot2 = Martingale_X*last_lot;
if( last_profit > 0 ) Lot2 = MicLot;
int res2;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
double ssA = iIchimoku(NULL, 0,TKS,TKS,TKS, MODE_SENKOUSPANA,0);
double ssB = iIchimoku(NULL, 0,TKS,TKS,TKS, MODE_SENKOUSPANB,0);
double kij1=iIchimoku(NULL, TF_KIJUN_Open1,TKS,TKS,TKS, MODE_KIJUNSEN,0);
double kij2=iIchimoku(NULL, TF_KIJUN_Open2,TKS,TKS,TKS, MODE_KIJUNSEN,0);
double rhigh = iHigh(Symbol(),Period(),iHighest(Symbol(), PERIOD_CURRENT, MODE_HIGH, BK_Turtle1,1+1));
double rlow = iLow(Symbol(),Period(),iLowest(Symbol(), PERIOD_CURRENT, MODE_LOW, BK_Turtle1, 1+1));
double rhigh2 = iHigh(Symbol(),Period(),iHighest(Symbol(), PERIOD_CURRENT, MODE_HIGH, BK_Turtle2,1+1));
double rlow2 = iLow(Symbol(),Period(),iLowest(Symbol(), PERIOD_CURRENT, MODE_LOW, BK_Turtle2, 1+1));
double CLOSE = iClose(Symbol(),0, 1);
double HIGH = iHigh(Symbol(),0, 1);
double LOW = iLow(Symbol(),0, 1);
//--- SELL conditions
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) && (Ema200Filter()))
if(Open[1] < kij1)
if(Open[1] < kij2)
if (((CLOSE < rlow && 1 > 0) || (LOW < rlow)) && ((CLOSE < rlow2 && 1 > 0) || (LOW < rlow2)) && StrictEntry == true)
if (EAon1() )
if (Hour_trade()==1)
if (DaytoTrade() )
{
if (PercentR())
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res2=OrderSend(Symbol(),OP_SELL,Lot1,Bid,3,sls,tps,Sell_Com_UT2+"_%Open_Sell_Bk_"+Magic,Magic,0,Red);
if (MICLot())
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res2=OrderSend(Symbol(),OP_SELL,Lot2,Bid,3,sls,tps,Sell_Com_UT2+"_Open_Sell_Bk_"+Magic,Magic,0,Red);
}
//--- BUY conditions
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) && (Ema200Filter()))
if(Open[1] > kij1)
if(Open[1] > kij2)
if (((CLOSE > rhigh && 1 > 0) || (HIGH > rhigh)) && ((CLOSE > rhigh2 && 1 > 0) || (HIGH > rhigh2)) && StrictEntry == true)
if (EAon1() )
if (Hour_trade()==1)
if (DaytoTrade() )
{
if (PercentR())
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res2=OrderSend(Symbol(),OP_BUY,Lot1,Ask,3,sls,tps,Buy_Com_UT2+"_%Open_Buy_Bk_"+Magic,Magic,0,Blue);
if (MICLot())
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res2=OrderSend(Symbol(),OP_BUY,Lot2,Ask,3,sls,tps,Buy_Com_UT2+"_Open_Buy_Bk_"+Magic,Magic,0,Blue);
return;
}
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen2()
{
// Martingale %R
double Lot1 = (AccountEquity()/100*Risk/100);
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot1 = (AccountEquity()/100*Risk/100);
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot1 = Martingale_X*last_lot;
if( last_profit > 0 ) Lot1 = (AccountEquity()/100*Risk/100);
// Martingale MicLot
double Lot2 = MicLot;
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot2 = MicLot;
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot2 = Martingale_X*last_lot;
if( last_profit > 0 ) Lot2 = MicLot;
string ls_01 = " Levier: " + AccountLeverage()
+ "\n"
+ "\n"
+ " Heure du Server: " + TimeToStr(TimeCurrent(), TIME_SECONDS)
+ "\n";
string ls_02 = "-------------------------------------\n"+"\n";
string ls_07 = " Solde : " + AccountBalance()
+ "\n";
string ls_08 = " Equity : " + AccountEquity()
+ "\n";
string ls_09 = " Account Profits : " + AccountProfit()
+ "\n";
string ls_10 = " Symbol : " + Symbol() + " " + OrderProfit()
+ "\n";
Comment( ls_01 + ls_02 + ls_07 + ls_08 + ls_09 + ls_10 );
int res;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
double kij1=iIchimoku(NULL, TF_KIJUN_Open1,TKS,TKS,TKS, MODE_KIJUNSEN,0);
double kij2=iIchimoku(NULL, TF_KIJUN_Open2,TKS,TKS,TKS, MODE_KIJUNSEN,0);
double T_0=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_TENKANSEN, 0);
double T_1=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_TENKANSEN, 1);
double K_0=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_KIJUNSEN, 0);
double K_1=iIchimoku(NULL, PERIOD_CURRENT, T, K, S, MODE_KIJUNSEN, 1);
//--- SELL conditions
if(Open[1]<kij1)
if(Open[1]<kij2)
if( T_1 > K_1 && T_0 <= K_0 ) // Tenkan-sen crosses Kijun-sen downwards
if (EAon2() )
if (Hour_trade()==1)
if (DaytoTrade() )
{
if (PercentR())
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res=OrderSend(Symbol(),OP_SELL,Lot1,Bid,3,sls,tps,Sell_Com_UT1+"_%Open_Sell_Tk_"+OrderSymbol()+Magic,Magic,0,Red);
if (MICLot())
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res=OrderSend(Symbol(),OP_SELL,Lot2,Bid,3,sls,tps,Sell_Com_UT1+"_Open_Sell_Tk_"+OrderSymbol()+Magic,Magic,0,Red);
}
//--- BUY conditions
if(Open[1]>kij1)
if(Open[1]>kij2)
if( T_1 < K_1 && T_0 >= K_0 ) // Tenkan-sen crosses Kijun-sen upwards
if (EAon2() )
if (Hour_trade()==1)
if (DaytoTrade() )
{
if (PercentR())
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res=OrderSend(Symbol(),OP_BUY,Lot1,Ask,3,sls,tps,Buy_Com_UT1+"_%Open_Buy_Tk_"+OrderSymbol()+Magic,Magic,0,Blue);
if (MICLot())
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1) || (Ema200Filter()))
res=OrderSend(Symbol(),OP_BUY,Lot2,Ask,3,sls,tps,Buy_Com_UT1+"_Open_Buy_Tk_"+OrderSymbol()+Magic,Magic,0,Blue);
return;
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen1();
else CheckForClose();
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen2();
else CheckForClose();
//--- Basket Profit/Lost
profit = ProfitCheck();
if(UseProfitToClose)
{
if(profit>(AccountBalance() * ProfitToClose/100))
{
if(AllSymbols)
{
if(PendingOrders)
if(!CloseDeleteAll())
clear=false;
if(!PendingOrders)
if(!CloseDeleteAllNonPending())
clear=false;
}
if(!AllSymbols)
{
if(PendingOrders)
if(!CloseDeleteAllCurrent())
clear=false;
if(!PendingOrders)
if(!CloseDeleteAllCurrentNonPending())
clear=false;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CloseDeleteAll()
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUY :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue))
return(false);
}break;
case OP_SELL :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red))
return(false);
}break;
}
if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT)
if(!OrderDelete(OrderTicket()))
{
Print("Error deleting " + OrderType() + " order : ",GetLastError());
return (false);
}
}
}
return (true);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// delete all on current chart
bool CloseDeleteAllCurrent()
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
switch(OrderType())
{
case OP_BUY :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue))
return(false);
}break;
case OP_SELL :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red))
return(false);
}break;
}
if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT)
if(!OrderDelete(OrderTicket()))
{
return (false);
}
}
}
}
return (true);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// left pending orders
bool CloseDeleteAllNonPending()
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUY :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue))
return(false);
}break;
case OP_SELL :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red))
return(false);
}break;
}
}
}
return (true);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// delete all on current chart left pending
bool CloseDeleteAllCurrentNonPending()
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
switch(OrderType())
{
case OP_BUY :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue))
return(false);
}break;
case OP_SELL :
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red))
return(false);
}break;
}
}
}
}
return (true);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double ProfitCheck()
{
double profit=0;
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >=0 ; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(AllSymbols)
profit+=OrderProfit();
else if(OrderSymbol()==Symbol())
profit+=OrderProfit();
}
return(profit);
}
//+------------------------------------------------------------------+
// Martingale
//+------------------------------------------------------------------+
double last_history_profit()
{
double cpte_profit = 0; //int Magik_No = -1;
if( OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY) )
{
if( OrderMagicNumber() == Magic ) {
last_profit = OrderProfit();
last_lot = OrderLots();
last_tip = OrderType();
}
}
return(0);
}
//+------------------------------------------------------------------+
//| ATR |
//+------------------------------------------------------------------+
double ATR(string SYMBOL)
{
double ATR = iATR(SYMBOL,0,14,1);
return(ATR);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade=false;
if(Start_Hour>End_Hour)
{
if(Hour()>=Start_Hour || Hour()<End_Hour) trade=true;
}
else
if(Hour()>=Start_Hour && Hour()<End_Hour) trade=true;
return (trade);
}