Membre très actif
139 messages
- Inscrit le :
- 14 Jun 2020
- Genre :
- m
- Trading :
- Réel
Voici la version Final en ce 31 décembre 2021.
Les nouveautés sont principalement :
* Trading Horaire fonctionnel.
* Trading au jour le jour fonctionnel.
* Système martingale par coef si clôture déficit.
* Take Profit par Basket au %age du capital.
* Fermeture par ATR en fonction de la volatilité donc.
* Ouverture par LotFixe ajustable.
* Stop Loss et Trailing stop, avec fonction ON/OFF.
* Commentaire du Terminal personnalisable.
* Informations diverses quand E.A. Enclenché (en haut sur la Gauche)
* Ouverture en L'état avec : MOVING AVERAGE + R.S.I. + KUMO BreakOut.
Code
//+------------------------------------------------------------------+
//| aRka3579 |
//+------------------------------------------------------------------+
#property copyright "31 DEC 2021"
#property version "7.00"
string NAME = "My EA - MicLot";
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
input int Magic = 1;
extern int ATR_Period = 14;
extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||";
input double Lots = 0.01;
extern double Martingale_X = 1.7;
extern string _ = "";
extern string BP = "|||||||||| BASKET Profit_% ||||||||||";
extern bool UseProfitToClose = TRUE;
extern double ProfitToClose = 6.0;
extern bool AllSymbols = false;
extern bool PendingOrders = true;
extern string __1 = "|||||||||| SETTINGS ||||||||||";
extern string __2 = "";
extern bool StopLoss_ON = true;
extern double StopLoss_ATR = 2.0;
extern bool TrailingStep_ON = true;
extern double TrailingStep_ATR = 0.04;
extern string __3 = "";
extern string __4 = "|||||||||| MOVING AVERAGE ||||||||||";
extern string MA_info = "0 = sma, 1 = ema, 2 = smma, 3 = lwma";
input int MA_Filter = 120;
input int MA_Mode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
extern string __5 = "";
extern string __6 = "|||||||||| R.S.I. ||||||||||";
extern int RSI_Period = 14;
extern int RSI_Upper = 50;
extern int RSI_Lower = 50;
extern string __7 = "";
extern string __8 = "||||||||||||||||||||||| TERMINAL Comments ||||||||||||||||||||||||||||||";
input string Buy_Com = __FILE__;
input string Sell_Com = __FILE__;
extern string __9 = "";
extern string __10 = "|||||||||| 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 __11 = "";
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 __12 = "";
extern string INFO = "||||||||||||||||||||||| 0.1 MicroLot pour 4000€ de capital ||||||||||||||||||||||||||||||";
//+------------------------------------------------------------------+
int last_bar = 0;
double last_profit, last_lot;
int last_tip;
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 StopL(){
bool stopL = false;
if(DayOfWeek() == 5 && StopLoss_ON) stopL = true;
return(stopL);}
//+------------------------------------------------------------------+
//| My TrailingStop |
//+------------------------------------------------------------------+
void Trailingstop()
{
double SYMBOL;
double MyPoint = (ATR(SYMBOL) * TrailingStep_ATR) / MarketInfo(SYMBOL,MODE_POINT) ;
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()>MyPoint)
if(OrderStopLoss()<Bid-MyPoint)
int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(MyPoint),OrderTakeProfit(),0,clrNONE);
}
else if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()-Ask>MyPoint)
if(OrderStopLoss()>Ask+MyPoint)
int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(MyPoint),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 System +-------------
double Lot = Lots;
if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot = Lots;
else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit();
if( last_profit < 0 ) Lot = Martingale_X*last_lot;
if( last_profit > 0 ) Lot = 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;
//--- get Moving Average
double ssA=iIchimoku(NULL, 0,8,23,52, MODE_SENKOUSPANA,0);
double ssB=iIchimoku(NULL, 0,8,23,52, MODE_SENKOUSPANB,0);
//--- SELL conditions
if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1))
if(iRSI(NULL,PERIOD_CURRENT,RSI_Period,PRICE_CLOSE,0) < RSI_Lower && TradeAllowed == true)
if(Open[1]<ssA)
if(Open[1]<ssB)
if (DaytoTrade() )
{
res=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,0,Sell_Com,Magic,0,Red);
return;
}
//--- BUY conditions
if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1))
if(iRSI(NULL,PERIOD_CURRENT,RSI_Period,PRICE_CLOSE,0) > RSI_Upper && TradeAllowed == true)
if(Open[1]>ssA)
if(Open[1]>ssB)
if (DaytoTrade() )
{
res=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,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 SetStopLoss();
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else Trailingstop();
//--- 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);
}
//+------------------------------------------------------------------+
//| init
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
int start()
{
return(0);
}
//+------------------------------------------------------------------+
//| SL_Decision |
//+------------------------------------------------------------------+
int SL_Decision(string SYMBOL)
{
double SL = (ATR(SYMBOL) * StopLoss_ATR) / MarketInfo(SYMBOL,MODE_POINT) ;
int Stoploss = SL;
return(Stoploss);
}
//+------------------------------------------------------------------+
//| ATR |
//+------------------------------------------------------------------+
double ATR(string SYMBOL)
{
double ATR = iATR(SYMBOL,0,ATR_Period,1);
return(ATR);
}
//+------------------------------------------------------------------+
//| SetStopLoss |
//+------------------------------------------------------------------+
void SetStopLoss()
{
int i,Type; bool selected, success;
for(i=0; i<OrdersTotal(); i++)
{
if (StopL() )
selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT))
{
Type = OrderType();
success = false;
if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE);
if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE);
if (!success) Print("Error code = " + GetLastError());
}
}
} // end of SetStopLoss
//+------------------------------------------------------------------+
// 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);
}
Remerciements aux programmeurs.
Je n'ai pas inventé la musique mais vous me permettez de composé.
Bon réveillons de nouvelle année.
Je penserais a vous le 1er janvier 2022 !
Yohan. (aRka)
Modifié le 2021-12-31 14:32:02 par
arka3579