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

    En reel du 06.11.2021 au 02.12.2021 sur GBPUSD 1H
    lefeuvr3 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13730
  • Mikiburger

    500€ sur le mois ça peut être bien, ça dépend du capital que tu bloques pour ce robot.
    Comme c'est une martingale, le risque de perdre ton capital d'un coup est réel.
  • lefeuvr3

    Gain de 296.50 € pour 1820 €uros environ.
    Pour ne pas perdre le capital de depart ,il suffit de retirer les gains lorsque le capital a été doublé.

    D'autre part il faut faire varier les paramètres en fonction du capital Account Balance au niveau des profits et des lots ( je l'ai fait ,approximativement , a 6 niveaux différents et il faudrait que je le fasse a chaque gain supplémentaire de capital de 1000 à 5000 €uros

    Code
    extern string Parametre1="2000<->10000 **LF=364 **pairglobalprofitEXPO=3.9"; extern string Parametre2="10000<->16000 **LF=614 **pairglobalprofitEXPO=7"; extern string Parametre3="16000<->20000 **LF=800 **pairglobalprofitEXPO=8"; extern string Parametre4="20000<->50000 **LF=1050 **pairglobalprofitEXPO=10"; extern string Parametre5="50000<->100000 **LF=2000 **pairglobalprofitEXPO=20.5"; extern string Parametre6="100000<->150000 **LF=2950 **pairglobalprofitEXPO=34.5";

    Il apparait que plus le capital est important moins le gain relatif est grand ....il vaut mieux avoir plusieurs petits comptes plutot qu'un grand
    Modifié le 2021-12-07 19:47:26 par lefeuvr3 : precision
  • lefeuvr3

    Simplification du programme ,auto-adaptation au capital en utilisant MathPow.
    Capital 5000 €uros GBPUSD UT 1 Heure.
    Programme à Back tester en utilisant un historique fiable ( Tick Story)
    Toute nouvelle suggestion est bienvenue .

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-7.mq4 | //| Simplifed Version | //| 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 base=0.02; extern double exponent=1.5; extern double base1=0.2; extern double exponent1=0.84; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; 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; //+------------------------------------------------------------------+ //| 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) {} 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 ))); if( Ask <= orderPrice - S1 * Point() && buyOrderCount < S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance()* 0.01* MathPow(base,exponent)); 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 = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double R1 = (multiplcator * Pivot) - (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* MathPow(base,exponent)); 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 * MathPow(base1,exponent1))> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01* MathPow(base1,exponent1))) { 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-13739
  • Mikiburger

    Bonjour Gérard,

    Même remarque que précédemment, tu utilises un money management pour la taille de tes lots mais tu oublies de le faire pour ton lot de départ.
    J'ai changé ta ligne 82 :

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-7.mq4 | //| Simplifed Version | //| 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 base=0.02; extern double exponent=1.5; extern double base1=0.2; extern double exponent1=0.84; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; 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; //+------------------------------------------------------------------+ //| 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) {} 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= (multiplier > 0) ? NormalizeDouble(OrderLots() * multiplier, LotDigits) : (AccountBalance()* 0.01* MathPow(base,exponent));//Mikiburger 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 ))); if( Ask <= orderPrice - S1 * Point() && buyOrderCount < S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance()* 0.01* MathPow(base,exponent)); 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 = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double R1 = (multiplcator * Pivot) - (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* MathPow(base,exponent)); 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 * MathPow(base1,exponent1))> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01* MathPow(base1,exponent1))) { 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; }
  • Matthieuw31

    Bonjour,

    En effet, si on backteste en H1 il semble que l'on ait un bon résultat, par contre si on backteste, toujours en tick par tick avec l'historique M1, le capital s'effondre le 12 février 2021. Je n'utilise pas tick story ou autre mais je ne pense pas que ça change grand chose.
    Qu'en pensez-vous?
    Matthieuw31 a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13740
  • Mikiburger

    Bonjour Matthieuw31,

    C'est une martingale, ça finira tôt ou tard par s'effondrer sur une tendance trop soutenue.
    Quel que soit le timeframe ou la devise.
    Le fait que en GBPUSD H1 ne se soit pas effondré sur le backtest monte uniquement que la stratégie à bien été (sur)optimisée

    Mais il ne faut pas jeter le bébé avec l'eau du bain.
    On peut exploiter ce type de stratégie en retirant régulièrement ses gains.
    Et espérer que ceux ci dépassent la mise de départ avant l'effondrement.
  • lefeuvr3 — en réponse à Matthieuw31 dans son message #125604

    Matthieuw31
    L'utilisation de Tick Story change tout !
    Son utilisation est imperative pour obtenir un juste résultat.
    L'unité de temps optimale est l'UT 1 heure,de par la conception du programme.
    Pour ne pas perdre le capital de depart ,il suffit de retirer les gains lorsque le capital a été doublé.

    Mikiburger
    En utilisant un robot,il ne faut utiliser que le capital, que l'on est prêt à perdre dans son intégralité.
    Tu devrais publier ici le programme qui correspond a tes attentes, comme je l'ai fait maintes fois .
    Cela serait sympa pour les participants du forum.

    Bonne journée à tous

    Gerard
  • Mikiburger

    Bonjour Gérard,

    Je n'ai pas de robot qui correspond à mes attentes.
    Chaque robot a des avantages et des inconvénients.
    De manière générale, j'aime bien les robots avec martingale mais les utilisateurs doivent être conscient du risque avant de l'utiliser.
    Encore une fois, je te remercie pour tes partages et j'essaye juste de t'aider avec mes compétences limitées.
    Mais je n'ai pas de robot idéal.
  • lefeuvr3

    Mikiburger
    J'ai bien essayé ,anterieurement, mais quelques soient les parametres ,le Drawdown est trop important.
    Je te mets le programme ,si tu veux verifier par toi même.
    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-8.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 base0=0.02; extern double exponent0=1.5; extern double base=0.02; extern double exponent=1.5; extern double base1=0.21; extern double exponent1=0.84; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; 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; //+------------------------------------------------------------------+ //| 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) {} 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 = (AccountBalance()* 0.01* MathPow(base0,exponent0)); 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 ))); if( Ask <= orderPrice - S1 * Point() && buyOrderCount < S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance()* 0.01* MathPow(base,exponent)); 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 = (((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) + (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 ))) + Close[nb]) / 3); double R1 = (multiplcator * Pivot) - (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* MathPow(base,exponent)); 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 * MathPow(base1,exponent1))> 0 && (profitBuyOrders + profitSellOrders) >= (AccountBalance() * 0.01* MathPow(base1,exponent1))) { 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; }
  • Mikiburger

    Bonjour Gérard,

    J'ai une idée à essayer mais je n'ai pas encore eu le temps de la programmer.

    Sinon j'ai essayé de voir les performances de ton programme V7 en achat et en vente de manière individuelle.
    C'est étrange car si je sélectionne "Long & Short" ou "Long only" ça fonctionne mais si je sélectionne "Short only" il n'y a aucun trade qui s'effectue.
    Pourtant dans l'option "Long & Short", les trades Shorts se font correctement.

    Mon but était de vérifier que les deux sens de trade étaient bien indépendants mais apparemment ce n'est pas le cas.

    Je ne vois pas ce qui coince dans le programme. Peux tu regarder ?
    Mikiburger a joint une image
    ea-base-sur-les-points-pivots-mq4-a-developper-et-depoussierer-13741
  • lefeuvr3

    Mikiburger
    On a une erreur 4110
    L'EA est programmé pour ouvrir des ordres d'achat et de vente en même temps.
    C'est une condition importante de son travail.
    On ne peut donc pas trader dans un sens.
  • Mikiburger

    J'ai lancé le robot en forward testing sur compte démo.
    Cette semaine: gain d'un peu plus de 3%.
    Je continue à penser que le robot est dangereux pour le compte tel quel.
    Mais c'est tout de même intéressant.
  • Mikiburger

    Pas de fermeture de position cette semaine donc pas de gain mais on est sur une perte latente de 500€ sur les positions ouvertes
  • Mikiburger

    Tient c'est étrange mais le robot s'était enlevé du graphe.
    Pas la première fois que ça m'arrive, c'est peut être pour ça qu'il n'y a pas eu de fermeture d'ordres.

    A mon avis il y a dû avoir un soucis quand j'ai redémarré mon VPS pour une mise à jour.
  • lefeuvr3

    Variante avec modulation des plages horaires pour le lancement des trades et pour leurs fermetures....cela diminue encore la chute maximale.
    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1 Heure total planifié.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1 Heure plage horaire.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=424;//*** Lots extern int multiplcator=103;//*** Mutiplicator extern double pairglobalprofitEXPO= 2.7;//*** Exponentiel double Lot1Factor=130; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern string __TRADING_HOURS_LIMIT_____; extern int iStartTradingHour = 12; extern int iEndTradingHour = 0; extern string __TRADING_HOURS_LIMIT_CLOSE_____; extern int iStartTradingCloseHour = 15; extern int iEndTradingCloseHour = 23; 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; 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; //+------------------------------------------------------------------+ //| 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 (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) return; { if (GlobalVariableGet(stoptrading)==0) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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 (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) return; { 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) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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) // if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) return; { // open 1st sell order if ( GlobalVariableGet(stoptrading) == 0 ) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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 (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) return; { 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) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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) if (Hour() >= iStartTradingHour || Hour() <= iEndTradingHour) { 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)) if (Hour() >= iStartTradingCloseHour || Hour() <= iEndTradingCloseHour) { 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-13803
  • Mikiburger

    Je fais toujours tourner une version antérieure en forward testing sur compte démo.
    La semaine dernière j'ai eu un gain de 143€ et cette semaine 358€ avec 0,10 lot de départ.

    Je vais regarder cette nouvelle version. Merci pour le travail
Page 3