Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

EA basé sur les Points Pivots( mq4) ... a développer et dépoussiérer

  • lefeuvr3

    Utilisation en UT 1 Heure sur GBPUSD
    Code
    //+------------------------------------------------------------------+ //| PivotGBPUSD.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Lefeuvre" #property link "https://www.forexfactory.com" #property version "1" #property strict //----------------------- Include files ------------------------------------------------------------ #include <stdlib.mqh> // "stdlib.mqh" or "<sdlib.mqh> #include <stderror.mqh> // "stderror.mqh" or <stderror.mqh> //extern double VolatilityLimit = 180; extern double LotFactor=450; extern double Lot1Factor=18; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3;//pairglobalprofitEXPO=7 bool openonnewcandle = true; extern double spacePips = 6; extern double spaceOrders = 2; extern double space1Pips = 39; extern int space1Orders = 9; extern int magicbuy = 1; string buycomment = "buy"; extern int magicsell = 2; string sellcomment = "sell"; extern string Entry="Determine entry based on CCI"; extern int cciperiod = 5; extern double ccimax = 100; extern double ccimin = -100; extern bool suspendtrades = false; extern bool closeallsellsnow = false; extern bool closeallbuysnow = false; extern bool closeallnow = false; double totalprofit; bool sellallowed=false; bool buyallowed=false; bool firebuy=false; bool firesell=false; string stoptrading="0"; string error; int LotDigits = 2; //double volatility; //double ihigh; //double ilow; int barnumber=5; int nb=0; int multiplcator=10; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if (Digits==3 || Digits==5) { spacePips *= 10.0; space1Pips *= 10.0; } RemoveAllObjects(); double lotStep = MarketInfo(Symbol(),MODE_LOTSTEP) ; if (lotStep < 0.01) LotDigits=3; else if (lotStep < 0.1) LotDigits=2; else if (lotStep < 1.0) LotDigits=1; else LotDigits=0; double minLots = MarketInfo(Symbol(),MODE_MINLOT) ; double maxLots = MarketInfo(Symbol(),MODE_MAXLOT) ; if (multiplier==0) if (cciperiod<0) { error="cciperiod invalid"; return 0; } if (cciperiod > 0) { if (ccimax < ccimin) { error="ccimax/ccimin invalid"; return 0; } if (ccimax <-100 || ccimax > 100) { error="ccimax invalid"; return 0; } if (ccimin <-100 || ccimin > 100) { error="ccimin invalid"; return 0; } } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void RemoveAllObjects() { for(int i = ObjectsTotal() - 1; i >= 0; i--) { if (StringFind(ObjectName(i),"EA-",0) > -1) ObjectDelete(ObjectName(i)); } } //------------------------------------------------------------------+ // Generic Money management code //------------------------------------------------------------------+ double GetLotSize() { double lots = Lots; return(lots); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticketBuyOrder = GetTicketOfLatestBuyOrder(); int ticketSellOrder = GetTicketOfLatestSellOrder(); bool isNewBar = IsNewBar(); int index; // only show panel during live trading, not during optimization or backtesting if ( !IsTesting() && !IsOptimization() ) { if (GlobalVariableGet(stoptrading) == 1 && OrdersTotal() == 0 ) { GlobalVariableSet(stoptrading, 0); } } // determine entry based on CCI if (cciperiod > 0 && isNewBar == true) { firebuy = false; firesell = false; double cci = iCCI(Symbol(), 0, cciperiod, PRICE_TYPICAL, 0); if(sellallowed && cci < ccimin) { firesell = true; sellallowed = false; } if(buyallowed && cci > ccimax) { firebuy = true; buyallowed = false; } if (cci < ccimax && cci > ccimin) { buyallowed = true; sellallowed = true; } } // open 1st buy order if (firebuy && ticketBuyOrder == 0 && suspendtrades==false && closeallnow==false ) { if (GlobalVariableGet(stoptrading)==0) { index = OrderSend (Symbol(),OP_BUY, GetLotSize() , Ask , 3, 0, 0, buycomment, magicbuy, 0, Blue); if (index >= 0) { firebuy = false; } } } // manage buy orders, open new buy orders when needed if ( ticketBuyOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketBuyOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int buyOrderCount = GetBuyOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); double Pivot = (((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double S1 = (multiplcator * Pivot) - (iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))); double S2 = Pivot - ((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 )))); double R1 = (multiplcator * Pivot) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 ))); double R2 = Pivot + ((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 )))); if( Ask <= orderPrice - S1 * Point() && buyOrderCount < S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - S2 * Point() && buyOrderCount <= (S1 + S2 -1) && buyOrderCount >= S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } } } } // open 1st sell order.. if (firesell == true && ticketSellOrder == 0 && suspendtrades == false && closeallnow == false) { // open 1st sell order if ( GlobalVariableGet(stoptrading) == 0 ) { index = OrderSend (Symbol(), OP_SELL, GetLotSize(), Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); if (index >= 0) { firesell = false; } } } // manage sell order. open new sell orders when needed if ( ticketSellOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketSellOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int sellOrderCount = GetSellOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); /* double Pivot = ((High[nb] + Low[nb] + Close[nb]) / 3); double S1 = (2 * Pivot) - (High[nb]); double S2 = Pivot - (High[nb] - Low[nb]); double R1 = (2 * Pivot) - (Low[nb]); double R2 = Pivot + (High[nb] - Low[nb]);*/ double Pivot = (((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double S1 = (multiplcator * Pivot) - (iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))); double S2 = Pivot - ((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 )))); double R1 = (multiplcator * Pivot) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 ))); double R2 = Pivot + ((iHigh ( Symbol (), PERIOD_D1 , iHighest ( Symbol (), PERIOD_D1 , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), PERIOD_D1 , iLowest ( Symbol (), PERIOD_D1 , MODE_LOW, barnumber , 1 )))); if( Bid >= orderPrice + R1 * Point() && GetSellOrderCount() < R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } else if( Bid >= orderPrice + R2 * Point() && sellOrderCount <= (R1 + R2 - 1) && sellOrderCount >= R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } } } } // calculate profit / loss of all open orders double profitBuyOrders = 0; double profitSellOrders = 0; for(int k=OrdersTotal()-1; k >=0; k--) { if ( OrderSelect(k, SELECT_BY_POS)) { if (Symbol() == OrderSymbol()) { if (OrderType()==OP_BUY && OrderMagicNumber() == magicbuy) { profitBuyOrders = profitBuyOrders + OrderProfit() + OrderSwap() + OrderCommission(); } if (OrderType()==OP_SELL && OrderMagicNumber() == magicsell) { profitSellOrders = profitSellOrders + OrderProfit() + OrderSwap() + OrderCommission(); } } } } // close all buy orders (for this pair) when total profit of buy orders > profit if ((profit > 0 && profitBuyOrders >= profit) || closeallbuysnow == true) { CloseAllBuyOrders(); firebuy = false; } // close all sell orders (for this pair) when total profit of sell orders > profit if ((profit > 0 && profitSellOrders >= profit) || closeallsellsnow == true) { CloseAllSellOrders(); firesell = false; } // close all orders when total profit on this pair > pairglobalprofit if ((AccountBalance() * 0.01 /pairglobalprofitEXPO)> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01 /pairglobalprofitEXPO)) { CloseAllSellOrders(); CloseAllBuyOrders(); firebuy = false; firesell = false; } // close all orders when total profit on all pairs > totalglobalprofit // or if total loss on all pairs > maximaloss double totalglobalprofit = TotalProfitOnAllPairs(); if((globalprofit > 0 && totalglobalprofit >= globalprofit) /*|| (maximaloss < 0 && totalglobalprofit <= maximaloss)*/) { GlobalVariableSet(stoptrading, 1); CloseAllOrdersOnAllPairs(); firebuy = false; firesell = false; } } //+------------------------------------------------------------------+ // GetBuyOrderCount() // returns the number of open buy orders //+------------------------------------------------------------------+ int GetBuyOrderCount() { int count=0; for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType()==OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetSellOrderCount() // returns the number of open sell orders //+------------------------------------------------------------------+ int GetSellOrderCount() { int count=0; // find all open orders of today for (int k = OrdersTotal(); k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetTicketOfLatestBuyOrder() // returns the ticket of the latest open buy order //+------------------------------------------------------------------+ int GetTicketOfLatestBuyOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l,SELECT_BY_POS)) { if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // GetTicketOfLatestSellOrder() // returns the ticket of the latest open sell order //+------------------------------------------------------------------+ int GetTicketOfLatestSellOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l, SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // CloseAllBuyOrders() // closes all open buy orders //+------------------------------------------------------------------+ void CloseAllBuyOrders() { for (int m=OrdersTotal(); m>=0; m--) { if ( OrderSelect(m, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success = OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue); } } } } //+------------------------------------------------------------------+ // CloseAllSellOrders() // closes all open sell orders //+------------------------------------------------------------------+ void CloseAllSellOrders() { for (int h=OrdersTotal();h>=0;h--) { if ( OrderSelect(h,SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } } } } //+------------------------------------------------------------------+ // CloseAllOrdersOnAllPairs() // closes all open orders on all pairs //+------------------------------------------------------------------+ void CloseAllOrdersOnAllPairs() { for (int h=OrdersTotal(); h>=0; h--) { if ( OrderSelect(h, SELECT_BY_POS) ) { if (OrderType() == OP_SELL && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } if (OrderType() == OP_BUY && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red); } } } } //+------------------------------------------------------------------+ // TotalProfitOnAllPairs() // returns the total profit for all open orders on all pairs //+------------------------------------------------------------------+ double TotalProfitOnAllPairs() { double totalProfit = 0; for (int j=OrdersTotal();j >= 0; j--) { if( OrderSelect(j,SELECT_BY_POS)) { if (OrderMagicNumber() == magicsell || OrderMagicNumber() == magicbuy) { RefreshRates(); totalProfit = totalProfit + OrderProfit() + OrderSwap() + OrderCommission(); } } } return totalProfit; } //+------------------------------------------------------------------+ // IsNewBar() // returns if new bar has started //+------------------------------------------------------------------+ bool IsNewBar() { static datetime time = Time[0]; if(Time[0] > time) { time = Time[0]; //newbar, update time return (true); } return(false); } //-------------------------------------------------------------------------------- // TradesToday() // return total number of trades done today (closed and still open) //-------------------------------------------------------------------------------- int TradesToday() { int count=0; if (IsTesting() || IsOptimization()) return 0; // find all open orders of today for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k,SELECT_BY_POS)) { if (OrderSymbol() == Symbol() ) { if(OrderLots() == Lots) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if( TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { count=count+1; } } } } } } for (int l=OrdersHistoryTotal(); l >= 0; l--) { if(OrderSelect(l, SELECT_BY_POS,MODE_HISTORY)) { if (OrderSymbol() == Symbol() ) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if(TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { if(OrderLots() == Lots) { count = count + 1; } } else { return count; } } } } } return count; }
    lefeuvr3 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13700
  • Mikiburger

    Merci.
    Ca a l'air de bien fonctionner.
    Tu as les paramètres pour l'EURUSD ?
  • Haithemfx06

    Mikiburger, le 28/09/2021 dit :
    Merci. Ca a l'air de bien fonctionner. Tu as les paramètres pour l'EURUSD ?


    pour un DD pareil non il n'assure pas
    - la perte maximale (1700) ne doit pas dépasser le capital investi (1000),
    - un taux de profit de 62% c'est faible. un bon EA commence par 78% et plus.
    il faut changer le montant du dépôt minimum.
    c'est une bonne idée mais juste limiter le risk ratio. le but c'est de rendre cela viable a long terme
    Modifié le 2021-09-28 13:02:02 par Haithemfx06
  • lefeuvr3

    Je viens de l'ameliorer
    Code
    //+------------------------------------------------------------------+ //| lefeuvreGBPUSD.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //----------------------- Include files ------------------------------------------------------------ #include <stdlib.mqh> // "stdlib.mqh" or "<sdlib.mqh> #include <stderror.mqh> // "stderror.mqh" or <stderror.mqh> extern double LotFactor=320; extern double Lot1Factor=70; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 2.8;//pairglobalprofitEXPO=7 bool openonnewcandle = true; extern int magicbuy = 1; string buycomment = "buy"; extern int magicsell = 2; string sellcomment = "sell"; extern string Entry="Determine entry based on CCI"; extern int cciperiod = 5; extern double ccimax = 100; extern double ccimin = -100; extern bool suspendtrades = false; extern bool closeallsellsnow = false; extern bool closeallbuysnow = false; extern bool closeallnow = false; double totalprofit; bool sellallowed=false; bool buyallowed=false; bool firebuy=false; bool firesell=false; string stoptrading="0"; string error; int LotDigits = 2; int barnumber=5; int nb=0; int multiplcator=10; extern string Periode1="M1=1**M5=5**M15=15**M30=30**H1=60**H4=240**D1=1440**W1=10080**MN=43200"; extern int Periode=1440; extern int Periode2=60; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if (Digits==3 || Digits==5) RemoveAllObjects(); double lotStep = MarketInfo(Symbol(),MODE_LOTSTEP) ; if (lotStep < 0.01) LotDigits=3; else if (lotStep < 0.1) LotDigits=2; else if (lotStep < 1.0) LotDigits=1; else LotDigits=0; double minLots = MarketInfo(Symbol(),MODE_MINLOT) ; double maxLots = MarketInfo(Symbol(),MODE_MAXLOT) ; if (multiplier==0) if (cciperiod<0) { error="cciperiod invalid"; return 0; } if (cciperiod > 0) { if (ccimax < ccimin) { error="ccimax/ccimin invalid"; return 0; } if (ccimax <-100 || ccimax > 100) { error="ccimax invalid"; return 0; } if (ccimin <-100 || ccimin > 100) { error="ccimin invalid"; return 0; } } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void RemoveAllObjects() { for(int i = ObjectsTotal() - 1; i >= 0; i--) { if (StringFind(ObjectName(i),"EA-",0) > -1) ObjectDelete(ObjectName(i)); } } //------------------------------------------------------------------+ // Generic Money management code //------------------------------------------------------------------+ double GetLotSize() { double lots = Lots; return(lots); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticketBuyOrder = GetTicketOfLatestBuyOrder(); int ticketSellOrder = GetTicketOfLatestSellOrder(); bool isNewBar = IsNewBar(); int index; // only show panel during live trading, not during optimization or backtesting if ( !IsTesting() && !IsOptimization() ) { if (GlobalVariableGet(stoptrading) == 1 && OrdersTotal() == 0 ) { GlobalVariableSet(stoptrading, 0); } } // determine entry based on CCI if (cciperiod > 0 && isNewBar == true) { firebuy = false; firesell = false; double cci = iCCI(Symbol(), 0, cciperiod, PRICE_TYPICAL, 0); double orderPrice = OrderOpenPrice(); double Pivot = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); if(sellallowed && Pivot < orderPrice) { firesell = true; sellallowed = false; } if(buyallowed && Pivot > orderPrice) { firebuy = true; buyallowed = false; } if (cci < ccimax && cci > ccimin) { buyallowed = true; sellallowed = true; } } // open 1st buy order if (firebuy && ticketBuyOrder == 0 && suspendtrades==false && closeallnow==false ) { if (GlobalVariableGet(stoptrading)==0) { index = OrderSend (Symbol(),OP_BUY, GetLotSize() , Ask , 3, 0, 0, buycomment, magicbuy, 0, Blue); if (index >= 0) { firebuy = false; } } } // manage buy orders, open new buy orders when needed if ( ticketBuyOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketBuyOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int buyOrderCount = GetBuyOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); double Pivot = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double S1 = (multiplcator * Pivot) - (iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))); double S2 = Pivot - ((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); double R1 = (multiplcator * Pivot) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))); double R2 = Pivot + ((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); if( Ask <= orderPrice - S1 * Point() && buyOrderCount < S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - S2 * Point() && buyOrderCount <= (S1 + S2 -1) && buyOrderCount >= S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } } } } // open 1st sell order.. if (firesell == true && ticketSellOrder == 0 && suspendtrades == false && closeallnow == false) { // open 1st sell order if ( GlobalVariableGet(stoptrading) == 0 ) { index = OrderSend (Symbol(), OP_SELL, GetLotSize(), Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); if (index >= 0) { firesell = false; } } } // manage sell order. open new sell orders when needed if ( ticketSellOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketSellOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int sellOrderCount = GetSellOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); /* double Pivot = ((High[nb] + Low[nb] + Close[nb]) / 3); double S1 = (2 * Pivot) - (High[nb]); double S2 = Pivot - (High[nb] - Low[nb]); double R1 = (2 * Pivot) - (Low[nb]); double R2 = Pivot + (High[nb] - Low[nb]); */ double Pivot = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double S1 = (multiplcator * Pivot) - (iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))); double S2 = Pivot - ((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); double R1 = (multiplcator * Pivot) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))); double R2 = Pivot + ((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); if( Bid >= orderPrice + R1 * Point() && GetSellOrderCount() < R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } else if( Bid >= orderPrice + R2 * Point() && sellOrderCount <= (R1 + R2 - 1) && sellOrderCount >= R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } } } } // calculate profit / loss of all open orders double profitBuyOrders = 0; double profitSellOrders = 0; for(int k=OrdersTotal()-1; k >=0; k--) { if ( OrderSelect(k, SELECT_BY_POS)) { if (Symbol() == OrderSymbol()) { if (OrderType()==OP_BUY && OrderMagicNumber() == magicbuy) { profitBuyOrders = profitBuyOrders + OrderProfit() + OrderSwap() + OrderCommission(); } if (OrderType()==OP_SELL && OrderMagicNumber() == magicsell) { profitSellOrders = profitSellOrders + OrderProfit() + OrderSwap() + OrderCommission(); } } } } // close all buy orders (for this pair) when total profit of buy orders > profit if ((profit > 0 && profitBuyOrders >= profit) || closeallbuysnow == true) { CloseAllBuyOrders(); firebuy = false; } // close all sell orders (for this pair) when total profit of sell orders > profit if ((profit > 0 && profitSellOrders >= profit) || closeallsellsnow == true) { CloseAllSellOrders(); firesell = false; } // close all orders when total profit on this pair > pairglobalprofit if ((AccountBalance() * 0.01 /pairglobalprofitEXPO)> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01 /pairglobalprofitEXPO)) { CloseAllSellOrders(); CloseAllBuyOrders(); firebuy = false; firesell = false; } // close all orders when total profit on all pairs > totalglobalprofit // or if total loss on all pairs > maximaloss double totalglobalprofit = TotalProfitOnAllPairs(); if((globalprofit > 0 && totalglobalprofit >= globalprofit) /*|| (maximaloss < 0 && totalglobalprofit <= maximaloss)*/) { GlobalVariableSet(stoptrading, 1); CloseAllOrdersOnAllPairs(); firebuy = false; firesell = false; } } //+------------------------------------------------------------------+ // GetBuyOrderCount() // returns the number of open buy orders //+------------------------------------------------------------------+ int GetBuyOrderCount() { int count=0; for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType()==OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetSellOrderCount() // returns the number of open sell orders //+------------------------------------------------------------------+ int GetSellOrderCount() { int count=0; // find all open orders of today for (int k = OrdersTotal(); k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetTicketOfLatestBuyOrder() // returns the ticket of the latest open buy order //+------------------------------------------------------------------+ int GetTicketOfLatestBuyOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l,SELECT_BY_POS)) { if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // GetTicketOfLatestSellOrder() // returns the ticket of the latest open sell order //+------------------------------------------------------------------+ int GetTicketOfLatestSellOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l, SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // CloseAllBuyOrders() // closes all open buy orders //+------------------------------------------------------------------+ void CloseAllBuyOrders() { for (int m=OrdersTotal(); m>=0; m--) { if ( OrderSelect(m, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success = OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue); } } } } //+------------------------------------------------------------------+ // CloseAllSellOrders() // closes all open sell orders //+------------------------------------------------------------------+ void CloseAllSellOrders() { for (int h=OrdersTotal();h>=0;h--) { if ( OrderSelect(h,SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } } } } //+------------------------------------------------------------------+ // CloseAllOrdersOnAllPairs() // closes all open orders on all pairs //+------------------------------------------------------------------+ void CloseAllOrdersOnAllPairs() { for (int h=OrdersTotal(); h>=0; h--) { if ( OrderSelect(h, SELECT_BY_POS) ) { if (OrderType() == OP_SELL && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } if (OrderType() == OP_BUY && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red); } } } } //+------------------------------------------------------------------+ // TotalProfitOnAllPairs() // returns the total profit for all open orders on all pairs //+------------------------------------------------------------------+ double TotalProfitOnAllPairs() { double totalProfit = 0; for (int j=OrdersTotal();j >= 0; j--) { if( OrderSelect(j,SELECT_BY_POS)) { if (OrderMagicNumber() == magicsell || OrderMagicNumber() == magicbuy) { RefreshRates(); totalProfit = totalProfit + OrderProfit() + OrderSwap() + OrderCommission(); } } } return totalProfit; } //+------------------------------------------------------------------+ // IsNewBar() // returns if new bar has started //+------------------------------------------------------------------+ bool IsNewBar() { static datetime time = Time[0]; if(Time[0] > time) { time = Time[0]; //newbar, update time return (true); } return(false); } //-------------------------------------------------------------------------------- // TradesToday() // return total number of trades done today (closed and still open) //-------------------------------------------------------------------------------- int TradesToday() { int count=0; if (IsTesting() || IsOptimization()) return 0; // find all open orders of today for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k,SELECT_BY_POS)) { if (OrderSymbol() == Symbol() ) { if(OrderLots() == Lots) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if( TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { count=count+1; } } } } } } for (int l=OrdersHistoryTotal(); l >= 0; l--) { if(OrderSelect(l, SELECT_BY_POS,MODE_HISTORY)) { if (OrderSymbol() == Symbol() ) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if(TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { if(OrderLots() == Lots) { count = count + 1; } } else { return count; } } } } } return count; }
    lefeuvr3 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13703
  • Haithemfx06

    augmente ton capital investis
    Modifié le 2021-09-28 13:18:16 par Haithemfx06
    Haithemfx06 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13704
  • lefeuvr3

    Ce robot n' a que 3 jours ... ce n'est pas celui qui tourne sur ma plateforme.
    Il faut voir si on peut l'améliorer et le backtester avec tickstory ,dans tous les sens ,avec plusieurs montants de capital.
    En tout les cas j'ai utiliser des tas de points pivots et retenus les meilleurs ... modestement les miens :)
    Modifié le 2021-09-28 16:43:24 par lefeuvr3 : orthographe
  • stevenfoarbs

    Bonjour,

    Merci pour ce partage. J'ai une question qui ne concerne pas forcement ce robot mais plutôt tous les robots et leur rendements de manière générale :
    Pour parler de celui-ci par exemple, le résultat reste très positif avec une certaine régularité avec un test fait avec tickstory donc un bon modelage.
    Hors je lis souvent que ça ne reflète pas la réalité : qu'en est-il ?! est-ce que cela veut dire qu'il ne faut pas se fier à ces backtests ? Ou est-ce qu'il simplement aller plus loin dans les tests (faire des tests de plusieurs années par exemple) ?
    Quelle est la différence entre un backtest fait avec tickstory et du réel ?

    Merci pour vos précisions !
  • lefeuvr3

    stevenfoarbs ,je me suis rendu compte que les performances affichées sur les backtests sont moindres sur un compte réel ... par exemple : un capital multiplié par quatre dans un backtest ,ne sera multiplie que par deux sur un compte réel.
  • stevenfoarbs

    lefeuvr3, le 08/10/2021 dit :
    stevenfoarbs ,je me suis rendu compte que les performances affichées sur les backtests sont moindres sur un compte réel ... par exemple : un capital multiplié par quatre dans un backtest ,ne sera multiplie que par deux sur un compte réel.


    Merci pour la confirmation ! Mais du coup : à quoi est dû cette différence si grande ? c'est là ou j'ai du mal à comprendre.
    Si je laisse tourner un robot sur 3 mois par exemple, et que je refais le backtest sur ces mêmes 3 mois je n'aurai donc pas le même résultat ?! très étrange quand même...
  • Matthieuw31

    Bonjour Lefeuvr3,
    Ce backtest est très prometteur, par contre sur d'autres périodes hélas c'est la banque route. Le bot ouvre par exemple plusieurs ordres d'achat mais si le cours ne cesse de chuter, aucun de ces ordres n'est fermé. Y a t'il un paramètre pour éviter ça ?
  • lefeuvr3

    Nouvelle version simplifiée à Utiliser sur GBPUSD 1 mn.
    En réel ,dernièrement ,il m' a fait un peu peur mais a parfaitement rétabli la situation ,sans que j'ai eu a augmenter le capital de départ,en gérant au mieux les positions !
    Il faut toujours garder à l'esprit que l'on peut toujours perdre l'intégralité du capital investi.....il peut être judicieux de retirer ses benefices lorsque le capital de depart a été doublé.
    Code
    //+------------------------------------------------------------------+ //| Martingale-CCI-GBPUSD-1mn.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //----------------------- Include files ------------------------------------------------------------ #include <stdlib.mqh> // "stdlib.mqh" or "<sdlib.mqh> #include <stderror.mqh> // "stderror.mqh" or <stderror.mqh> //extern double VolatilityLimit = 180; extern double LotFactor=500; extern double Lot1Factor=290; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 8;//pairglobalprofitEXPO=7 bool openonnewcandle = true; extern double spacePips = 6; extern double spaceOrders = 2; extern double space1Pips = 39; extern int space1Orders = 5; extern int magicbuy = 1; string buycomment = "buy"; extern int magicsell = 2; string sellcomment = "sell"; extern string Entry="Determine entry based on CCI"; extern int cciperiod = 18; extern double ccimax = 100; extern double ccimin = -100; extern bool suspendtrades = false; extern bool closeallsellsnow = false; extern bool closeallbuysnow = false; extern bool closeallnow = false; double totalprofit; bool sellallowed=false; bool buyallowed=false; bool firebuy=false; bool firesell=false; string stoptrading="0"; string error; int LotDigits = 2; //double volatility; //double ihigh; //double ilow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if (Digits==3 || Digits==5) { spacePips *= 10.0; space1Pips *= 10.0; } RemoveAllObjects(); double lotStep = MarketInfo(Symbol(),MODE_LOTSTEP) ; if (lotStep < 0.01) LotDigits=3; else if (lotStep < 0.1) LotDigits=2; else if (lotStep < 1.0) LotDigits=1; else LotDigits=0; double minLots = MarketInfo(Symbol(),MODE_MINLOT) ; double maxLots = MarketInfo(Symbol(),MODE_MAXLOT) ; if (multiplier==0) if (cciperiod<0) { error="cciperiod invalid"; return 0; } if (cciperiod > 0) { if (ccimax < ccimin) { error="ccimax/ccimin invalid"; return 0; } if (ccimax <-100 || ccimax > 100) { error="ccimax invalid"; return 0; } if (ccimin <-100 || ccimin > 100) { error="ccimin invalid"; return 0; } } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void RemoveAllObjects() { for(int i = ObjectsTotal() - 1; i >= 0; i--) { if (StringFind(ObjectName(i),"EA-",0) > -1) ObjectDelete(ObjectName(i)); } } //------------------------------------------------------------------+ // Generic Money management code //------------------------------------------------------------------+ double GetLotSize() { double lots = Lots; return(lots); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticketBuyOrder = GetTicketOfLatestBuyOrder(); int ticketSellOrder = GetTicketOfLatestSellOrder(); bool isNewBar = IsNewBar(); int index; // only show panel during live trading, not during optimization or backtesting if ( !IsTesting() && !IsOptimization() ) { if (GlobalVariableGet(stoptrading) == 1 && OrdersTotal() == 0 ) { GlobalVariableSet(stoptrading, 0); } } // determine entry based on CCI if (cciperiod > 0 && isNewBar == true) { firebuy = false; firesell = false; double cci = iCCI(Symbol(), 0, cciperiod, PRICE_TYPICAL, 0); if(sellallowed && cci < ccimin) { firesell = true; sellallowed = false; } if(buyallowed && cci > ccimax) { firebuy = true; buyallowed = false; } if (cci < ccimax && cci > ccimin) { buyallowed = true; sellallowed = true; } } // open 1st buy order if (firebuy && ticketBuyOrder == 0 && suspendtrades==false && closeallnow==false ) { if (GlobalVariableGet(stoptrading)==0) { index = OrderSend (Symbol(),OP_BUY, GetLotSize() , Ask , 3, 0, 0, buycomment, magicbuy, 0, Blue); if (index >= 0) { firebuy = false; } } } // manage buy orders, open new buy orders when needed if ( ticketBuyOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketBuyOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int buyOrderCount = GetBuyOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); if( Ask <= orderPrice - spacePips * Point() && buyOrderCount < spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - space1Pips * Point() && buyOrderCount <= (spaceOrders + space1Orders-1) && buyOrderCount >= spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } } } } // open 1st sell order.. if (firesell == true && ticketSellOrder == 0 && suspendtrades == false && closeallnow == false) { // open 1st sell order if ( GlobalVariableGet(stoptrading) == 0 ) { index = OrderSend (Symbol(), OP_SELL, GetLotSize(), Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); if (index >= 0) { firesell = false; } } } // manage sell order. open new sell orders when needed if ( ticketSellOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketSellOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int sellOrderCount = GetSellOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); if( Bid >= orderPrice + spacePips * Point() && GetSellOrderCount() < spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } else if( Bid >= orderPrice + space1Pips * Point() && sellOrderCount <= (spaceOrders + space1Orders - 1) && sellOrderCount >= spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } } } } // calculate profit / loss of all open orders double profitBuyOrders = 0; double profitSellOrders = 0; for(int k=OrdersTotal()-1; k >=0; k--) { if ( OrderSelect(k, SELECT_BY_POS)) { if (Symbol() == OrderSymbol()) { if (OrderType()==OP_BUY && OrderMagicNumber() == magicbuy) { profitBuyOrders = profitBuyOrders + OrderProfit() + OrderSwap() + OrderCommission(); } if (OrderType()==OP_SELL && OrderMagicNumber() == magicsell) { profitSellOrders = profitSellOrders + OrderProfit() + OrderSwap() + OrderCommission(); } } } } // close all buy orders (for this pair) when total profit of buy orders > profit if ((profit > 0 && profitBuyOrders >= profit) || closeallbuysnow == true) { CloseAllBuyOrders(); firebuy = false; } // close all sell orders (for this pair) when total profit of sell orders > profit if ((profit > 0 && profitSellOrders >= profit) || closeallsellsnow == true) { CloseAllSellOrders(); firesell = false; } // close all orders when total profit on this pair > pairglobalprofit if ((AccountBalance() * 0.01 /pairglobalprofitEXPO)> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01 /pairglobalprofitEXPO)) { CloseAllSellOrders(); CloseAllBuyOrders(); firebuy = false; firesell = false; } // close all orders when total profit on all pairs > totalglobalprofit // or if total loss on all pairs > maximaloss double totalglobalprofit = TotalProfitOnAllPairs(); if((globalprofit > 0 && totalglobalprofit >= globalprofit) /*|| (maximaloss < 0 && totalglobalprofit <= maximaloss)*/) { GlobalVariableSet(stoptrading, 1); CloseAllOrdersOnAllPairs(); firebuy = false; firesell = false; } } //+------------------------------------------------------------------+ // GetBuyOrderCount() // returns the number of open buy orders //+------------------------------------------------------------------+ int GetBuyOrderCount() { int count=0; for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType()==OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetSellOrderCount() // returns the number of open sell orders //+------------------------------------------------------------------+ int GetSellOrderCount() { int count=0; // find all open orders of today for (int k = OrdersTotal(); k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetTicketOfLatestBuyOrder() // returns the ticket of the latest open buy order //+------------------------------------------------------------------+ int GetTicketOfLatestBuyOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l,SELECT_BY_POS)) { if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // GetTicketOfLatestSellOrder() // returns the ticket of the latest open sell order //+------------------------------------------------------------------+ int GetTicketOfLatestSellOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l, SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // CloseAllBuyOrders() // closes all open buy orders //+------------------------------------------------------------------+ void CloseAllBuyOrders() { for (int m=OrdersTotal(); m>=0; m--) { if ( OrderSelect(m, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success = OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue); } } } } //+------------------------------------------------------------------+ // CloseAllSellOrders() // closes all open sell orders //+------------------------------------------------------------------+ void CloseAllSellOrders() { for (int h=OrdersTotal();h>=0;h--) { if ( OrderSelect(h,SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } } } } //+------------------------------------------------------------------+ // CloseAllOrdersOnAllPairs() // closes all open orders on all pairs //+------------------------------------------------------------------+ void CloseAllOrdersOnAllPairs() { for (int h=OrdersTotal(); h>=0; h--) { if ( OrderSelect(h, SELECT_BY_POS) ) { if (OrderType() == OP_SELL && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } if (OrderType() == OP_BUY && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red); } } } } //+------------------------------------------------------------------+ // TotalProfitOnAllPairs() // returns the total profit for all open orders on all pairs //+------------------------------------------------------------------+ double TotalProfitOnAllPairs() { double totalProfit = 0; for (int j=OrdersTotal();j >= 0; j--) { if( OrderSelect(j,SELECT_BY_POS)) { if (OrderMagicNumber() == magicsell || OrderMagicNumber() == magicbuy) { RefreshRates(); totalProfit = totalProfit + OrderProfit() + OrderSwap() + OrderCommission(); } } } return totalProfit; } //+------------------------------------------------------------------+ // IsNewBar() // returns if new bar has started //+------------------------------------------------------------------+ bool IsNewBar() { static datetime time = Time[0]; if(Time[0] > time) { time = Time[0]; //newbar, update time return (true); } return(false); } //-------------------------------------------------------------------------------- // TradesToday() // return total number of trades done today (closed and still open) //-------------------------------------------------------------------------------- int TradesToday() { int count=0; if (IsTesting() || IsOptimization()) return 0; // find all open orders of today for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k,SELECT_BY_POS)) { if (OrderSymbol() == Symbol() ) { if(OrderLots() == Lots) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if( TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { count=count+1; } } } } } } for (int l=OrdersHistoryTotal(); l >= 0; l--) { if(OrderSelect(l, SELECT_BY_POS,MODE_HISTORY)) { if (OrderSymbol() == Symbol() ) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if(TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { if(OrderLots() == Lots) { count = count + 1; } } else { return count; } } } } } return count; }
    Modifié le 2021-10-16 09:20:24 par lefeuvr3 : erreur balises
  • stevenfoarbs — en réponse à lefeuvr3 dans son message #125316

    Bonjour,

    J'ai fait le backtest sur une année avec cette nouvelle version en GBPUSD M1 (avec tickstory) et ça n'est pas positif.
    stevenfoarbs a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13718
  • lefeuvr3

    Je pense qu'il faut doubler le capital de depart ... soit 2000 €uros au moins
  • stevenfoarbs

    en effet je confirme ! pourquoi une telle différence du coup ?
    Les lots ne sont pas adaptés au capital ?
  • lefeuvr3

    J'ai tout adapté à la taille du solde (account balance ) dans le programme ,en croissance exponentielle ....tant au niveau des lots que des différents objectifs de gains des positions ouvertes....j'ai modéré le coefficient de croissance exponentielle pour limiter les risques de crash du compte !
  • lefeuvr3

    Est ce qu'une bonne âme ,pourrais adjoindre un trailing stop au programme une fois l'objectif de gain atteint .... merci d'avance
  • lefeuvr3

    J'ai donc adjoins un trailingstop mais le resultat n'est pas terrible
    Code
    extern int TrailingStop1 =340; ///+------------------------------------------------------------------+ //Trailing Stop for the BUY for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_BUY) { if(Bid >= OrderStopLoss() + (TrailingStop1*_Point)) bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),Ask - (TrailingStop1*_Point),( closeallbuysnow && closeallsellsnow ),0,Green); } } //Trailing Stop for the SELL for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELL) { if(Ask <= OrderStopLoss() - (TrailingStop1*_Point)) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),Bid + (TrailingStop1*_Point),(closeallbuysnow && closeallsellsnow ) ,0,Green); } } //+------------------------------------------------------------------+ // close all buy orders (for this pair) when total profit of buy orders > profit if ((profit > 0 && profitBuyOrders >= profit) || closeallbuysnow == true) { CloseAllBuyOrders(); firebuy = false; }
  • lefeuvr3

    Je vais essayer de limiter les trades quand la volatilité est trop forte pour dormir plus sereinement :)
  • lefeuvr3

    Reduction des trades si la volatilité est trop forte sur une certaine periode, pour dormir plus sereinement :)

    Code
    //+------------------------------------------------------------------+ //| Martingale-CCI-GBPUSD-1mn-Volatility.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //----------------------- Include files ------------------------------------------------------------ #include <stdlib.mqh> // "stdlib.mqh" or "<sdlib.mqh> #include <stderror.mqh> // "stderror.mqh" or <stderror.mqh> //extern double VolatilityLimit = 180; extern double LotFactor=500; extern double Lot1Factor=290; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 8;//pairglobalprofitEXPO=7 bool openonnewcandle = true; extern double spacePips = 6; extern double spaceOrders = 2; extern double space1Pips = 39; extern int space1Orders = 5; extern int magicbuy = 1; string buycomment = "buy"; extern int magicsell = 2; string sellcomment = "sell"; extern string Entry="Determine entry based on CCI"; extern int cciperiod = 18; extern double ccimax = 100; extern double ccimin = -100; extern bool suspendtrades = false; extern bool closeallsellsnow = false; extern bool closeallbuysnow = false; extern bool closeallnow = false; double totalprofit; bool sellallowed=false; bool buyallowed=false; bool firebuy=false; bool firesell=false; string stoptrading="0"; string error; int LotDigits = 2; extern int barnumber=15; double ihigh0 ; double ihigh1 ; double ilow0 ; double ilow1 ; double volatility0; double volatility1; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if (Digits==3 || Digits==5) { spacePips *= 10.0; space1Pips *= 10.0; } RemoveAllObjects(); double lotStep = MarketInfo(Symbol(),MODE_LOTSTEP) ; if (lotStep < 0.01) LotDigits=3; else if (lotStep < 0.1) LotDigits=2; else if (lotStep < 1.0) LotDigits=1; else LotDigits=0; double minLots = MarketInfo(Symbol(),MODE_MINLOT) ; double maxLots = MarketInfo(Symbol(),MODE_MAXLOT) ; if (multiplier==0) if (cciperiod<0) { error="cciperiod invalid"; return 0; } if (cciperiod > 0) { if (ccimax < ccimin) { error="ccimax/ccimin invalid"; return 0; } if (ccimax <-100 || ccimax > 100) { error="ccimax invalid"; return 0; } if (ccimin <-100 || ccimin > 100) { error="ccimin invalid"; return 0; } } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void RemoveAllObjects() { for(int i = ObjectsTotal() - 1; i >= 0; i--) { if (StringFind(ObjectName(i),"EA-",0) > -1) ObjectDelete(ObjectName(i)); } } //------------------------------------------------------------------+ // Generic Money management code //------------------------------------------------------------------+ double GetLotSize() { double lots = Lots; return(lots); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticketBuyOrder = GetTicketOfLatestBuyOrder(); int ticketSellOrder = GetTicketOfLatestSellOrder(); bool isNewBar = IsNewBar(); int index; // only show panel during live trading, not during optimization or backtesting if ( !IsTesting() && !IsOptimization() ) { if (GlobalVariableGet(stoptrading) == 1 && OrdersTotal() == 0 ) { GlobalVariableSet(stoptrading, 0); } } // determine entry based on CCI if (cciperiod > 0 && isNewBar == true) { firebuy = false; firesell = false; double cci = iCCI(Symbol(), 0, cciperiod, PRICE_TYPICAL, 0); if(sellallowed && cci < ccimin) { firesell = true; sellallowed = false; } if(buyallowed && cci > ccimax) { firebuy = true; buyallowed = false; } if (cci < ccimax && cci > ccimin) { buyallowed = true; sellallowed = true; } } // open 1st buy order if (firebuy && ticketBuyOrder == 0 && suspendtrades==false && closeallnow==false ) { if (GlobalVariableGet(stoptrading)==0) if ((volatility0)<(volatility1)) { index = OrderSend (Symbol(),OP_BUY, GetLotSize() , Ask , 3, 0, 0, buycomment, magicbuy, 0, Blue); if (index >= 0) { firebuy = false; } } } // manage buy orders, open new buy orders when needed if ( ticketBuyOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketBuyOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int buyOrderCount = GetBuyOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); if( Ask <= orderPrice - spacePips * Point() && buyOrderCount < spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - space1Pips * Point() && buyOrderCount <= (spaceOrders + space1Orders-1) && buyOrderCount >= spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } } } } // open 1st sell order.. if (firesell == true && ticketSellOrder == 0 && suspendtrades == false && closeallnow == false) { // open 1st sell order if ( GlobalVariableGet(stoptrading) == 0 ) ihigh0 = (iHigh ( Symbol (), PERIOD_M1 , iHighest ( Symbol (), PERIOD_M1 , MODE_HIGH, barnumber , 0 ))); ihigh1=(iHigh ( Symbol (), PERIOD_M1 , iHighest ( Symbol (), PERIOD_M1 , MODE_HIGH, barnumber , 1 ))) ; ilow0=(iLow ( Symbol (), PERIOD_M1 , iLowest ( Symbol (), PERIOD_M1 , MODE_LOW, barnumber , 0 ))); ilow1=(iLow ( Symbol (), PERIOD_M1 , iLowest ( Symbol (), PERIOD_M1 , MODE_LOW, barnumber , 1 ))); volatility0 = (ihigh0 - ilow0); volatility1 = ((ihigh1) - (ilow1)); if ((volatility0)<(volatility1)) { index = OrderSend (Symbol(), OP_SELL, GetLotSize(), Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); if (index >= 0) { firesell = false; } } } // manage sell order. open new sell orders when needed if ( ticketSellOrder != 0) { if ( isNewBar || openonnewcandle == 0) { if ( OrderSelect(ticketSellOrder, SELECT_BY_TICKET)) { double orderLots = OrderLots(); double orderPrice = OrderOpenPrice(); int sellOrderCount = GetSellOrderCount(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); if( Bid >= orderPrice + spacePips * Point() && GetSellOrderCount() < spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } else if( Bid >= orderPrice + space1Pips * Point() && sellOrderCount <= (spaceOrders + space1Orders - 1) && sellOrderCount >= spaceOrders) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, sellcomment, magicsell, 0, Red); } } } } // calculate profit / loss of all open orders double profitBuyOrders = 0; double profitSellOrders = 0; for(int k=OrdersTotal()-1; k >=0; k--) { if ( OrderSelect(k, SELECT_BY_POS)) { if (Symbol() == OrderSymbol()) { if (OrderType()==OP_BUY && OrderMagicNumber() == magicbuy) { profitBuyOrders = profitBuyOrders + OrderProfit() + OrderSwap() + OrderCommission(); } if (OrderType()==OP_SELL && OrderMagicNumber() == magicsell) { profitSellOrders = profitSellOrders + OrderProfit() + OrderSwap() + OrderCommission(); } } } } // close all buy orders (for this pair) when total profit of buy orders > profit if ((profit > 0 && profitBuyOrders >= profit) || closeallbuysnow == true) { CloseAllBuyOrders(); firebuy = false; } // close all sell orders (for this pair) when total profit of sell orders > profit if ((profit > 0 && profitSellOrders >= profit) || closeallsellsnow == true) { CloseAllSellOrders(); firesell = false; } // close all orders when total profit on this pair > pairglobalprofit if ((AccountBalance() * 0.01 /pairglobalprofitEXPO)> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01 /pairglobalprofitEXPO)) { CloseAllSellOrders(); CloseAllBuyOrders(); firebuy = false; firesell = false; } // close all orders when total profit on all pairs > totalglobalprofit // or if total loss on all pairs > maximaloss double totalglobalprofit = TotalProfitOnAllPairs(); if((globalprofit > 0 && totalglobalprofit >= globalprofit) /*|| (maximaloss < 0 && totalglobalprofit <= maximaloss)*/) { GlobalVariableSet(stoptrading, 1); CloseAllOrdersOnAllPairs(); firebuy = false; firesell = false; } } //+------------------------------------------------------------------+ // GetBuyOrderCount() // returns the number of open buy orders //+------------------------------------------------------------------+ int GetBuyOrderCount() { int count=0; for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType()==OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetSellOrderCount() // returns the number of open sell orders //+------------------------------------------------------------------+ int GetSellOrderCount() { int count=0; // find all open orders of today for (int k = OrdersTotal(); k >=0 ;k--) { if (OrderSelect(k, SELECT_BY_POS)) { if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { count=count+1; } } } return count; } //+------------------------------------------------------------------+ // GetTicketOfLatestBuyOrder() // returns the ticket of the latest open buy order //+------------------------------------------------------------------+ int GetTicketOfLatestBuyOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l,SELECT_BY_POS)) { if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // GetTicketOfLatestSellOrder() // returns the ticket of the latest open sell order //+------------------------------------------------------------------+ int GetTicketOfLatestSellOrder() { double maxLots=0; int orderTicketNr=0; for (int l=OrdersTotal() - 1; l >= 0; l--) { if ( OrderSelect(l, SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { return OrderTicket(); } } } return 0; } //+------------------------------------------------------------------+ // CloseAllBuyOrders() // closes all open buy orders //+------------------------------------------------------------------+ void CloseAllBuyOrders() { for (int m=OrdersTotal(); m>=0; m--) { if ( OrderSelect(m, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success = OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue); } } } } //+------------------------------------------------------------------+ // CloseAllSellOrders() // closes all open sell orders //+------------------------------------------------------------------+ void CloseAllSellOrders() { for (int h=OrdersTotal();h>=0;h--) { if ( OrderSelect(h,SELECT_BY_POS) ) { if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } } } } //+------------------------------------------------------------------+ // CloseAllOrdersOnAllPairs() // closes all open orders on all pairs //+------------------------------------------------------------------+ void CloseAllOrdersOnAllPairs() { for (int h=OrdersTotal(); h>=0; h--) { if ( OrderSelect(h, SELECT_BY_POS) ) { if (OrderType() == OP_SELL && OrderMagicNumber() == magicsell) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red); } if (OrderType() == OP_BUY && OrderMagicNumber() == magicbuy) { RefreshRates(); bool success =OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red); } } } } //+------------------------------------------------------------------+ // TotalProfitOnAllPairs() // returns the total profit for all open orders on all pairs //+------------------------------------------------------------------+ double TotalProfitOnAllPairs() { double totalProfit = 0; for (int j=OrdersTotal();j >= 0; j--) { if( OrderSelect(j,SELECT_BY_POS)) { if (OrderMagicNumber() == magicsell || OrderMagicNumber() == magicbuy) { RefreshRates(); totalProfit = totalProfit + OrderProfit() + OrderSwap() + OrderCommission(); } } } return totalProfit; } //+------------------------------------------------------------------+ // IsNewBar() // returns if new bar has started //+------------------------------------------------------------------+ bool IsNewBar() { static datetime time = Time[0]; if(Time[0] > time) { time = Time[0]; //newbar, update time return (true); } return(false); } //-------------------------------------------------------------------------------- // TradesToday() // return total number of trades done today (closed and still open) //-------------------------------------------------------------------------------- int TradesToday() { int count=0; if (IsTesting() || IsOptimization()) return 0; // find all open orders of today for (int k = OrdersTotal();k >=0 ;k--) { if (OrderSelect(k,SELECT_BY_POS)) { if (OrderSymbol() == Symbol() ) { if(OrderLots() == Lots) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if( TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { count=count+1; } } } } } } for (int l=OrdersHistoryTotal(); l >= 0; l--) { if(OrderSelect(l, SELECT_BY_POS,MODE_HISTORY)) { if (OrderSymbol() == Symbol() ) { if (OrderMagicNumber() == magicbuy || OrderMagicNumber() == magicsell) { if(TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent())) { if(OrderLots() == Lots) { count = count + 1; } } else { return count; } } } } } return count; }
    lefeuvr3 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13727
  • stevenfoarbs

    c'est propre ! bravo ! y à plus qu'à backtester à donf..