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

  • stevenfoarbs

    je n'ai pas eu encore l'occasion de me mettre vraiment dans le code mais quelle est la stratégie exactement ? c'est basé sur les points pivots mais après ? buy si c'est au dessus du point pivot et inversement ? pourrait-on en savoir plus ?
    Merci
  • Mikiburger

    Bonjour Lefeuvr3,

    J'ai un peu de temps pour jeter un œil à ton programme. J'aurais quelques remarques.

    Remarque 1:
    N'as tu pas inversé tes ordres par rapport au CCI ?
    Par exemple, tu passes un ordre BUY quand le CCI > 100.
    Alors que en théorie un CCI > 100 est un signal de surachat et donc en général on préconise plutôt un ordre SELL.
    (Et inversément pour le CCI < -100)

    D'ailleurs le backtest donne un meilleur gain suivant cette règle.
  • Mikiburger

    Remarque 2:
    Toujours selon la bonne pratique du CCI, un ordre SELL ne se place pas exactement quand CCI dépasse les 100 mais plutôt quand le CCI revient dans les bornes après avoir dépassé les 100.
    (et inversément pour le BUY et le CCI<-100)

    Le backtest est également meilleur selon cette règle, avec une chute plus faible.
  • Mikiburger

    Remarque 3:
    Pourquoi avoir placé le calcul de la volatilité dans la condition de signal SELL ?
    Il aurait été plus logique de la calculer en amont du programme.
    Sinon le signal BUY se base sur le calcul de la volatilité au moment du dernier signal SELL.
    Mais de toutes façons, le résultat est meilleur sans ce filtre de volatilité.
    Pourquoi l'avoir mit ?
  • Mikiburger

    Remarque 4:
    Il y a un problème dans ta gestion de lots.
    Le premier ordre est à 0,01 lot puis tu passes direct à 0,20 lots, puis 0,34 lots...

    Les 4 lignes (identiques) suivantes:
    double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot1Factor);
    sont à changer avec:
    double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * Lots*0.1 /LotFactor);
  • lefeuvr3

    Mikburger ,je vais revoir le programme en tenant compte de tes observations
    Merci
    Bon weekend
    Gerard
  • lefeuvr3

    Résultat compte de trading réel de puis le 06.11.2021,avec l'utilisation du CCI et des points pivots sur GBPUSD 1 heure
    https://urlz.fr/gOSZ
  • Mikiburger

    Merci Lefeuvr3, c'est très motivant de voir des résultats de comptes réels.
    Avec quel taille de lot tu commences ?
    As tu peux regarder à mes remarques pour ton programme ?
  • lefeuvr3 — en réponse à Mikiburger dans son message #125508

    Salut Mikiburger
    Je commence toujours par 0.01 lot
    Je me suis penché sur tes remarques et le mieux que je puisse obtenir est le programme qui suit
    La taille des lots augmente avec la taille du capital ( en faisant varier le LotFactor et le Lot1Factor ) et j'ai réduit l'utilisation du CCI
    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1 Heure.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=380; extern double Lot1Factor=130; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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; extern int StopLossB1 =0; extern int StopLossB2 =0; extern int StopLossB3 =0; extern int StopLossS1 =0; extern int StopLossS2 =0; extern int StopLossS3 =0; //+------------------------------------------------------------------+ //| 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, StopLossB1, 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, StopLossB2, 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, StopLossB3, 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, StopLossS1, 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, StopLossS2, 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, StopLossS3, 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 signaler que les points pivots sont atypiques et peu communs :)
    Après quelques recherches ,c'est ceux que j'ai mis au point et que je trouve être les plus performants .
    Bonne journée
    Gerard
  • Mikiburger

    Bonjour Lefeuvr3,
    Je ne comprend vraiment pas ta gestion des lots.
    Dans ta dernière version, le premier trade se fait toujours à 0.01 lot et les suivants sont fonctions du capital.
    Et il n'y a plus de martingale, tout les trades suivant sont du même volume (en fonction du capital). Mais c'est peut être voulu de ta part.

    Voici ton programme avec le premier trade qui est aussi fonction du capital:

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1 Heure.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=380; extern double Lot1Factor=130; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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; extern int StopLossB1 =0; extern int StopLossB2 =0; extern int StopLossB3 =0; extern int StopLossS1 =0; extern int StopLossS2 =0; extern int StopLossS3 =0; //+------------------------------------------------------------------+ //| 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; double orderLots = OrderLots();// Mikiburger add double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits);// Mikiburger add double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); // Mikiburger add 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, StopLossB1, 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, StopLossB2, 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, StopLossB3, 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, StopLossS1, 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, StopLossS2, 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, StopLossS3, 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

    En effet j'ai essayé de mettre d'autres lots de taille différente à differents niveaux etagés mais cela n'apporte rien de plus .
    CF exemple
    Code
    // 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 : spaceLots; 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 : space1Lots; index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - space2Pips * Point() && buyOrderCount <= (space2Orders + space1Orders + spaceOrders-1) && buyOrderCount > (spaceOrders + space1Orders-1)) { double lots= (multiplier > 0) ? nextMultiplierLotSize : space2Lots; index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } else if( Ask <= orderPrice - space3Pips * Point() && buyOrderCount <= (space3Orders + space2Orders + space1Orders + spaceOrders) && buyOrderCount > (spaceOrders + space1Orders + space2Orders-1)) { double lots= (multiplier > 0) ? nextMultiplierLotSize : space3Lots; index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, 0, 0, buycomment, magicbuy, 0, Blue); } } }

    Il faudra peut être que je reesaye pour voir !
  • lefeuvr3

    J'ai modifié légèrement le programme de tel manière que l'on puisse si on le désire utiliser, ou pas ,un TrailingStop ou un palier supplémentaire pour Résistance ou Soutien de points pivots.....mais je ne pense pas que cela soit vraiment un plus ... je vous laisse le soin de faire votre propre idée.

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-2.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=380; extern double Lot1Factor=130; extern double Lot2Factor=350; double Lots = 0.01; extern bool trail= false; extern int TrailingStop =10; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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; extern int StopLossB1 =0; extern int StopLossB2 =0; extern int StopLossB3 =0; extern int StopLossB4 =0; extern int StopLossS1 =0; extern int StopLossS2 =0; extern int StopLossS3 =0; extern int StopLossS4 =0; extern bool steps= false; //+------------------------------------------------------------------+ //| 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, StopLossB1, 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 Range =((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); 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 S3 =(S1)- ((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 )))); double R3 =(R1) + (((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, StopLossB2, 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, StopLossB3, 0, buycomment, magicbuy, 0, Blue); } else if (steps) { if( Ask <= orderPrice - S3 * Point() && buyOrderCount <= (S1 + S2 + S3 -1) && buyOrderCount >= S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot2Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, StopLossB4, 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, StopLossS1, 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 Range =((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); 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 S3 =(S1)- ((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 )))); double R3 =(R1) + (((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, StopLossS2, 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, StopLossS3, 0, sellcomment, magicsell, 0, Red); } else if (steps) { if( Bid >= orderPrice + R3 * Point() && sellOrderCount <= (R1 + R2 + R3 - 1) && sellOrderCount >= R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot2Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, StopLossS4, 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(); } } } } ///+------------------------------------------------------------------+ if (trail) { //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() + (TrailingStop*_Point)) bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),Ask - (TrailingStop*_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() - (TrailingStop*_Point)) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),Bid + (TrailingStop*_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; } // 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

    J'ai constaté une petite erreur de programmation sur le trailing stop :(
    Je l'ai corrigée et je mets le programme modifié.
    Il ne reste plus qu' à backtester :)

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-2.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=380; extern double Lot1Factor=130; extern double Lot2Factor=350; double Lots = 0.01; extern bool trail= true; extern int TrailingStop =20; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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 StopLossB1 =0; extern int StopLossB2 =0; extern int StopLossB3 =0; extern int StopLossB4 =0; extern int StopLossS1 =0; extern int StopLossS2 =0; extern int StopLossS3 =0; extern int StopLossS4 =0; extern bool steps= true; extern int MagicNumber=10001; extern int MyPoint=7; //+------------------------------------------------------------------+ //| 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, StopLossB1, 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 Range =((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); 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 S3 =(S1)- ((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 )))); double R3 =(R1) + (((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, StopLossB2, 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, StopLossB3, 0, buycomment, magicbuy, 0, Blue); } else if (steps) { if( Ask <= orderPrice - S3 * Point() && buyOrderCount <= (S1 + S2 + S3 -1) && buyOrderCount >= S1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot2Factor); index = OrderSend (Symbol(), OP_BUY, lots, Ask, 3, StopLossB4, 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, StopLossS1, 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 Range =((iHigh ( Symbol (), Periode , iHighest ( Symbol (), Periode , MODE_HIGH, barnumber , 1 ))) - (iLow ( Symbol (), Periode , iLowest ( Symbol (), Periode , MODE_LOW, barnumber , 1 )))); 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 S3 =(S1)- ((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 )))); double R3 =(R1) + (((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, StopLossS2, 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, StopLossS3, 0, sellcomment, magicsell, 0, Red); } else if (steps) { if( Bid >= orderPrice + R3 * Point() && sellOrderCount <= (R1 + R2 + R3 - 1) && sellOrderCount >= R1) { double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /Lot2Factor); index = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, StopLossS4, 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(); } } } } ///+------------------------------------------------------------------+ ///+------------------------------------------------------------------+ if (trail) { for(int cnt=0;cnt<OrdersTotal();cnt++) { if( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if(OrderStopLoss()+Point<Bid-MyPoint*TrailingStop) { bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); } } } } else { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if((OrderStopLoss()-Point>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0)) { bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red); } } } } } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // 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-11-22 10:45:12 par lefeuvr3 : orthographe
  • lefeuvr3

    Version simplifiée

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-5.mq4 | //| Simplified 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 LotFactor=364; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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; //+------------------------------------------------------------------+ //| 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 /LotFactor); 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 /LotFactor); 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; }
  • Mikiburger

    Bonjour Gérard,

    Dans ta dernière version, il y a ton premier trade qui est toujours étrangement à 0,01 lot.
    Voici ton programme corrigé:

    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-5.mq4 | //| Simplified 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 LotFactor=364; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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; //+------------------------------------------------------------------+ //| 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) { double orderLots = OrderLots(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(),OP_BUY, lots , 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 /LotFactor); 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 ) { double orderLots = OrderLots(); double nextMultiplierLotSize = NormalizeDouble(orderLots * multiplier, LotDigits); double lots= (multiplier > 0) ? nextMultiplierLotSize : (AccountBalance() * 0.01 /LotFactor); index = OrderSend (Symbol(), OP_SELL, lots, 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 /LotFactor); 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

    Salut Mikiburger
    J'ai essayé de faire varier la taille du premier lot mais ,je n'ai rien obtenu de positif ....si tu as une idée ,je suis preneur !
  • Mikiburger

    Bonjour Gérard,

    C'est le principe même de la stratégie, si tu rentres avec un premier trade de taille de lot ridicule par rapport aux suivant selon une grille, c'est que ton paramètre d'entrée n'est pas bon. Voir même systématiquement dans le mauvais sens (cf mes messages précédents).
    En principe le premier trade doit avoir un pourcentage de réussite important sans compter sur les trades suivants qui sont là pour récupérer la sauce.
    Dans ta stratégie le premier trade est à 0,01 lot et les suivant sont fonction de ton capital, donc facilement du 0,20 ou 040 lot. Où est la logique là dedans ? Si ton premier trade est directement gagnant, tu vas gagner beaucoup moins que si il devient perdant et que les suivants viennent compléter.
    Donc ton optimisation fait en sorte que ta stratégie aie un pourcentage de réussite de premier trade très faible.
  • lefeuvr3

    Bonjour Mikiburger
    J'ai mis une petite strategie pour le point d'entrée et je permets à la taille des lots de grandir en fonction du capital.( mais je trouve que cela augmente beaucoup le DrawDown )
    Si tu as une meilleur idée, n'hésite pas a refaire le programme en l'incluant. ta version.
    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1-Heure-Version-6.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 LotFactor=400; extern double LotFactorFirst =1900; double Lots = 0.01; double multiplier = 0; double profit = 0; double globalprofit = 0; extern double pairglobalprofitEXPO= 3.9;//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 Period="M1=1**M5=5**M15=15**M30=30**H1=60**H4=240**D1=1440**W1=10080**MN=43200"; extern int Periode=1440; extern bool PERIOD_M1=true; extern bool PERIOD_M5=true; extern bool PERIOD_M15=true; extern bool PERIOD_M30=true; extern bool PERIOD_H1=true; extern bool PERIOD_H4=true; extern bool PERIOD_D1=true; extern bool PERIOD_W1=true; //+------------------------------------------------------------------+ //| 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) //+------------------------------------------------------------------+ //| Starting strategy buy to open 1st buy order | //+------------------------------------------------------------------+ if ((iClose(Symbol(),PERIOD_M1,0)>(iClose(Symbol(),PERIOD_M1,1)))) if ((iClose(Symbol(),PERIOD_M5,0)>(iClose(Symbol(),PERIOD_M5,1)))) if ((iClose(Symbol(),PERIOD_M15,0)>(iClose(Symbol(),PERIOD_M15,1)))) if ((iClose(Symbol(),PERIOD_M30,0)>(iClose(Symbol(),PERIOD_M30,1)))) if ((iClose(Symbol(),PERIOD_H1,0)>(iClose(Symbol(),PERIOD_M1,1)))) if ((iClose(Symbol(),PERIOD_H4,0)>(iClose(Symbol(),PERIOD_M5,1)))) if ((iClose(Symbol(),PERIOD_D1,0)>(iClose(Symbol(),PERIOD_M15,1)))) if ((iClose(Symbol(),PERIOD_W1,0)>(iClose(Symbol(),PERIOD_M30,1)))) //+------------------------------------------------------------------+ { index = OrderSend (Symbol(),OP_BUY, /*GetLotSize()*/(AccountBalance() * 0.01 /LotFactorFirst) , 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 /LotFactor); 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 ) //+------------------------------------------------------------------+ //| Starting strategy sell to open 1st sell order //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ if ((iClose(Symbol(),PERIOD_M1,0)<(iClose(Symbol(),PERIOD_M1,1)))) if ((iClose(Symbol(),PERIOD_M5,0)<(iClose(Symbol(),PERIOD_M5,1)))) if ((iClose(Symbol(),PERIOD_M15,0)<(iClose(Symbol(),PERIOD_M15,1)))) if ((iClose(Symbol(),PERIOD_M30,0)<(iClose(Symbol(),PERIOD_M30,1)))) if ((iClose(Symbol(),PERIOD_H1,0)<(iClose(Symbol(),PERIOD_M1,1)))) if ((iClose(Symbol(),PERIOD_H4,0)<(iClose(Symbol(),PERIOD_M5,1)))) if ((iClose(Symbol(),PERIOD_D1,0)<(iClose(Symbol(),PERIOD_M15,1)))) if ((iClose(Symbol(),PERIOD_W1,0)<(iClose(Symbol(),PERIOD_M30,1)))) //+------------------------------------------------------------------+ { index = OrderSend (Symbol(), OP_SELL,/* GetLotSize()*/(AccountBalance() * 0.01 /LotFactorFirst), 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 /LotFactor); 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-13729
  • lefeuvr3

    Pour le moment ,je continue à laisser tourner en Réel ma version
    Code
    //+------------------------------------------------------------------+ //| Points-Pivots-Lefeuvre-GBPUSD-1 Heure.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+
    qui me donne de bons résultats...cf fichier ci dessous

    Modifié le 2021-12-02 13:36:15 par lefeuvr3