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

Une fois n'est pas coutume...J'ai besoin de votre aide ...merci

  • lefeuvr3

    Bonjour à tous, j’aurais besoin de votre aide pour mon EA.Je voudrais envoyer quand les conditions d'achat sont remplies ,en même temps un ordre "buy" et un ordre "buystop" ,et quand les conditions de vente sont remplies ,je voudrais envoyer un ordre "sell" et un ordre "sellstop" ...cela fait un moment que je tente plusieurs méthodes pour y arriver sans succès..merci d'avance

    Code
    //+------------------------------------------------------------------+ //| BOLLINGER_COMPLET_LOOP_V1.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 <stderror.mqh> #include <stdlib.mqh> //+------------------------------------------------------------------+ //| Divergences Rsi //| Rsi Level //| Bollinger Bands //| Atr (dynamic TP-SL-TS) //| Dynamic Lots //| Spread //| Margin Level //| Pending Order //+------------------------------------------------------------------+ extern int MagicNumber=21122020; extern int atrMultipleSL=15; extern int atrMultipleTP=3; extern int atrMultipleTS=12; extern int PeriodATR=1; extern int ShiftATR=0; extern int Slippage=3; extern int shift=9; double MarginFree; // Free margin in percentage extern double MinMarginLevel = 100; // Lowest allowed Margin level for new positions to be opened. extern double LotFactor =170; //lotsize factor double lot; extern double Lowlevel=49; extern double Highlevel=84; extern int Periode=12; extern int Indicatorperiod=35; extern int BBDeviation=2; extern int barnumber =5; extern int CandlesToRetrace=15; //Num.Of Candles For Divergence extern int RSI=11; //RSI extern int volume1=1; extern int volume0=0; extern int adxperiod= 31; extern int adxthreshold=23; extern int PriceLevel=13; extern int numberpositions=0; double result1,result2,result3,result4; extern double AddPriceGap = 0; extern double martingale =0; double last_profit, last_lot; int last_tip; //+------------------------------------------------------------------+ // expert start function //+------------------------------------------------------------------+ int start() { //============================================================================ //double llots = 0.1; double llots = (AccountBalance() * 0.01 /LotFactor); if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) llots =/* Lots*/(AccountBalance() * 0.01 /LotFactor); else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit(); if( last_profit < 0 ) llots = martingale*last_lot; if( last_profit > 0 ) llots = (AccountBalance() * 0.01 /LotFactor); //============================================================================ double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*10; double TheStopLoss=0; double TheTakeProfit=0; //+------------------------------------------------------------------+ // dynamic parameters double atr = iATR(NULL, 0, PeriodATR, ShiftATR); //double StopLossPending = (atr * atrMultipleSL / Point); double StopLoss = (atr * atrMultipleSL / Point); double TakeProfit =(atr * atrMultipleTP / Point);//(atr * atrMultipleTP / Point); double TrailingStop=(atr * atrMultipleTS / Point); //+------------------------------------------------------------------+ //Calculate and check spread double MaxSpreadInPoints = 30; double Spread = Ask - Bid; if(Spread>MaxSpreadInPoints*Point) return(false); //+------------------------------------------------------------------+ double am = 0.000000001; // Set variable to a very small number double marginlevel; // Get the Free Margin MarginFree = AccountFreeMargin(); // Calculate Margin level if ( AccountMargin() != 0 ) am = AccountMargin(); marginlevel = AccountEquity() / am * 100; // Free Margin is less than the value of MinMarginLevel, so no trading is allowed if ( marginlevel < MinMarginLevel ) { Comment ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" ); Alert ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" ); return(0); } //+------------------------------------------------------------------+ if( TotalOrdersCount()<=numberpositions ) { int result=0; // Here is your open buy rule if( RSI()==1) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,0))) // Bollinger bands if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)<Lowlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)>Lowlevel))// Rsi Level //if (!IsTradeContextBusy() && IsTradeAllowed()) { result=OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,Slippage,0,0,"BOLLINGER_COMPLET",MagicNumber,0,Blue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid-StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } // Here is your open Sell rule if( RSI()==2) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,0))) if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)>Highlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)<Highlevel))//Rsi Level // if (!IsTradeContextBusy() && IsTradeAllowed()) { result=OrderSend(Symbol(),OP_SELL,NR(Lot_Volume()),Bid,Slippage,0,0,"BOLLINGER_COMPLET",MagicNumber,0,Red); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Ask-TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask+StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } // // Here is your open buy rule if( RSI()==1) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,0))) // Bollinger bands if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)<Lowlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)>Lowlevel))// Rsi Level { // if (!IsTradeContextBusy() && IsTradeAllowed()) result=OrderSend(Symbol(), OP_BUYSTOP, NR(Lot_Volume()), Ask + PriceLevel * Point, Slippage, Bid-StopLoss *Point-AddPriceGap, Bid+TakeProfit*Point+AddPriceGap, "BOLLINGER_BANDS_EA_V1", MagicNumber, 0, Blue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid-StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } if( RSI()==2) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,0))) if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)>Highlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)<Highlevel))//Rsi Level { // if (!IsTradeContextBusy() && IsTradeAllowed()) result=OrderSend(Symbol(), OP_SELLSTOP,NR(Lot_Volume()), Bid- PriceLevel * Point, Slippage, Ask+StopLoss *Point+AddPriceGap, Ask-TakeProfit*Point-AddPriceGap, "BOLLINGER_BANDS_EA_V1", MagicNumber, 0, Red); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Ask-TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask+StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } } for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if (OrderStopLoss()+ 0.5 * Point < Bid-MyPoint*TrailingStop)//+0.5 against error modify 1 { bool modif3= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); return(0); } } } } else { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if (OrderStopLoss()-0.5*Point >Ask+MyPoint*TrailingStop || (OrderStopLoss()==0))//-0.5 against error modify 1 { bool modif4= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } int TotalOrdersCount() { int result=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS ,MODE_TRADES)) if (OrderMagicNumber()==MagicNumber) result++; } return (result); } //+------------------------------------------------------------------+ //Calculates Lot Size based on balance and factor //+------------------------------------------------------------------+ double NR(double thelot) { double maxlots=MarketInfo(Symbol(),MODE_MAXLOT), minilot=MarketInfo(Symbol(),MODE_MINLOT), lstep=MarketInfo(Symbol(),MODE_LOTSTEP); double lots=lstep*NormalizeDouble(thelot/lstep,0); lots=MathMax(MathMin(maxlots,lots),minilot); return (lots); } //+------------------------------------------------------------------+ double Lot_Volume() { lot=AccountBalance() * 0.01 /LotFactor ; return(lot); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ int RSI()//Divergences Rsi { for(int i=CandlesToRetrace; i>=0; i--) { if(((iRSI(Symbol(),0,RSI,PRICE_HIGH,1)<iRSI(Symbol(),0,RSI,PRICE_HIGH,i))&& (High[1]>iHigh ( Symbol (), 0 , iHighest ( Symbol (), 0 , MODE_HIGH, barnumber , i )) )) ||((iRSI(Symbol(),0,RSI,PRICE_HIGH,1)>iRSI(Symbol(),0,RSI,PRICE_HIGH,i))&& (High[1]<iHigh ( Symbol (), 0 , iHighest ( Symbol (), 0 , MODE_HIGH, barnumber , i )) ))) { return(1); Comment("The trend is up"); } else if(((iRSI(Symbol(),0,RSI,PRICE_LOW,1)>iRSI(Symbol(),0,RSI,PRICE_TYPICAL,i))&& (Low[1]<iLow ( Symbol (), 0 , iLowest ( Symbol (), 0 , MODE_LOW, barnumber , i )))) ||((iRSI(Symbol(),0,RSI,PRICE_LOW,1)<iRSI(Symbol(),0,RSI,PRICE_LOW,i))&& (Low[1]>iLow ( Symbol (), 0 , iLowest ( Symbol (), 0 , MODE_LOW, barnumber , i ))))) { return(2); Comment("The trend is down"); } } return(0); } //+------------------------------------------------------------------+ //============================================================================ double last_history_profit() { double cpte_profit = 0; //int Magik_No = -1; if( OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY) ) { if( OrderMagicNumber() == MagicNumber ) { last_profit = OrderProfit(); last_lot = OrderLots(); last_tip = OrderType(); } } return(0); }
  • Mikiburger

    Bonjour Gérard, je regarderais demain.
    A quelle distance veux tu tes ordres stop ?
  • lefeuvr3

    Salut Miklburger
    Les parametres sont dynamiques pour le TP SL TS
    Code
    // dynamic parameters double atr = iATR(NULL, 0, PeriodATR, ShiftATR); //double StopLossPending = (atr * atrMultipleSL / Point); double StopLoss = (atr * atrMultipleSL / Point); double TakeProfit =(atr * atrMultipleTP / Point);//(atr * atrMultipleTP / Point); double TrailingStop=(atr * atrMultipleTS / Point); //----------------------------------------------- avec pour le stop loss extern int atrMultipleSL=15;

    En l'etat les resultats sont bons (avec Tickstory) mais je pense qui si tu arrives a faire cette petite manipulation ,on augmentera le nombre de trades et donc de gains
    lefeuvr3 a joint une image
    une-fois-n-est-pas-coutume-j-ai-besoin-de-votre-aide-merci-12534
  • Mikiburger

    Bonjour Gérard,

    Tu veux placer un ordre stop en même temps que ton ordre d'achat ou de vente.
    Ma question était de savoir a quelle distance tu veux mettre cet ordre stop.

    Par exemple si tu ouvre un ordre "buy", veux tu mettre ton "buystop" 10 pips au dessus ? 15 pips ? Ou veux tu simplement quelque chose de paramétrable ?
  • Mikiburger

    Je ne dois pas avoir très bien compris ta demande.

    Car pour placer ton ordre stop en même temps que ton ordre il suffit de placer la commande juste en dessous:

    Code
    if( TotalOrdersCount()<=numberpositions ) { int result=0; // Here is your open buy rule if( RSI()==1) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,0))) // Bollinger bands if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)<Lowlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)>Lowlevel))// Rsi Level //if (!IsTradeContextBusy() && IsTradeAllowed()) { result=OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,Slippage,0,0,"BOLLINGER_COMPLET",MagicNumber,0,Blue); result=OrderSend(Symbol(), OP_BUYSTOP, NR(Lot_Volume()), Ask + PriceLevel * Point, Slippage, Bid-StopLoss *Point-AddPriceGap, Bid+TakeProfit*Point+AddPriceGap, "BOLLINGER_BANDS_EA_V1", MagicNumber, 0, Blue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid-StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); }
  • Mikiburger

    Par contre en faisant tourner ton robot j'ai tout de même un truc qui me chiffonne.
    Je pense que tu modifies ton ordre beaucoup trop souvent.
    Ca ne va pas plaire au broker, il risque de bloquer ton compte.

    Il faut modérer le nombre de modification par un timer ou par un écart minimal de pips.
  • lefeuvr3

    Bonjour Milkburger ....merci pour ton intervention
    Je vais etudier la commande que tu as propose
    pour moduler le nombre de modification j'ai rajouté ou retranche 0.5....peut être que cela n'est pas suffisant
    Code
    if (OrderStopLoss()+ 0.5 * Point < Bid-MyPoint*TrailingStop) //+0.5 against error modify 1 //+------------------------------------------- if (OrderStopLoss()-0.5*Point >Ask+MyPoint*TrailingStop || (OrderStopLoss()==0))//-0.5 against error modify 1
  • lefeuvr3

    Bonjour Milkburger
    J'ai finalisé ,sur tes conseils ,le programme .
    Je le back teste et ensuite je le mets en ligne.
  • Matthieuw31

    Bonjour Lefeuvr,

    Vos backtests sur 6 mois sont intéressants. Néanmoins, je vous conseille également de faire des backtests sur des durées plus longues (2 ans est le strict minimum).
  • lefeuvr3

    Salut Matthieuw31
    Mon problème est que les backtests en Ticks prennent beaucoup de temps.
  • lefeuvr3

    Milkburger
    Voici le code avec un pending order à l'achat ou a la vente ( on peut si on le souhaite ,en mettre plusieurs,comme je l'ai fait sur une variante)
    Si tu peux trouver une solution pour avoir moins de modifications avec un timer ou un ecart minimal de pips ,je suis preneur ....sinon je m'y attèlerai

    Code
    //+------------------------------------------------------------------+ //| BOLLINGER_COMPLET_LOOP_V1.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 <stderror.mqh> #include <stdlib.mqh> //+------------------------------------------------------------------+ //| Divergences Rsi //| Rsi Level //| Bollinger Bands //| Atr (dynamic TP-SL-TS) //| Dynamic Lots //| Spread //| Margin Level //| Pending Order //+------------------------------------------------------------------+ extern int MagicNumber=21122020; extern int atrMultipleSL=5; extern int atrMultipleTP=10; extern int atrMultipleTS=9; extern int PeriodATR=1; int ShiftATR=0; extern int Slippage=3; double MarginFree; // Free margin in percentage extern double MinMarginLevel = 100; // Lowest allowed Margin level for new positions to be opened. extern double LotFactor =170; //lotsize factor double lot; extern double Lowlevel=49; extern double Highlevel=84; extern int Periode=12; extern int Indicatorperiod=35; extern int BBDeviation=2; extern int barnumber =11; extern int CandlesToRetrace=25; //Num.Of Candles For Divergence extern int RSI=21; //RSI extern int PriceLevel=41; int numberpositions=0; extern double AddPriceGap = 0; double martingale =0; double correctmodify=0.5; double last_profit, last_lot; int last_tip; //+------------------------------------------------------------------+ // expert start function //+------------------------------------------------------------------+ int start() { //============================================================================ //double llots = 0.1; double llots = (AccountBalance() * 0.01 /LotFactor); if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) llots =/* Lots*/(AccountBalance() * 0.01 /LotFactor); else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit(); if( last_profit < 0 ) llots = martingale*last_lot; if( last_profit > 0 ) llots = (AccountBalance() * 0.01 /LotFactor); //============================================================================ double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*10; double TheStopLoss=0; double TheTakeProfit=0; //+------------------------------------------------------------------+ // dynamic parameters double atr = iATR(NULL, 0, PeriodATR, ShiftATR); //double StopLossPending = (atr * atrMultipleSL / Point); double StopLoss = (atr * atrMultipleSL / Point); double TakeProfit =(atr * atrMultipleTP / Point);//(atr * atrMultipleTP / Point); double TrailingStop=(atr * atrMultipleTS / Point); //+------------------------------------------------------------------+ //Calculate and check spread double MaxSpreadInPoints = 30; double Spread = Ask - Bid; if(Spread>MaxSpreadInPoints*Point) return(false); //+------------------------------------------------------------------+ double am = 0.000000001; // Set variable to a very small number double marginlevel; // Get the Free Margin MarginFree = AccountFreeMargin(); // Calculate Margin level if ( AccountMargin() != 0 ) am = AccountMargin(); marginlevel = AccountEquity() / am * 100; // Free Margin is less than the value of MinMarginLevel, so no trading is allowed if ( marginlevel < MinMarginLevel ) { Comment ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" ); Alert ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" ); return(0); } //+------------------------------------------------------------------+ if( TotalOrdersCount()<=numberpositions ) { int result=0; // Here is your open buy rule if( RSI()==1) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_LOWER,0))) // Bollinger bands if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)<Lowlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)>Lowlevel))// Rsi Level if (!IsTradeContextBusy() && IsTradeAllowed()) { double result1=OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,Slippage,0,0,"BOLLINGER_COMPLET",MagicNumber,0,Blue); double result2=OrderSend(Symbol(), OP_BUYSTOP, NR(Lot_Volume()), Ask + PriceLevel * Point, Slippage, Bid-StopLoss *Point-AddPriceGap, Bid+TakeProfit*Point+AddPriceGap, "BOLLINGER_BANDS_EA_V1", MagicNumber, 0, Blue); if((result1>0)&&(result2>0)) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid-StopLoss*MyPoint; if((OrderSelect((int)result1,SELECT_BY_TICKET)) &&(OrderSelect((int)result2,SELECT_BY_TICKET))) bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } // Here is your open Sell rule if( RSI()==2) if((iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1)>iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,1)) &&(iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)<iBands(NULL,0,Indicatorperiod,BBDeviation,0,PRICE_OPEN,MODE_UPPER,0))) if((iRSI(NULL,0,Periode,PRICE_CLOSE,1)>Highlevel)&&(iRSI(NULL,0,Periode,PRICE_CLOSE,0)<Highlevel))//Rsi Level if (!IsTradeContextBusy() && IsTradeAllowed()) { double result3=OrderSend(Symbol(),OP_SELL,NR(Lot_Volume()),Bid,Slippage,0,0,"BOLLINGER_COMPLET",MagicNumber,0,Red); double result4=OrderSend(Symbol(), OP_SELLSTOP,NR(Lot_Volume()), Bid- PriceLevel * Point, Slippage, Ask+StopLoss *Point+AddPriceGap, Ask-TakeProfit*Point-AddPriceGap, "BOLLINGER_BANDS_EA_V1", MagicNumber, 0, Red); if((result3>0)&&(result4>0)) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Ask-TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask+StopLoss*MyPoint; if((OrderSelect((int)result3,SELECT_BY_TICKET)) &&(OrderSelect((int)result4,SELECT_BY_TICKET))) bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); } return(0); } } for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if (OrderStopLoss()+ correctmodify * Point < Bid-MyPoint*TrailingStop)//+0.5 against error modify 1 { bool modif3= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); return(0); } } } } else { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if (OrderStopLoss()-correctmodify*Point >Ask+MyPoint*TrailingStop || (OrderStopLoss()==0))//-0.5 against error modify 1 { bool modif4= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } int TotalOrdersCount() { int result=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS ,MODE_TRADES)) if (OrderMagicNumber()==MagicNumber) result++; } return (result); } //+------------------------------------------------------------------+ //Calculates Lot Size based on balance and factor //+------------------------------------------------------------------+ double NR(double thelot) { double maxlots=MarketInfo(Symbol(),MODE_MAXLOT), minilot=MarketInfo(Symbol(),MODE_MINLOT), lstep=MarketInfo(Symbol(),MODE_LOTSTEP); double lots=lstep*NormalizeDouble(thelot/lstep,0); lots=MathMax(MathMin(maxlots,lots),minilot); return (lots); } //+------------------------------------------------------------------+ double Lot_Volume() { lot=AccountBalance() * 0.01 /LotFactor ; return(lot); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ int RSI()//Divergences Rsi { for(int i=CandlesToRetrace; i>=0; i--) { if(((iRSI(Symbol(),0,RSI,PRICE_HIGH,1)<iRSI(Symbol(),0,RSI,PRICE_HIGH,i))&& (High[1]>iHigh ( Symbol (), 0 , iHighest ( Symbol (), 0 , MODE_HIGH, barnumber , i )) )) ||((iRSI(Symbol(),0,RSI,PRICE_HIGH,1)>iRSI(Symbol(),0,RSI,PRICE_HIGH,i))&& (High[1]<iHigh ( Symbol (), 0 , iHighest ( Symbol (), 0 , MODE_HIGH, barnumber , i )) ))) { return(1); Comment("The trend is up"); } else if(((iRSI(Symbol(),0,RSI,PRICE_LOW,1)>iRSI(Symbol(),0,RSI,PRICE_TYPICAL,i))&& (Low[1]<iLow ( Symbol (), 0 , iLowest ( Symbol (), 0 , MODE_LOW, barnumber , i )))) ||((iRSI(Symbol(),0,RSI,PRICE_LOW,1)<iRSI(Symbol(),0,RSI,PRICE_LOW,i))&& (Low[1]>iLow ( Symbol (), 0 , iLowest ( Symbol (), 0 , MODE_LOW, barnumber , i ))))) { return(2); Comment("The trend is down"); } } return(0); } //============================================================================ double last_history_profit() { double cpte_profit = 0; //int Magik_No = -1; if( OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY) ) { if( OrderMagicNumber() == MagicNumber ) { last_profit = OrderProfit(); last_lot = OrderLots(); last_tip = OrderType(); } } return(0); } //============================================================================
    lefeuvr3 a joint une image
    une-fois-n-est-pas-coutume-j-ai-besoin-de-votre-aide-merci-12537
  • Mikiburger

    C'est à essayer comme ça et si le broker menace de fermer le compte pour hyper activité, on peut augmenter le "correctmodify" à 5 ou 10 et il n'y aura plus de problème.

    Par contre, est-ce normal que tes ordres Sell et Buy n'ont pas de Stop gain ni de Stop loss ?

    Sinon, pour le backtest, moi je termine par deux grosses pertes qui font perdre tout les gains.
  • lefeuvr3

    Il y a un stop-loss ,un trailing stop, un take profit modulé par l' ATR
    Code
    extern int atrMultipleSL=5; extern int atrMultipleTP=10; extern int atrMultipleTS=9; extern int PeriodATR=1; int ShiftATR=0;