Voila ! Avec un peu de retard :
Code
//+------------------------------------------------------------------+
//| aRka3579 |
//+------------------------------------------------------------------+
#property copyright "13 JANV 2021"
#property version "1.00"
string NAME = "My EA - % eLitePRO DOUBLE_Bk";
enum ENUM_HOUR
{
h00=00, //00:00
h01=01, //01:00
h02=02, //02:00
h03=03, //03:00
h04=04, //04:00
h05=05, //05:00
h06=06, //06:00
h07=07, //07:00
h08=08, //08:00
h09=09, //08:00
h10=10, //10:00
h11=11, //11:00
h12=12, //12:00
h13=13, //13:00
h14=14, //14:00
h15=15, //15:00
h16=16, //16:00
h17=17, //17:00
h18=18, //18:00
h19=19, //19:00
h20=20, //20:00
h21=21, //21:00
h22=22, //22:00
h23=23, //23:00
};
//--- Inputs
extern bool POWER_ON = true;
extern string ___ = "||||||||||||||||||";
input int Magic = 1;
extern int ATR_Period = 24;
extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||";
input double Lots = 25;
extern double Martingale_X = 3.0;
extern string _ = "";
extern string __1 = "|||||||||| SETTINGS ||||||||||";
extern string __2 = "";
extern bool TakeProfit_ON = true;
extern double TP_ATR = 7.77 ;
extern bool StopLoss_ON = true;
extern double SL_ATR = 6.66;
extern bool TrailingStep_ON = true;
extern double TS_ATR = 2.7;
extern string __3 = "";
extern string __4 = "|||||||||| BOLLINGER-B & M.A. ||||||||||";
extern string MA_info = "0 = sma, 1 = ema, 2 = smma, 3 = lwma";
extern string ____ = "";
input int BB_period = 120;
input double BB_deviation = 1.11;
extern string __5 = "";
extern string HL = "|||||||||| HIGH - LOW Settings ||||||||||";
extern int NbreBar = 3;
extern int NbreBar2 = 9;
extern string __15 = "||||||||||||||||||||||| TERMINAL Comments ||||||||||||||||||||||||||||||";
input string Buy_Com = __FILE__;
input string Sell_Com = __FILE__;
extern string __16 = "";
extern string __17 = "|||||||||| DAY Settings ||||||||||";
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 __18 = "";
extern string TIME_setting = "|||||||||| TIME Settings ||||||||||";
extern bool UseTimer = false; // Use start & end times in Hours
input ENUM_HOUR StartHour = h06; // Start operation hour
input ENUM_HOUR EndHour = h22; // Last operation hour
extern string __19 = "";
extern string INFO = "||||||||||||||||||||||| 0.01 MicroLot pour 250€ de capital ||||||||||||||||||||||||||||||";
//+------------------------------------------------------------------+
bool EAon(){
bool eaon = false;
if(POWER_ON) eaon = true;
return(eaon);}
double slb,tpb,sls,tps,pt;
int last_bar = 0;
double last_profit, last_lot;
int last_tip;
static int ATR_TF;
datetime CurrentTime;
double pips2dbl, pips2point, pipValue, profit, profitnow;
bool clear;
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);}
bool Trail(){
bool trailing = false;
if(DayOfWeek() == 5 && TrailingStep_ON) trailing = true;
return(trailing);}
bool TakeP(){
bool takeP = false;
if(DayOfWeek() == 5 && TakeProfit_ON) takeP = true;
return(takeP);}
bool StopL(){
bool stopL = false;
if(DayOfWeek() == 5 && StopLoss_ON) stopL = true;
return(stopL);}
//+------------------------------------------------------------------+
//| My TrailingStop |
//+------------------------------------------------------------------+
void Trailingstop()
{
for(int i=OrdersTotal()-1; i>=0;i--)
{
if (Trail() )
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==Magic)
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR)
if(OrderStopLoss()<Bid-iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR)
int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR,OrderTakeProfit(),0,clrNONE);
}
else if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()-Ask>-iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR)
if(OrderStopLoss()>Ask+iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR)
int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+iATR(NULL,PERIOD_CURRENT,17,0)*TS_ATR,OrderTakeProfit(),0,clrNONE);
}
}
}
//+------------------------------------------------------------------+
//| 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);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
//+------------------------------------------------------------------+
// Martingale (double Martingale)
//+------------------------------------------------------------------+
double Lot = (AccountEquity() * 0.001 /Lots);
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot = (AccountEquity() * 0.001 /Lots);
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot = Martingale_X*last_lot;
if( last_profit > 0 ) Lot = (AccountEquity() * 0.001 /Lots);
//+--------
string ls_01 = " Levier: " + AccountLeverage()
+ "\n"
+ "\n"
+ " Heure du Server: " + TimeToStr(TimeCurrent(), TIME_SECONDS)
+ "\n"
+ " Heure Locale: " + TimeToStr(TimeLocal(), TIME_SECONDS)
+ "\n";
string ls_02 = "-------------------------------------\n"+"\n";
int Spread;
Spread=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD);
//--- Output values in three lines
string ls_03 = (StringFormat(" Spread = %d", Spread));
string ls_04 = "\n"
+ "\n";
string ls_05 = "-------------------------------------\n";
string profitstr = DoubleToStr(profitnow,2);
string ls_06 = "\n"
+ "\n";
string ls_07 = " Solde : " + AccountBalance()
+ "\n";
string ls_08 = " Equity : " + AccountEquity()
+ "\n";
string ls_09 = " Profits : " + AccountProfit()
+ "\n";
Comment( ls_01 + ls_02 + ls_03 + ls_04 + ls_05 + ls_06 + ls_07 + ls_08 + ls_09 );
int res;
// Trading hours
if(UseTimer == true)
{
CurrentTime = TimeLocal();
int GetWeekday = TimeDayOfWeek(CurrentTime);
int GetHour = TimeHour(CurrentTime);
int GetMinute = TimeMinute(CurrentTime);
if(GetHour >= StartHour && GetHour <= EndHour && GetWeekday <6)
{
bool TradeAllowed = true;
}
else TradeAllowed = false;
}
else TradeAllowed = true;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
if(SL_ATR==0)slb=0;else slb=Close[0]-iATR(NULL,PERIOD_CURRENT,17,0)*SL_ATR;
if(SL_ATR==0)sls=0;else sls=Close[0]+iATR(NULL,PERIOD_CURRENT,17,0)*SL_ATR;
if(TP_ATR==0)tpb=0;else tpb=Close[0]+iATR(NULL,PERIOD_CURRENT,17,0)*TP_ATR;
if(TP_ATR==0)tps=0;else tps=Close[0]-iATR(NULL,PERIOD_CURRENT,17,0)*TP_ATR;
//--- get Moving Average
//--- SELL conditions
if(iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,1)<iBands(NULL,PERIOD_CURRENT,BB_period,BB_deviation,0,PRICE_OPEN,MODE_LOWER,1))
if(Ask<Low[NbreBar]&& TradeAllowed == true)
if(Ask<Low[NbreBar2])
if (DaytoTrade() )
if (EAon() )
{
res=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,sls,tps,Sell_Com,Magic,0,Red);
return;
}
//--- BUY conditions
if(iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,1)>iBands(NULL,PERIOD_CURRENT,BB_period,BB_deviation,0,PRICE_OPEN,MODE_UPPER,1))
if(Bid>High[NbreBar]&& TradeAllowed == true)
if(Bid>High[NbreBar2])
if (DaytoTrade() )
if (EAon() )
{
res=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,slb,tpb,Buy_Com,Magic,0,Blue);
return;
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else Trailingstop();
}
//+------------------------------------------------------------------+
//| init
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
int start()
{
return(0);
}
//+------------------------------------------------------------------+
//| ATR |
//+------------------------------------------------------------------+
double ATR(string SYMBOL)
{
double ATR = iATR(SYMBOL,ATR_TF,ATR_Period,1);
return(ATR);
}
//+------------------------------------------------------------------+
// 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);
}