- Utama
- Komuniti
- Pengaturcaraan
- London Breakout: Expert Advisors in Meta Quote Language 5 (M...
Edit Your Comment
London Breakout: Expert Advisors in Meta Quote Language 5 (MQL5)
Ahli sejak Jun 02, 2024
4 hantaran
Jan 03 at 14:51
Ahli sejak Jun 02, 2024
4 hantaran
Bonjour et bonsoir a vous tous, j'ai codé une stratégie parlant de la cassure des high et Low lors de la session de Londres, qui constitue a prendre une position acheteur lorsque le prix casse le high de la session asiatique et une position vendeur lorsque le prix casse le Low de la session asiatique.
Voici le code source, comme je suis débutant, je vous laisse me corriger en commentaire, et j'aimerais que vous repondiez 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;
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();
}
}
void ClosingOrder(){
for(int i = OrdersTotal()-1; i>=0; i--){
ulong OrderTicket = OrderGetTicket(i);
if(OrderSelect(OrderTicket) && IsTradeOpen())
trade.OrderDelete(OrderTicket);
}
}
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);
}
}
}
}
Bon visionnage et j'ai épinglé l'extension du fichier au cas ou....
Voici le code source, comme je suis débutant, je vous laisse me corriger en commentaire, et j'aimerais que vous repondiez 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;
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();
}
}
void ClosingOrder(){
for(int i = OrdersTotal()-1; i>=0; i--){
ulong OrderTicket = OrderGetTicket(i);
if(OrderSelect(OrderTicket) && IsTradeOpen())
trade.OrderDelete(OrderTicket);
}
}
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);
}
}
}
}
Bon visionnage et j'ai épinglé l'extension du fichier au cas ou....
*Penggunaan komersil dan spam tidak akan diterima, dan boleh mengakibatkan penamatan akaun.
Petua: Menyiarkan url gambar/youtube akan menyisipkannya secara automatik dalam siaran hantaran anda!
Tip: Taipkan tanda @ untuk melengkapkan nama pengguna yang menyertai perbincangan ini secara automatik.