Je vous joint un EA fini ou je dirait presque fini , car pour moi un EA fini cela n'existent pas car il doit être modifier pendant son cours de fonctionnement , celui-ci a de tout , MM ,martingale ect......enfin juste ce qu'il faut pour son fonctionnement qui est basé sur la taille de la bougie et pour un long terme . corriger si le code passe bien ou message privé et je vous le joint par mail.
il peut -être profitable si il est bien exploiter , j'y travail justement . POUR MT4
il peut -être profitable si il est bien exploiter , j'y travail justement . POUR MT4
Code
//+------------------------------------------------------------------+
//| TAILLE-BOUGIE-EA.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
extern int MagicNumber = 2009;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.01;
extern double IncLot=0.01;
extern int Step=200;
extern double MinProfit=1;
extern bool ProfitManuel = true;
extern double ProfitFactor=150;
extern string comment="heure de trading";
extern double TailleBougie = 15;
extern int Slippage = 3;
extern bool UseStopLoss = false;
extern int StopLoss = 20;
extern bool UseTakeProfit = false;
extern int TakeProfit = 20;
extern bool UseTrailingStop = false;
extern int TrailingStop = 30;
extern bool UseMoneyManagement = true; //Use Money Management or not
extern bool AccountIsMicro = true; //Use Micro-Account or not
extern double Risk = 10; //10%
extern double VMartingale = 1;
extern int StartTime = 14;
extern int EndTime = 16;
double gLotSell=0;
double gLotBuy=0;
double LSP,LBP;
int BarCount;
int Current;
double CurrentProfit;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
if(Digits == 3 || Digits == 5)
{
StopLoss *=10;
TakeProfit *=10;
TrailingStop *=10;
Slippage *= 10;
Step *= 10;
}
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
double LotSize()
{
double lotMM = MathCeil(AccountFreeMargin() * Risk / 10000) / 100;
if(AccountIsMicro==false) //normal account
{
if (lotMM < 0.1) lotMM = Lots;
if (lotMM > 1000) lotMM = 1000;
}
else //micro account
{
if (lotMM < 0.01) lotMM = Lots;
if (lotMM > 1000) lotMM = 1000;
}
return (lotMM);
}
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
if( ProfitManuel==false ) ProfitFactor = 500;
if(UseMoneyManagement==true && IncLot != 0) IncLot = LotSize();
if(UseMoneyManagement==true) MinProfit = Lots * ProfitFactor;
CurrentProfit=GetOrdersProfit(MagicNumber);
if (CurrentProfit>=MinProfit)
{
DeletePendingOrders(MagicNumber);
CloseOrders(MagicNumber);
}
//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+
double Buy1_1 = iMA(NULL, 0, 500, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, 500, 0, MODE_SMA, PRICE_CLOSE, Current + 1);
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
double OpenC = iOpen(NULL, 0, Current + 0);
double CloseC = iClose(NULL, 0, Current + 0);
double bull = - (TailleBougie / 10000);
double bear = TailleBougie / 10000;
double Dernier_Trade;
double Dernier_Lot;
double Dernier_Trade2;
double Dernier_Lot2;
double iLots;
double CurrentProfit;
bool martingale;
CurrentProfit=GetOrdersProfit(MagicNumber);
if (CurrentProfit>=MinProfit)
{
DeletePendingOrders(MagicNumber);
CloseOrders(MagicNumber);
}
for(int j = 1; j < OrdersHistoryTotal(); j++)
{
if (OrderSelect(OrdersHistoryTotal() - j, SELECT_BY_POS, MODE_HISTORY) == true )
{
Dernier_Trade = OrderProfit();
Dernier_Lot = OrderLots();
break;
}
}
for(int k = 2; k < OrdersHistoryTotal(); k++)
{
if (OrderSelect(OrdersHistoryTotal() - k, SELECT_BY_POS, MODE_HISTORY) == true )
{
Dernier_Trade2 = OrderProfit();
Dernier_Lot2 = OrderLots();
break;
}
}
if ( Dernier_Trade < 0 )
martingale = true;
if ( Dernier_Trade > 0 )
martingale = false;
if (martingale == true)
{
iLots = Dernier_Lot * VMartingale ;
}
if (martingale == false)
{
iLots = Lots ;
}
double lotMM = MathCeil (AccountFreeMargin() * Risk / 10000) / 100;
if(UseMoneyManagement==true) Lots = LotSize();
if (Buy1_1 > Buy1_2 && bull > (OpenC - CloseC) && TradeSession() == 1) Order = SIGNAL_BUY;
if (Buy1_1 < Buy1_2 && bear < (OpenC - CloseC) && TradeSession() == 1) Order = SIGNAL_SELL;
LSP=GetLastSellPrice(MagicNumber);
LBP=GetLastBuyPrice(MagicNumber);
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, iLots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, iLots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
if (!EachTickMode) BarCount = Bars;
if((LSP-Bid)<=5*Point)
{
OrderSend(Symbol(),OP_SELLLIMIT,gLotSell+IncLot,LSP+Step*Point,3,0,0,comment,MagicNumber,0,Red);
}
if((Ask-LBP)<=5*Point)
{
OrderSend(Symbol(),OP_BUYLIMIT,gLotBuy+IncLot,LBP-Step*Point,3,0,0,comment,MagicNumber,0,Red);
}
return(0);
}
int TradeSession() {
if (StartTime < EndTime && TimeHour(TimeCurrent()) < StartTime || TimeHour(TimeCurrent()) >= EndTime) return (0);
if (StartTime > EndTime && (TimeHour(TimeCurrent()) < StartTime && TimeHour(TimeCurrent()) >= EndTime)) return (0);
if (EndTime == 0) EndTime = 24;
if (Hour() == EndTime - 1 && Minute() >= 55) return (0);
return (1);
}
double GetLastBuyPrice(int MagicNumber)
{
int total=OrdersTotal()-1;
for (int cnt = total ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == MagicNumber && OrderSymbol()==Symbol() && (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUY))
{
gLotBuy=OrderLots();
return(OrderOpenPrice());
break;
}
}
return(0);
}
double GetLastSellPrice(int MagicNumber)
{
int total=OrdersTotal()-1;
for (int cnt = total ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == MagicNumber && OrderSymbol()==Symbol() && (OrderType()==OP_SELLLIMIT ||OrderType()==OP_SELL))
{
gLotSell=OrderLots();
return(OrderOpenPrice());
break;
}
}
return(100000);
}
double GetOrdersProfit(int Magic)
{
double gProfit=0;
int total=OrdersTotal()-1;
for (int cnt = total ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
{
gProfit=gProfit+OrderProfit();
}
}
return(gProfit);
}
int DeletePendingOrders(int Magic)
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >= 0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && OrderType()!=OP_BUY && OrderType()!=OP_SELL)
{
OrderDelete(OrderTicket());
}
}
return(0);
}
int CloseOrders(int Magic)
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >= 0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3);
}
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Modifié le 2017-05-06 11:48:37 par
AliX
: [code] [/code]