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

Cherche aide pour améliorer EA supertrend

  • tonyclub33

    Bonjour a tous,

    Au vu que je ne comprend rien en programmations Mql4, je souhaiterai Qu’une personne puise m'aidez a améliorer un Ea bassé sur supertrend
    Je souhaiterai simplement rajouter 2 choses
    1- Un trailing stop avec des paliers
    2-Que l'ea commence a prendre des position entre une tranche horaire. (ouverture 6h et arrêts de prendre des positions 12h)
    Voici le code de l'ea
    Code
    extern string _tmp0_=" --- Trade settings ---"; extern double TotalLots=0.3; extern int StopLoss=30; extern int TakeProfit1=0; extern int MovetoBE=0; extern int MagicNumber = 623456; extern string EA_Comments="SuperTrend EA"; extern string _tmp1_=" --- Supertrend settings ---"; extern int Nbr_Period1 = 106; extern int Nbr_Period2 = 106; extern int Nbr_Period3 = 106; extern int Nbr_Period4 = 106; extern double Multiplier = 2.7; double points; int per = 0; double green[4], prevgreen[4], red[4], prevred[4]; bool bMovetoBE = false; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if (Digits==3 || Digits==5) points = Point*10; else points = Point; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- double CurrProfit; if ( per!=Time[0] ) { green[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 0, 1 ); green[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 0, 1 ); green[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 0, 1 ); green[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 0, 1 ); prevgreen[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 0, 2 ); prevgreen[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 0, 2 ); prevgreen[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 0, 2 ); prevgreen[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 0, 2 ); red[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 1, 1 ); red[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 1, 1 ); red[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 1, 1 ); red[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 1, 1 ); prevred[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 1, 2 ); prevred[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 1, 2 ); prevred[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 1, 2 ); prevred[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 1, 2 ); // Let's zero out any empty values for( int i=0; i< 4; i++) { if( green[i] == EMPTY_VALUE ) green[i] = 0; if( red[i] == EMPTY_VALUE ) red[i] = 0; if( prevgreen[i] == EMPTY_VALUE ) prevgreen[i] = 0; if( prevred[i] == EMPTY_VALUE ) prevred[i] = 0; } Print( "green values ", green[0]," ", green[1]," ", green[2]," ",green[3] ); Print( "prev green values ", prevgreen[0]," ", prevgreen[1]," ", prevgreen[2]," ",prevgreen[3] ); Print( "red values ", red[0]," ", red[1]," ", red[2]," ",red[3] ); Print( "prev red values ", prevred[0]," ", prevred[1]," ", prevred[2]," ",prevred[3] ); } if ( WorkingOrder() ) { if ( OrderType() == OP_BUY ) { if ( red[0] > 0 || red[1] > 0 || red[2] > 0 || red[3] > 0 ) { // Close order since change in direction OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue); bMovetoBE = false; } CurrProfit = (Bid/points) - (OrderOpenPrice()/points); if ( OrderLots() == TotalLots && TakeProfit1 > 0 ) { if ( CurrProfit > TakeProfit1 ) OrderClose(OrderTicket(),(OrderLots()/2),Bid,3,Blue); } else if ( !bMovetoBE && MovetoBE > 0 && CurrProfit > MovetoBE ) { if (OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice(),0,0,Blue)) bMovetoBE = true; } } else if ( OrderType() == OP_SELL ) { if ( green[0] > 0 || green[1] > 0 || green[2] > 0 || green[3] > 0 ) { // Close order since change in direction OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); bMovetoBE = false; } CurrProfit= (OrderOpenPrice()/points) - (Ask/points); if ( OrderLots() == TotalLots && TakeProfit1 > 0 ) { if ( CurrProfit > TakeProfit1 ) OrderClose(OrderTicket(),(OrderLots()/2),Ask,3,Blue); }else if ( !bMovetoBE && MovetoBE > 0 && CurrProfit > MovetoBE ) { if (OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice(),0,0,Red)) bMovetoBE = true; } } } else if ( per!=Time[0] ) { //Let's see if we should open any trades if ( (green[0] > 0 && green[1] > 0 && green[2] > 0 && green[3] > 0) && (prevred[0] > 0 || prevred[1] > 0 || prevred[2] > 0 || prevred[3] > 0) ) { if ( OpenBuy() ) bMovetoBE = false; } else if ( (red[0] > 0 && red[1] > 0 && red[2] > 0 && red[3] > 0) && (prevgreen[0] > 0 || prevgreen[1] > 0 || prevgreen[2] > 0 || prevgreen[3] > 0) ) { if ( OpenSell() ) bMovetoBE = false; } } per = Time[0]; //---- return(0); } //+------------------------------------------------------------------+ // WorkingOrder - Check to see if any orders are opened | //+------------------------------------------------------------------+ bool WorkingOrder() { int total = OrdersTotal(); for(int cnt = 0; cnt < total; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber)) return(true); } return (false); } //+------------------------------------------------------------------+ //| OpenBuy/OpenSell() - initiate buy and sell functions | //+------------------------------------------------------------------+ bool OpenBuy() { int ticket = OrderSend(Symbol(),OP_BUY,TotalLots,Ask,3,0,0,EA_Comments,MagicNumber,0,Blue); if( ticket < 1 ) { return(false); } OrderSelect(ticket, SELECT_BY_TICKET); double order_price = OrderOpenPrice(); OrderModify(ticket, order_price,(order_price-(points*StopLoss)),0,0,Blue); Print("Buy has been opened at ",order_price ); return(true); } bool OpenSell() { int ticket = OrderSend(Symbol(),OP_SELL,TotalLots,Bid,3,0,0,EA_Comments,MagicNumber,0,Red); if( ticket < 1 ) { return(false); } OrderSelect(ticket, SELECT_BY_TICKET); double order_price = OrderOpenPrice(); OrderModify(ticket, order_price,(order_price+(points*StopLoss)),0,0,Red); Print("Sell has been opened at ",order_price ); return(true); } //+------------------------------------------------------------------+

    Merci par avance
  • Altore — en réponse à tonyclub33 dans son message #70913

    bonsoir tonyclub33

    pourrai tu mettre le programme de l'indicateur ,je vais voir ce que je peux faire
  • tonyclub33

    Bonjour Altore
    Super si tu peut faire quelque chose
    Voici le code de supertrend
    Code
    //+------------------------------------------------------------------+ //| SuperTrend.mq4 v1.2 | //| Copyright © 2008, Jason Robinson (jnrtrading). | //| http://www.spreadtrade2win.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Jason Robinson." #property link "http://www.spreadtrade2win.com" #property indicator_chart_window #property indicator_color1 Lime #property indicator_color2 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_buffers 2 double TrendUp[], TrendDown[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0, TrendUp); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(0, "Trend Up"); SetIndexBuffer(1, TrendDown); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(1, "Trend Down"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- for (i = Bars; i >= 0; i--) { TrendUp[i] = EMPTY_VALUE; TrendDown[i] = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr[i]); medianPrice = (High[i]+Low[i])/2; //Print("medianPrice: "+medianPrice[i]); up[i]=medianPrice+(Multiplier*atr); //Print("up: "+up[i]); dn[i]=medianPrice-(Multiplier*atr); //Print("dn: "+dn[i]); trend[i]=1; if (Close[i]>up[i+1]) { trend[i]=1; if (trend[i+1] == -1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (Close[i]<dn[i+1]) { trend[i]=-1; if (trend[i+1] == 1) changeOfTrend = 1; //Print("trend: "+trend[i]); } else if (trend[i+1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i+1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i+1]>0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend[i]>0 && trend[i+1]<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend[i]>0 && dn[i]<dn[i+1]) dn[i]=dn[i+1]; if (trend[i]<0 && up[i]>up[i+1]) up[i]=up[i+1]; if (flag==1) up[i]=medianPrice+(Multiplier*atr); if (flagh==1) dn[i]=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; changeOfTrend = 0; } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+
  • Altore — en réponse à tonyclub33 dans son message #70964

    bonsoir tonyclub
    pour les heures c'est OK, pour le traling stop il me faut un peu plus de temps, enfin si j'y arrive...
    a moin que quelqu'un apporte la solution

    si tu veux deja la modif avec les heures?
    comment on fais pour poster le programme sans que les carracteres des codes soit deformé? il y a une fonction sur le forum?
  • tonyclub33

    Cool c'est déjà pas mal !
    Oui je vais tester pour cela Tu poste un nouveaux message et en haut à droite tu as les balises bbcodes et tu vas tomber sur [ code ] à placer en début et à la fin [ / code ] sans les espaces
    Encore merci
    Modifié le 2013-02-25 21:01:25 par tonyclub33
  • Altore

    voila le programme avec le rajout des heures de trading

    Code
    extern string _tmp0_=" --- Trade settings ---"; extern double TotalLots=0.3; extern int StopLoss=30; extern int TakeProfit1=0; extern int MovetoBE=0; extern int MagicNumber = 623456; extern string EA_Comments="SuperTrend EA"; extern string _tmp1_=" --- Supertrend settings ---"; extern int Nbr_Period1 = 106; extern int Nbr_Period2 = 106; extern int Nbr_Period3 = 106; extern int Nbr_Period4 = 106; extern double Multiplier = 2.7; extern string Temps = "Heure Francaise"; extern int Demarrage_Heure_EA = 6; extern int Arret_Heure_EA = 12; double points; int per = 0; double green[4], prevgreen[4], red[4], prevred[4]; bool bMovetoBE = false; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if (Digits==3 || Digits==5) points = Point*10; else points = Point; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- double CurrProfit; if ( per!=Time[0] ) { green[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 0, 1 ); green[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 0, 1 ); green[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 0, 1 ); green[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 0, 1 ); prevgreen[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 0, 2 ); prevgreen[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 0, 2 ); prevgreen[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 0, 2 ); prevgreen[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 0, 2 ); red[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 1, 1 ); red[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 1, 1 ); red[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 1, 1 ); red[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 1, 1 ); prevred[0] = iCustom( 0, 0, "SuperTrend", Nbr_Period1, Multiplier, 1, 2 ); prevred[1] = iCustom( 0, 0, "SuperTrend", Nbr_Period2, Multiplier, 1, 2 ); prevred[2] = iCustom( 0, 0, "SuperTrend", Nbr_Period3, Multiplier, 1, 2 ); prevred[3] = iCustom( 0, 0, "SuperTrend", Nbr_Period4, Multiplier, 1, 2 ); // Let's zero out any empty values for( int i=0; i< 4; i++) { if( green[i] == EMPTY_VALUE ) green[i] = 0; if( red[i] == EMPTY_VALUE ) red[i] = 0; if( prevgreen[i] == EMPTY_VALUE ) prevgreen[i] = 0; if( prevred[i] == EMPTY_VALUE ) prevred[i] = 0; } Print( "green values ", green[0]," ", green[1]," ", green[2]," ",green[3] ); Print( "prev green values ", prevgreen[0]," ", prevgreen[1]," ", prevgreen[2]," ",prevgreen[3] ); Print( "red values ", red[0]," ", red[1]," ", red[2]," ",red[3] ); Print( "prev red values ", prevred[0]," ", prevred[1]," ", prevred[2]," ",prevred[3] ); } if ( WorkingOrder() ) { if ( OrderType() == OP_BUY ) { if ( red[0] > 0 || red[1] > 0 || red[2] > 0 || red[3] > 0 ) { // Close order since change in direction OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue); bMovetoBE = false; } CurrProfit = (Bid/points) - (OrderOpenPrice()/points); if ( OrderLots() == TotalLots && TakeProfit1 > 0 ) { if ( CurrProfit > TakeProfit1 ) OrderClose(OrderTicket(),(OrderLots()/2),Bid,3,Blue); } else if ( !bMovetoBE && MovetoBE > 0 && CurrProfit > MovetoBE ) { if (OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice(),0,0,Blue)) bMovetoBE = true; } } else if ( OrderType() == OP_SELL ) { if ( green[0] > 0 || green[1] > 0 || green[2] > 0 || green[3] > 0 ) { // Close order since change in direction OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); bMovetoBE = false; } CurrProfit= (OrderOpenPrice()/points) - (Ask/points); if ( OrderLots() == TotalLots && TakeProfit1 > 0 ) { if ( CurrProfit > TakeProfit1 ) OrderClose(OrderTicket(),(OrderLots()/2),Ask,3,Blue); }else if ( !bMovetoBE && MovetoBE > 0 && CurrProfit > MovetoBE ) { if (OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice(),0,0,Red)) bMovetoBE = true; } } } else if ( per!=Time[0] ) { //Let's see if we should open any trades if (Hour ()> Demarrage_Heure_EA-2 && Hour () < Arret_Heure_EA-1) if ( (green[0] > 0 && green[1] > 0 && green[2] > 0 && green[3] > 0) && (prevred[0] > 0 || prevred[1] > 0 || prevred[2] > 0 || prevred[3] > 0) ) { if ( OpenBuy() ) bMovetoBE = false; } else if (Hour ()> Demarrage_Heure_EA-2 && Hour () < Arret_Heure_EA-1) if ( (red[0] > 0 && red[1] > 0 && red[2] > 0 && red[3] > 0) && (prevgreen[0] > 0 || prevgreen[1] > 0 || prevgreen[2] > 0 || prevgreen[3] > 0) ) { if ( OpenSell() ) bMovetoBE = false; } } per = Time[0]; //---- return(0); } //+------------------------------------------------------------------+ // WorkingOrder - Check to see if any orders are opened | //+------------------------------------------------------------------+ bool WorkingOrder() { int total = OrdersTotal(); for(int cnt = 0; cnt < total; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber)) return(true); } return (false); } //+------------------------------------------------------------------+ //| OpenBuy/OpenSell() - initiate buy and sell functions | //+------------------------------------------------------------------+ bool OpenBuy() { int ticket = OrderSend(Symbol(),OP_BUY,TotalLots,Ask,3,0,0,EA_Comments,MagicNumber,0,Blue); if( ticket < 1 ) { return(false); } OrderSelect(ticket, SELECT_BY_TICKET); double order_price = OrderOpenPrice(); OrderModify(ticket, order_price,(order_price-(points*StopLoss)),0,0,Blue); Print("Buy has been opened at ",order_price ); return(true); } bool OpenSell() { int ticket = OrderSend(Symbol(),OP_SELL,TotalLots,Bid,3,0,0,EA_Comments,MagicNumber,0,Red); if( ticket < 1 ) { return(false); } OrderSelect(ticket, SELECT_BY_TICKET); double order_price = OrderOpenPrice(); OrderModify(ticket, order_price,(order_price+(points*StopLoss)),0,0,Red); Print("Sell has been opened at ",order_price ); return(true); } //+------------------------------------------------------------------+
    Modifié le 2013-02-26 12:53:21 par AliX
  • tonyclub33

    Super, si tu as le temps ou quelqu’un d'autre pourrai rajouter le traling stop avec 1 palier (2 serai bien)
    encore merci Je viens de faire backtest sur eur/jpy et déjà c'est beaucoup mieux
  • tonyclub33

    Voici 1er backtest sur eur/jpy en M5 du 1er janvier2013 au 26fevrier 2013
    De 7h a 14h Et avec un risque 10%
    Il manque plus que trailing stop avec palier
    Modifié le 2013-02-26 12:38:07 par tonyclub33
    tonyclub33 a joint une image
    cherche-aide-pour-ameliorer-ea-supertrend-6930
  • Altore

    bonsoir tonyclub
    je viens de t'envoyé par mail l'EA avec le rajout des heures de trading active et le trailing stop

    mais sinon c'est quoi le trailling stop avec palier?
  • tonyclub33

    C'est un stop suiveur qui se déclenche au bout de par ex +10 pips, puis va progresser.
    Je tes envoyer par mail un stop suiveur, si tu peux l’insérer.
  • tonyclub33

    Cherche quelqu'un pour l’amélioré l'ea ! Une idée, un truc suplémentaire ? Depuis hier en version test réel !
    +37 pips hier , aujourd’hui +22 pips pour l'instant !
  • tomyamkhung

    un trailling stop immédiat ou un trailling stop activé après breakeven ?
  • tonyclub33

    Oui tout a fait dans le style après un breakeven, pour cela je pensé avoir au moins 2 paramètre breakeven .
    Suivre un gros mouvement comme lundi ! Idéal
  • greg3395

    tonyclub33 laisse tombée pour un EA Super_Trend
    j'ai tout essayé l'étè dernier et j'ai laissée tomber 3 mois plus tard.

    les backtest n'as jamais était concluant.
    même en mettant des SL a zéro rapidement, stop suiveur , pyramider ou un systéme pour éviter les fausse cassure , détècter quand le marcher est dans une tendance ou non tendance.

    rien n'y fait ,, l'EA ne donne pas de bon résultat.
    au contraire plus je rajouté pour l'améliorer , les résultat etait de moins en moins bon !!

    Greg
  • tonyclub33

    Humm... Je pense qu'il a des limite lui aussi ! lol
    Pour l'instant la tranche horaire 7 h 14h avec 20-30 pips regulier c'est un plus ! il viens de finir avec ma dernier position en mode semi auto +26 pips .
    Soit 48 pips depuis ce matin .
    A vrai dire je pense plus rien rajouter !