- Início
- Comunidade
- Programação
- London Breakout Optimisation1: Expert Advisors in Meta Quote...
Edit Your Comment
London Breakout Optimisation1: Expert Advisors in Meta Quote Language 5 (MQL5)
Membro Desde Jun 02, 2024
4 postagens
Jan 05 at 14:16
Membro Desde Jun 02, 2024
4 postagens
Bonjour et Bonsoir a tous, récemment j'avais écrit une article sur la stratégie London Breakout. Désormais j'essayerais de l'optimiser avec mes connaissances et compétences et je vous tiendrais au courent des améliorations faites a chaque fin de semaine.
Avant de vous montrez les améliorations, j'aimerais que vous répondiez au sondage suivant :
1. la stratégie London Breakout est-il rentable ou non ?
2. le code écrit est-il bon ou mauvais ?
J'attend vos réponses avec impatients.
CODE SOURCE :
//+------------------------------------------------------------------+
//| BreakoutLondon.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include
CTrade trade;
input group "Parametre de trading"
input double RiskInPercent = 0.5; // Risque Par Trade
datetime LondonOpen, LondonClose;
bool IsLondonOpen;
void OnTick(){
TrailingStop();
TimeStructure();
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
if(TimeCurrent() > LondonOpen && TimeCurrent() < LondonClose && !IsLondonOpen){
int AsianSessionHighest = iHighest(_Symbol,PERIOD_H1,MODE_HIGH,10,1);
int AsianSessionLowest = iLowest(_Symbol,PERIOD_H1,MODE_LOW,10,1);
double AsianSessionHigh = iHigh(_Symbol,PERIOD_H1,AsianSessionHighest);
double AsianSessionLow = iLow(_Symbol,PERIOD_H1,AsianSessionLowest);
string strAsianSessionHigh = DoubleToString(AsianSessionHigh,_Digits);
string strAsianSessionLow = DoubleToString(AsianSessionLow,_Digits);
ObjectCreate(ChartID(),"London Open",OBJ_VLINE,0,LondonOpen,0);
ObjectCreate(ChartID(),"Asian Open",OBJ_VLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,0);
ObjectCreate(ChartID(),"Asian High",OBJ_HLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,AsianSessionHigh);
ObjectCreate(ChartID(),"Asian Low",OBJ_HLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,AsianSessionLow);
if(ask < AsianSessionHigh && bid > AsianSessionLow && !IsTradeOpen()){
if((AsianSessionHigh-AsianSessionLow)*10000 >= 25 && (AsianSessionHigh-AsianSessionLow)*10000 <= 35){
Print("Nombre de Pips est: ", (AsianSessionHigh-AsianSessionLow)*10000);
Print(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow));
trade.BuyStop(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow),AsianSessionHigh,_Symbol,AsianSessionLow,0,ORDER_TIME_SPECIFIED,LondonClose,strAsianSessionLow);
trade.SellStop(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow),AsianSessionLow,_Symbol,AsianSessionHigh,0,ORDER_TIME_SPECIFIED,LondonClose,strAsianSessionHigh);
}
}
IsLondonOpen = true;
}
if(TimeCurrent() > LondonClose && IsLondonOpen){
IsLondonOpen = false;
}
if(IsTradeOpen()){
ClosingOrder();
}
}
//+------------------------------------------------------------------+
//| Ancienne fonction: ClosingOrder()
//+------------------------------------------------------------------+
//void ClosingOrder(){
//
//for(int i = OrdersTotal()-1; i>=0; i--){
//
//ulong OrderTicket = OrderGetTicket(i);
//if(OrderSelect(OrderTicket) && IsTradeOpen())
//trade.OrderDelete(OrderTicket);
//}
//}
//+------------------------------------------------------------------+
//| Optimisation du fonction: ClosingOrder()
//+------------------------------------------------------------------+
bool ClosingOrder(){
for(int i = OrdersTotal()-1; i>=0; i--){
ulong OrderTicket = OrderGetTicket(i);
if(OrderSelect(OrderTicket) && IsTradeOpen()){
trade.OrderDelete(OrderTicket);
return true;
}
}
return false;
}
bool IsTradeOpen(){
for(int i = PositionsTotal()-1; i>=0; i--){
if(PositionGetString(POSITION_SYMBOL) == _Symbol){
return true;
}
}
return false;
}
double PositionSizeCalculator(double StopLoseSize){
double TickSize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
double TickValue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
double VolumeStep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
double RiskInCurrency = AccountInfoDouble(ACCOUNT_BALANCE)*RiskInPercent/100;
double RiskVolumeStep = StopLoseSize/TickSize*VolumeStep*TickValue;
double PositionSize = MathFloor(RiskInCurrency/RiskVolumeStep)*VolumeStep;
return PositionSize;
}
void TimeStructure(){
int Offset_hours = 2;
MqlDateTime structLondonOpen;
TimeCurrent(structLondonOpen);
structLondonOpen.hour = 8 + Offset_hours;
structLondonOpen.min = 0;
structLondonOpen.sec = 0;
LondonOpen = StructToTime(structLondonOpen);
MqlDateTime structLondonClose;
TimeCurrent(structLondonClose);
structLondonClose.hour = 17 + Offset_hours;
structLondonClose.min = 0;
structLondonClose.sec = 0;
LondonClose = StructToTime(structLondonClose);
}
void TrailingStop(){
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
for(int i = PositionsTotal()-1; i>=0; i--){
ulong PositionTicket = PositionGetTicket(i);
if(PositionSelectByTicket(PositionTicket) && PositionGetInteger(POSITION_TYPE) == 0){
double PositionSL = PositionGetDouble(POSITION_SL);
double PositionTP = PositionGetDouble(POSITION_TP);
double PositionPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
string PositionComment = PositionGetString(POSITION_COMMENT);
double FirstPositionSL = StringToDouble(PositionComment);
double PipsInProfit = ask - PositionPriceOpen;
double TrailingSL = FirstPositionSL + PipsInProfit;
if(PipsInProfit > 0 && TrailingSL > PositionSL){
trade.PositionModify(PositionTicket,TrailingSL,PositionTP);
}
}
if(PositionSelectByTicket(PositionTicket) && PositionGetInteger(POSITION_TYPE) == 1){
double PositionSL = PositionGetDouble(POSITION_SL);
double PositionTP = PositionGetDouble(POSITION_TP);
double PositionPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
string PositionComment = PositionGetString(POSITION_COMMENT);
double FirstPositionSL = StringToDouble(PositionComment);
double PipsInProfit = PositionPriceOpen - bid;
double TrailingSL = FirstPositionSL - PipsInProfit;
if(PipsInProfit > 0 && TrailingSL < PositionSL){
trade.PositionModify(PositionTicket,TrailingSL,PositionTP);
}
}
}
}
Et voici le changement dans le graphique....(Cf. Fichiers Jointes)
Bon visionnage et voici le lien de la précèdent article sur cette strategie....https://www.myfxbook.com/community/programming/london-breakout-expert-advisors-meta/3200425,1
Avant de vous montrez les améliorations, j'aimerais que vous répondiez au sondage suivant :
1. la stratégie London Breakout est-il rentable ou non ?
2. le code écrit est-il bon ou mauvais ?
J'attend vos réponses avec impatients.
CODE SOURCE :
//+------------------------------------------------------------------+
//| BreakoutLondon.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include
CTrade trade;
input group "Parametre de trading"
input double RiskInPercent = 0.5; // Risque Par Trade
datetime LondonOpen, LondonClose;
bool IsLondonOpen;
void OnTick(){
TrailingStop();
TimeStructure();
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
if(TimeCurrent() > LondonOpen && TimeCurrent() < LondonClose && !IsLondonOpen){
int AsianSessionHighest = iHighest(_Symbol,PERIOD_H1,MODE_HIGH,10,1);
int AsianSessionLowest = iLowest(_Symbol,PERIOD_H1,MODE_LOW,10,1);
double AsianSessionHigh = iHigh(_Symbol,PERIOD_H1,AsianSessionHighest);
double AsianSessionLow = iLow(_Symbol,PERIOD_H1,AsianSessionLowest);
string strAsianSessionHigh = DoubleToString(AsianSessionHigh,_Digits);
string strAsianSessionLow = DoubleToString(AsianSessionLow,_Digits);
ObjectCreate(ChartID(),"London Open",OBJ_VLINE,0,LondonOpen,0);
ObjectCreate(ChartID(),"Asian Open",OBJ_VLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,0);
ObjectCreate(ChartID(),"Asian High",OBJ_HLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,AsianSessionHigh);
ObjectCreate(ChartID(),"Asian Low",OBJ_HLINE,0,TimeCurrent()-PeriodSeconds(PERIOD_H1)*10,AsianSessionLow);
if(ask < AsianSessionHigh && bid > AsianSessionLow && !IsTradeOpen()){
if((AsianSessionHigh-AsianSessionLow)*10000 >= 25 && (AsianSessionHigh-AsianSessionLow)*10000 <= 35){
Print("Nombre de Pips est: ", (AsianSessionHigh-AsianSessionLow)*10000);
Print(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow));
trade.BuyStop(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow),AsianSessionHigh,_Symbol,AsianSessionLow,0,ORDER_TIME_SPECIFIED,LondonClose,strAsianSessionLow);
trade.SellStop(PositionSizeCalculator(AsianSessionHigh-AsianSessionLow),AsianSessionLow,_Symbol,AsianSessionHigh,0,ORDER_TIME_SPECIFIED,LondonClose,strAsianSessionHigh);
}
}
IsLondonOpen = true;
}
if(TimeCurrent() > LondonClose && IsLondonOpen){
IsLondonOpen = false;
}
if(IsTradeOpen()){
ClosingOrder();
}
}
//+------------------------------------------------------------------+
//| Ancienne fonction: ClosingOrder()
//+------------------------------------------------------------------+
//void ClosingOrder(){
//
//for(int i = OrdersTotal()-1; i>=0; i--){
//
//ulong OrderTicket = OrderGetTicket(i);
//if(OrderSelect(OrderTicket) && IsTradeOpen())
//trade.OrderDelete(OrderTicket);
//}
//}
//+------------------------------------------------------------------+
//| Optimisation du fonction: ClosingOrder()
//+------------------------------------------------------------------+
bool ClosingOrder(){
for(int i = OrdersTotal()-1; i>=0; i--){
ulong OrderTicket = OrderGetTicket(i);
if(OrderSelect(OrderTicket) && IsTradeOpen()){
trade.OrderDelete(OrderTicket);
return true;
}
}
return false;
}
bool IsTradeOpen(){
for(int i = PositionsTotal()-1; i>=0; i--){
if(PositionGetString(POSITION_SYMBOL) == _Symbol){
return true;
}
}
return false;
}
double PositionSizeCalculator(double StopLoseSize){
double TickSize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
double TickValue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
double VolumeStep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
double RiskInCurrency = AccountInfoDouble(ACCOUNT_BALANCE)*RiskInPercent/100;
double RiskVolumeStep = StopLoseSize/TickSize*VolumeStep*TickValue;
double PositionSize = MathFloor(RiskInCurrency/RiskVolumeStep)*VolumeStep;
return PositionSize;
}
void TimeStructure(){
int Offset_hours = 2;
MqlDateTime structLondonOpen;
TimeCurrent(structLondonOpen);
structLondonOpen.hour = 8 + Offset_hours;
structLondonOpen.min = 0;
structLondonOpen.sec = 0;
LondonOpen = StructToTime(structLondonOpen);
MqlDateTime structLondonClose;
TimeCurrent(structLondonClose);
structLondonClose.hour = 17 + Offset_hours;
structLondonClose.min = 0;
structLondonClose.sec = 0;
LondonClose = StructToTime(structLondonClose);
}
void TrailingStop(){
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
for(int i = PositionsTotal()-1; i>=0; i--){
ulong PositionTicket = PositionGetTicket(i);
if(PositionSelectByTicket(PositionTicket) && PositionGetInteger(POSITION_TYPE) == 0){
double PositionSL = PositionGetDouble(POSITION_SL);
double PositionTP = PositionGetDouble(POSITION_TP);
double PositionPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
string PositionComment = PositionGetString(POSITION_COMMENT);
double FirstPositionSL = StringToDouble(PositionComment);
double PipsInProfit = ask - PositionPriceOpen;
double TrailingSL = FirstPositionSL + PipsInProfit;
if(PipsInProfit > 0 && TrailingSL > PositionSL){
trade.PositionModify(PositionTicket,TrailingSL,PositionTP);
}
}
if(PositionSelectByTicket(PositionTicket) && PositionGetInteger(POSITION_TYPE) == 1){
double PositionSL = PositionGetDouble(POSITION_SL);
double PositionTP = PositionGetDouble(POSITION_TP);
double PositionPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
string PositionComment = PositionGetString(POSITION_COMMENT);
double FirstPositionSL = StringToDouble(PositionComment);
double PipsInProfit = PositionPriceOpen - bid;
double TrailingSL = FirstPositionSL - PipsInProfit;
if(PipsInProfit > 0 && TrailingSL < PositionSL){
trade.PositionModify(PositionTicket,TrailingSL,PositionTP);
}
}
}
}
Et voici le changement dans le graphique....(Cf. Fichiers Jointes)
Bon visionnage et voici le lien de la précèdent article sur cette strategie....https://www.myfxbook.com/community/programming/london-breakout-expert-advisors-meta/3200425,1
*Não serão tolerados uso comercial ou spam. O não cumprimento desta regra poderá resultar na exclusão da conta.
Dica: Ao adicionar uma URL de imagem/youtube, você estará automaticamente incorporando-a à sua postagem!
Dica: Digite o símbolo @ para que o nome de um usuário que participe desta discussão seja completado automaticamente.