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

Mon tout 1er EA ! Présentation ..

  • arka3579

    Voici mon 1er EA, aboutissement de mes 1ères recherches..
    J'y connais rien, mais j'avance :)

    * Ouverture des positions par Clôture de la bougie, qui casse M.A. Smooth (Périodes réglables)
    sous la condition suivante : "AccountEquity.. ..."
    * Fermeture des positions par Stop-Loss Suiveur "PIPS / START / STEP"
    * MagicNumber Fixe.

    INCROYABLE, Zéro Erreur et tout FONCTIONNE ! ^^

    J'ai kke questions car je suis bloqué, j'avance plus ;
    J ARRIVE PAS. )=

    -1- Je souhaite un MagicNumber Modifiable dans MT4, pas un numéro Unique. > #define MAGICMA 1 <
    -2- J'aimerai qu'un commentaire s'intègre a l'ouverture de la position dans la colonne "COMMENTAIRE" > TERMINAL <
    -3- Je veux remplacer l'ouverture actuel par Range/BREAKOUT, 11 (Réglable)
    -4- J'imagine un Stop-Loss suiveur sur ATR 14 avec coefficient (Réglable)

    Si kk1 veut se penché sur tout cela, ben..
    Merci :)

    Et a très vite par la !

    Je vous donne le [code] dans 2 mn !
  • arka3579 — en réponse à arka3579 dans son message #124660

    Code
    #define MAGICMA 1 //--- Inputs input double LotFactor =1; input int MA_simple =1; input int SMMA_Fast =5; input int SMMA_Slow =19; input int MovingShift =0; extern double atrMultiple = 3; extern double Percent=8; input int Stoploss = 25; input int Takeprofit = 250; input int TrailingStop = 25; input int TrailingStart = 5; input int TrailingStep = 10; double TrallB = 0; double TrallS = 0; int slippage=3; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,MA_simple,MovingShift,MODE_SMA,PRICE_CLOSE,0); //--- get Moving Average ma=iMA(NULL,0,SMMA_Slow,MovingShift,MODE_SMMA,PRICE_CLOSE,0); //--- get Moving Average //--- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"",MAGICMA,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"",MAGICMA,0,Blue); return; } //--- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double OOP,SL; int b=0,s=0,tip,TicketB=0,TicketS=0; for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()) { tip = OrderType(); OOP = NormalizeDouble(OrderOpenPrice(),Digits); if(tip==OP_BUY) { b++; TicketB=OrderTicket(); if(Stoploss!=0 && Bid<=OOP - Stoploss * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;} if(Takeprofit!=0 && Bid>=OOP + Takeprofit * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;} if(TrailingStop>0) { SL=NormalizeDouble(Bid-TrailingStop*Point,Digits); if(SL>=OOP+TrailingStart*Point && (TrallB==0 || TrallB+TrailingStep*Point<SL)) TrallB=SL; } } if(tip==OP_SELL) { s++; if(Stoploss!=0 && Ask>=OOP + Stoploss * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;} if(Takeprofit!=0 && Ask<=OOP - Takeprofit * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;} TicketS=OrderTicket(); if(TrailingStop>0) { SL=NormalizeDouble(Ask+TrailingStop*Point,Digits); if(SL<=OOP-TrailingStart*Point && (TrallS==0 || TrallS-TrailingStep*Point>SL)) TrallS=SL; } } } } } if(b!=0) { if(b>1) Comment("Òðàë êîððåêòíî ðàáîòàåò òîëüêî ñ 1 îðäåðîì"); else if(TrallB!=0) { Comment("Òðàëèì îðäåð ",TicketB); DrawHline("SL Buy",TrallB,clrBlue,1); if(Bid<=TrallB) { if(OrderSelect(TicketB,SELECT_BY_TICKET)) if(OrderProfit()>0) if(!OrderClose(TicketB,OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrRed)) Comment("Îøèáêà çàêðûòèÿ îðäåðà ",GetLastError()); } } } else {TrallB=0;ObjectDelete("SL Buy");} //--- if(s!=0) { if(s>1) Comment("Òðàë êîððåêòíî ðàáîòàåò òîëüêî ñ 1 îðäåðîì"); else if(TrallS!=0) { Comment("Òðàëèì îðäåð ",TicketS); DrawHline("SL Sell",TrallS,clrRed,1); if(Ask>=TrallS) { if(OrderSelect(TicketS,SELECT_BY_TICKET)) if(OrderProfit()>0) if(!OrderClose(TicketS,OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrRed)) Comment("Îøèáêà çàêðûòèÿ îðäåðà ",GetLastError()); } } } else {TrallS=0;ObjectDelete("SL Sell");} //--- int err; if(IsTesting() && OrdersTotal()==0) { double Lot=0.1; err=OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),slippage,0,0,"òåñò",0); err=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,0,0,"òåñò",0); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DrawHline(string name,double P,color clr,int WIDTH) { if(ObjectFind(name)!=-1) ObjectDelete(name); ObjectCreate(name,OBJ_HLINE,0,0,P,0,0,0,0); ObjectSet(name,OBJPROP_COLOR,clr); ObjectSet(name,OBJPROP_STYLE,2); ObjectSet(name,OBJPROP_WIDTH,WIDTH); } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //--- } //+------------------------------------------------------------------+
  • arka3579

    Nouvelle version..
    Les conditions d'entrée sont les mêmes, Cassure après clôture sur M.A. SLOW (Lente)

    Modification de la fermetures des positions par : Clôture sur M.A. FAST (Rapide)

    Code
    //+------------------------------------------------------------------+ //| Double-MA².mq4 | //+------------------------------------------------------------------+ #property description "Double Moving Av." #define MAGICMA 1 //--- Inputs input double LotFactor =2; input int SMMA_Fast =9; input int SMMA_Slow =18; input int MovingShift =0; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,SMMA_Slow,MovingShift,MODE_SMMA,PRICE_CLOSE,0); //--- get Moving Average //--- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"",MAGICMA,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"",MAGICMA,0,Blue); return; } //--- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,SMMA_Fast,MovingShift,MODE_SMMA,PRICE_CLOSE,0); //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //--- check order type if(OrderType()==OP_BUY) { if(Open[1]>ma && Close[1]<ma) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White)) Print("OrderClose error ",GetLastError()); } break; } if(OrderType()==OP_SELL) { if(Open[1]<ma && Close[1]>ma) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White)) Print("OrderClose error ",GetLastError()); } break; } } //--- } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //--- } //+------------------------------------------------------------------+
  • arka3579

    Nouvelle version..
    Les conditions d'entrée changent, Cassure M.A. SIMPLE / SMMA (Slow)

    LA BASE n'est plus la même.

    Code
    #property copyright "Dernière mise à jour le 25-06-2021" #property version "2.00" /* ENTRY BUY: when the fast MA crosses the slow from the bottom, both MA are going up ENTRY SELL: when the fast MA crosses the slow from the top, both MA are going down EXIT: Can be fixed pips (Stop Loss and Take Profit) or the entry signal for the next trade Only 1 order at a time */ extern double LotFactor=2; //Position size extern bool UseEntryToExit=true; //Use next entry to close the trade (if false uses take profit) extern double StopLoss=0; //Stop loss in pips extern double TakeProfit=5; //Take profit in pips extern int Slippage=3; //Slippage in pips extern bool TradeEnabled=true; //Enable trade input int SMA_Fast =1; input int SMMA_Slow =11; //Functional variables double ePoint; //Point normalized bool CanOrder; //Check for risk management bool CanOpenBuy; //Flag if there are buy orders open bool CanOpenSell; //Flag if there are sell orders open int OrderOpRetry=10; //Number of attempts to perform a trade operation int SleepSecs=3; //Seconds to sleep if can't order int MinBars=60; //Minimum bars in the graph to enable trading //Functional variables to determine prices double MinSL; double MaxSL; double TP; double SL; double Spread; int Slip; //Variable initialization function void Initialize(){ RefreshRates(); ePoint=Point; Slip=Slippage; if (MathMod(Digits,2)==1){ ePoint*=10; Slip*=10; } TP=TakeProfit*ePoint; SL=StopLoss*ePoint; CanOrder=TradeEnabled; CanOpenBuy=true; CanOpenSell=true; } //Check if orders can be submitted void CheckCanOrder(){ if( Bars<MinBars ){ Print("INFO - Not enough Bars to trade"); CanOrder=false; } OrdersOpen(); return; } //Check if there are open orders and what type void OrdersOpen(){ for( int i = 0 ; i < OrdersTotal() ; i++ ) { if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) { Print("ERROR - Unable to select the order - ",GetLastError()); break; } if( OrderSymbol()==Symbol() && OrderType() == OP_BUY) CanOpenBuy=false; if( OrderSymbol()==Symbol() && OrderType() == OP_SELL) CanOpenSell=false; } return; } //Close all the orders of a specific type and current symbol void CloseAll(int Command){ double ClosePrice=0; for( int i = 0 ; i < OrdersTotal() ; i++ ) { if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) { Print("ERROR - Unable to select the order - ",GetLastError()); break; } if( OrderSymbol()==Symbol() && OrderType()==Command) { if(Command==OP_BUY) ClosePrice=Bid; if(Command==OP_SELL) ClosePrice=Ask; double Lots=OrderLots(); int Ticket=OrderTicket(); for(int j=1; j<OrderOpRetry; j++){ bool res=OrderClose(Ticket,Lots,ClosePrice,Slip,Red); if(res){ Print("TRADE - CLOSE - Order ",Ticket," closed at price ",ClosePrice); break; } else Print("ERROR - CLOSE - error closing order ",Ticket," return error: ",GetLastError()); } } } return; } //Open new order of a given type void OpenNew(int Command){ RefreshRates(); double OpenPrice=0; double SLPrice=0; double TPPrice=0; if(Command==OP_BUY){ OpenPrice=Ask; if(!UseEntryToExit){ SLPrice=OpenPrice-SL; TPPrice=OpenPrice+TP; } } if(Command==OP_SELL){ OpenPrice=Bid; if(!UseEntryToExit){ SLPrice=OpenPrice+SL; TPPrice=OpenPrice-TP; } } for(int i=1; i<OrderOpRetry; i++){ int res=OrderSend(Symbol(),Command,(AccountEquity() * 0.0001 /LotFactor),OpenPrice,Slip,NormalizeDouble(SLPrice,Digits),NormalizeDouble(TPPrice,Digits),"",0,0,Green); if(res){ Print("TRADE - NEW - Order ",res," submitted: Command ",Command," Volume ",LotFactor," Open ",OpenPrice," Slippage ",Slip," Stop ",SLPrice," Take ",TPPrice); break; } else Print("ERROR - NEW - error sending order, return error: ",GetLastError()); } return; } //Technical analysis of the indicators bool CrossToBuy=false; bool CrossToSell=false; void CheckMACross(){ CrossToBuy=false; CrossToSell=false; double MASlowCurr=iMA(Symbol(),0,SMA_Fast,0,MODE_SMMA,PRICE_CLOSE,1); double MASlowPrev=iMA(Symbol(),0,SMA_Fast,0,MODE_SMMA,PRICE_CLOSE,2); double MAFastCurr=iMA(Symbol(),0,SMMA_Slow,0,MODE_SMA,PRICE_CLOSE,1); double MAFastPrev=iMA(Symbol(),0,SMMA_Slow,0,MODE_SMA,PRICE_CLOSE,2); if(MASlowPrev>MAFastPrev && MAFastCurr>MASlowCurr){ CrossToBuy=true; } if(MASlowPrev<MAFastPrev && MAFastCurr<MASlowCurr){ CrossToSell=true; } } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- //Calling initialization, checks and technical analysis Initialize(); CheckCanOrder(); CheckMACross(); //Check of Entry/Exit signal with operations to perform if(CrossToBuy){ if(UseEntryToExit) CloseAll(OP_SELL); if(CanOpenBuy && CanOpenSell && CanOrder) OpenNew(OP_BUY); } if(CrossToSell){ if(UseEntryToExit) CloseAll(OP_BUY); if(CanOpenSell && CanOpenBuy && CanOrder) OpenNew(OP_SELL); } } //+------------------------------------------------------------------+
  • arka3579

    J'ai bien avancé :) Voila ou j'en suis.

    Ouverture par Prix cloture qui casse MA Smooth Slow
    Fermeture par Prix cloture qui casse MA Smooth Fast
    Mise en place automatique du Stop Loss Fixe (non suiveur) à ATR 14 , coef (réglable)

    Voici le code ;

    Code
    //+------------------------------------------------------------------+ //| DoubleMAcross-SL_ATR.mq4 | //| aRka3579 | //+------------------------------------------------------------------+ #property copyright "26 juin 2021" #define MAGICMA 24 //--- Inputs extern string MA = "=== M.A. Setting ==="; input int MA_Fast = 5; // input int MA_Slow = 19; // input int MovingShift = 0; extern string About = "=== MONEY MANAGEMENT Risk ==="; extern string About2 = "~~~ 2 = OpenSoft / 1 = OpenNormal / LotFactor ; 0,5 = OpenHard >>>"; input double LotFactor =2; extern bool Set_StopLoss = true; // StopLoss extern string SLTPExp = "=== S.L. & T.P. Setting ==="; extern string SLExp = "~~~ StopLoss ~~~"; extern string StopLossExp = "1=Fixed Pips 2=ATR Multiple"; extern int StopLoss_Method = 2 ; extern int Fixed_SL = 0; extern double StopLoss_ATR = 2.2 ; // TakeProfit extern string TPExp = "~~~ TakeProfit ~~~"; extern int TakeProfit = 0; // ATR Setting extern string ATRExp = "=== ATR Setting ==="; extern string TF_note = "0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1"; extern int ATR_TimeFrame = 0; extern int ATR_Period = 14; string NAME = "Auto SL-TP Setter v1"; static int ATR_TF; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,MA_Slow,MovingShift,MODE_SMMA,PRICE_CLOSE,0); //--- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"",MAGICMA,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"",MAGICMA,0,Blue); return; } //--- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,MA_Fast,MovingShift,MODE_SMMA,PRICE_CLOSE,0); //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //--- check order type if(OrderType()==OP_BUY) { if(Open[1]>ma && Close[1]<ma) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White)) Print("OrderClose error ",GetLastError()); } break; } if(OrderType()==OP_SELL) { if(Open[1]<ma && Close[1]>ma) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White)) Print("OrderClose error ",GetLastError()); } break; } } //--- }//+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetStopLoss(); if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //--- } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| init //+------------------------------------------------------------------+ int init() { ATR_TF = TF_Selector(ATR_TimeFrame); return(0); } //+------------------------------------------------------------------+ //| TF Selector | //+------------------------------------------------------------------+ int TF_Selector(int TIMEFRAME) { int TF; // Indicator Time Frame switch(TIMEFRAME) // 0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1 9=MN { case 0 : TF = 0; break; case 1 : TF = 1; break; case 2 : TF = 5; break; case 3 : TF = 15; break; case 4 : TF = 30; break; case 5 : TF = 60; break; case 6 : TF = 240; break; case 7 : TF = 1440; break; case 8 : TF = 10080; break; default: TF = 0; break; } return(TF); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ int start() { if(Set_StopLoss) SetStopLoss(); return(0); } //+------------------------------------------------------------------+ //| SL_Decision | //+------------------------------------------------------------------+ int SL_Decision(string SYMBOL) { if(StopLoss_Method>2 || StopLoss_Method<1) StopLoss_Method = 1; // error correction double SL = Fixed_SL * DeciQuoteAdjuster(SYMBOL) ; if(StopLoss_Method == 2) SL = (ATR(SYMBOL) * StopLoss_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; int Stoploss = SL; return(Stoploss); } //+------------------------------------------------------------------+ //| ATR | //+------------------------------------------------------------------+ double ATR(string SYMBOL) { double ATR = iATR(SYMBOL,ATR_TF,ATR_Period,1); return(ATR); } //+------------------------------------------------------------------+ //| SetStopLoss | //+------------------------------------------------------------------+ void SetStopLoss() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ //| Deci Quote Adjuster | //+------------------------------------------------------------------+ int DeciQuoteAdjuster(string SYMBOL) { int DQADJ = 1; int DIGITS = MarketInfo(SYMBOL,MODE_DIGITS); if(DIGITS == 5 || DIGITS == 3 ) DQADJ = 10; return(DQADJ); }

    Je n'arrive toujours pas à :

    * Mettre un MAGIC NUMBER "au choix"
    * Je trouve pas d'information concernant l'ouverture sur Breakout / RANGE
    * J'aimerai ajouter des horaires de trading Début / Fin
    * J'aimerai remplacer le stop loss ATR fixe par un mode ATR suiveur et enlever la clôture par MA
    * J'aimerai un avoir un commentaire "BUY Position" ou "SELL Position" dans le "TERMINAL" quand le robot ouvre une position.

    Merci pour votre aide.

    aRka.
  • arka3579

    Nouvelle Version, ce 27 juin.
    Ouverture par prix qui casse EMA.
    Nouveauté : Magic Number ajustable, et Trailing ATR by STEP.

    Code
    //+------------------------------------------------------------------+ //| DoubleMAcross-T.SL_ATR.mq4 | //| aRka3579 | //| | //| Ouverture ordre par %equity du prix qui casse EMA | //| StopLoss ATR Suiveur by Step | //| TakeProfit SL Suiveur | //+------------------------------------------------------------------+ #property copyright "27 juin 2021" #property version "2.07" //--- Inputs extern string MA_setting = "=== M.A. Setting ==="; input int EMA_Open = 34; // input int MovingShift = 0; extern string MM = "=== MONEY MANAGEMENT Risk ==="; extern string MM_info = "~~~ LotFactor ; 2 = SoftRisk / 1 = Normal / 0,5 = HardRisk >>>"; input double Magic = 1; input double LotFactor =2; extern bool Set_StopLoss = true; // StopLoss extern string SLTP_setting = "=== S.L. & T.P. Setting ==="; extern string StopL = "~~~ StopLoss ~~~"; extern string StopLoss = "1=Fixed Pips 2=ATR Multiple"; extern int StopLoss_Method = 2 ; extern int Fixed_SL = 0; extern double StopLoss_ATR = 2.7 ; // ATR Setting extern string ATR_setting = "=== ATR Setting ==="; extern string TF_note = "0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1"; extern int ATR_TimeFrame = 0; extern int ATR_Period = 14; // SL STEP Setting extern string TSL_setting = "=== T.S.L. STEP Setting ==="; input double Trailingstop = 25; //+------------------------------------------------------------------+ //| My TrailingStop | //+------------------------------------------------------------------+ void TrailingStop() { double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*10; for(int i=OrdersTotal()-1; i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==Magic) if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>Trailingstop*MyPoint) if(OrderStopLoss()<Bid-Trailingstop*MyPoint) int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailingstop*MyPoint),OrderTakeProfit(),0,clrNONE); } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>Trailingstop*MyPoint) if(OrderStopLoss()>Ask+Trailingstop*MyPoint) int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailingstop*MyPoint),OrderTakeProfit(),0,clrNONE); } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ string NAME = "Auto SL-TP Setter v1"; static int ATR_TF; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,EMA_Open,MovingShift,MODE_EMA,PRICE_CLOSE,0); //--- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"",Magic,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"",Magic,0,Blue); return; } //--- } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetStopLoss(); if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else TrailingStop(); //--- } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| init //+------------------------------------------------------------------+ int init() { ATR_TF = TF_Selector(ATR_TimeFrame); return(0); } //+------------------------------------------------------------------+ //| TF Selector | //+------------------------------------------------------------------+ int TF_Selector(int TIMEFRAME) { int TF; // Indicator Time Frame switch(TIMEFRAME) // 0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1 9=MN { case 0 : TF = 0; break; case 1 : TF = 1; break; case 2 : TF = 5; break; case 3 : TF = 15; break; case 4 : TF = 30; break; case 5 : TF = 60; break; case 6 : TF = 240; break; case 7 : TF = 1440; break; case 8 : TF = 10080; break; default: TF = 0; break; } return(TF); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ int start() { if(Set_StopLoss) SetStopLoss(); return(0); } //+------------------------------------------------------------------+ //| SL_Decision | //+------------------------------------------------------------------+ int SL_Decision(string SYMBOL) { if(StopLoss_Method>2 || StopLoss_Method<1) StopLoss_Method = 1; // error correction double SL = Fixed_SL * DeciQuoteAdjuster(SYMBOL) ; if(StopLoss_Method == 2) SL = (ATR(SYMBOL) * StopLoss_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; int Stoploss = SL; return(Stoploss); } //+------------------------------------------------------------------+ //| ATR | //+------------------------------------------------------------------+ double ATR(string SYMBOL) { double ATR = iATR(SYMBOL,ATR_TF,ATR_Period,1); return(ATR); } //+------------------------------------------------------------------+ //| SetStopLoss | //+------------------------------------------------------------------+ void SetStopLoss() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ //| Deci Quote Adjuster | //+------------------------------------------------------------------+ int DeciQuoteAdjuster(string SYMBOL) { int DQADJ = 1; int DIGITS = MarketInfo(SYMBOL,MODE_DIGITS); if(DIGITS == 5 || DIGITS == 3 ) DQADJ = 10; return(DQADJ); }

    Laissez vos remarques si vous avez des idées, ou autre.


    Bon dimanche.

    aRka.
  • arka3579

    1er résultat (Je ne saurai jamais si c'est fiable ou pas, ce truc, j'ai toujours eu un doute ^^)

    Long & Short // Méthode Chaque TICK (précise)
    arka3579 a joint une image
    mon-tout-1er-ea-presentation-13584
  • arka3579 — en réponse à arka3579 dans son message #124710

    Résultat sur l'image ;
    arka3579 a joint une image
    mon-tout-1er-ea-presentation-13585
  • arka3579

    CAC 40 en M5 - avec les réglages suivant ;
    arka3579 a joint une image
    mon-tout-1er-ea-presentation-13586
  • arka3579

    Dernière version en date ; avec S.M.A. (Moving Average SIMPLE)

    Code
    //+------------------------------------------------------------------+ //| SMA/Price-T.SL_ATR.mq4 | //| aRka3579 | //| | //| Ouverture ordre par %equity du prix qui casse SMA | //| StopLoss ATR Suiveur by Step | //| TakeProfit SL Suiveur | //+------------------------------------------------------------------+ #property copyright "29 juin 2021" #property version "1.00" //--- Inputs extern string MA_setting = "|||||||||| S.M.A. Setting ||||||||||"; input int SMA_Open = 85; // input int MovingShift = 0; extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||"; extern string MM_info = "LotFactor ; 2,5 = SoftRisk / 1,5 = Normal / 0,5 = HardRisk"; input double Magic = 1; input double LotFactor =1.5; extern bool Set_StopLoss = true; // StopLoss extern string SLTP_setting = "|||||||||| STOP.LOSS Setting ||||||||||"; extern string StopL = "StopLoss"; extern string StopLoss = "1=Fixed Pips 2=ATR Multiple"; extern int StopLoss_Method = 2 ; extern int Fixed_SL = 0; extern double StopLoss_ATR = 2.5 ; // ATR Setting extern string ATR_setting = "|||||||||| ATR Setting ||||||||||"; extern string TF_note = "0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1"; extern int ATR_TimeFrame = 0; extern int ATR_Period = 20; // SL STEP Setting extern string TSL_setting = "|||||||||| T.STOP.LOSS ||||||||||"; input double TrailingStop = 1000; //+------------------------------------------------------------------+ //| My TrailingStop | //+------------------------------------------------------------------+ void Trailingstop() { double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*1; for(int i=OrdersTotal()-1; i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==Magic) if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>TrailingStop*MyPoint) if(OrderStopLoss()<Bid-TrailingStop*MyPoint) int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(TrailingStop*MyPoint),OrderTakeProfit(),0,clrNONE); } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>TrailingStop*MyPoint) if(OrderStopLoss()>Ask+TrailingStop*MyPoint) int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(TrailingStop*MyPoint),OrderTakeProfit(),0,clrNONE); } } } //+------------------------------------------------------------------+ string NAME = "SMA-T.SL_ATR v1.00"; static int ATR_TF; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double sma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average sma=iMA(NULL,0,SMA_Open,MovingShift,MODE_SMA,PRICE_CLOSE,0); //--- sell conditions if(Open[1]>sma && Close[1]<sma) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"",Magic,0,Red); return; } //--- buy conditions if(Open[1]<sma && Close[1]>sma) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"",Magic,0,Blue); return; } } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetStopLoss(); if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else Trailingstop(); } //+------------------------------------------------------------------+ //| init //+------------------------------------------------------------------+ int init() { ATR_TF = TF_Selector(ATR_TimeFrame); return(0); } //+------------------------------------------------------------------+ //| TF Selector | //+------------------------------------------------------------------+ int TF_Selector(int TIMEFRAME) { int TF; // Indicator Time Frame switch(TIMEFRAME) // 0=Chart 1=M1 2=M5 3=M15 4=M30 5=1H 6=4H 7=D1 8=W1 9=MN { case 0 : TF = 0; break; case 1 : TF = 1; break; case 2 : TF = 5; break; case 3 : TF = 15; break; case 4 : TF = 30; break; case 5 : TF = 60; break; case 6 : TF = 240; break; case 7 : TF = 1440; break; case 8 : TF = 10080; break; default: TF = 0; break; } return(TF); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ int start() { if(Set_StopLoss) SetStopLoss(); return(0); } //+------------------------------------------------------------------+ //| SL_Decision | //+------------------------------------------------------------------+ int SL_Decision(string SYMBOL) { if(StopLoss_Method>2 || StopLoss_Method<1) StopLoss_Method = 1; // error correction double SL = Fixed_SL * DeciQuoteAdjuster(SYMBOL) ; if(StopLoss_Method == 2) SL = (ATR(SYMBOL) * StopLoss_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; int Stoploss = SL; return(Stoploss); } //+------------------------------------------------------------------+ //| ATR | //+------------------------------------------------------------------+ double ATR(string SYMBOL) { double ATR = iATR(SYMBOL,ATR_TF,ATR_Period,1); return(ATR); } //+------------------------------------------------------------------+ //| SetStopLoss | //+------------------------------------------------------------------+ void SetStopLoss() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ //| Deci Quote Adjuster | //+------------------------------------------------------------------+ int DeciQuoteAdjuster(string SYMBOL) { int DQADJ = 1; int DIGITS = MarketInfo(SYMBOL,MODE_DIGITS); if(DIGITS == 5 || DIGITS == 3 ) DQADJ = 10; return(DQADJ); }


    J'arrive pas a inclure un créneaux horaire de trading ;
    Heure de début 21H10 / Heure de fin 7H00. (par exemple)

    Si vous pouvez m'aider, j'arrive vraiment pas. )=

    Merci.
  • arka3579

    J'aimerai bien avoir un Message dans le "TERMINAL" dans la colonne >COMMENTAIRE<, quand le E.A. ouvre une position;
    J'arrive pas non plus. )= .. HELP.

    Merci
  • cohenhugo21 — en réponse à arka3579 dans son message #124711

    je suis desoler de te dire que te a fais une faute pour tester un robot il te faut tickstory pour fair tes teste aussi sa vaut rien du tout
    *
  • arka3579 — en réponse à cohenhugo21 dans son message #124721

    Merci pour l'info.Je vais me penché sur ton logiciel.
  • cohenhugo21

    faux que ta barre soit totalement vert
  • arka3579

    Hello à tous.
    Voici un petit E.A. fonctionnel.
    J'ai un soucis, j'arrive pas a mettre des Horaires de Trading Fonctionnelle.
    Kk1 veut-il bien compléter ce robot pour que la fonction Heure de début / Heure de fin ; soit ACTIVE.

    Un grand merci.
    aRka

    Le code :

    Code
    #property copyright "29 juillet 2021" #property version "1.00" enum ENUM_HOUR{ h00=00, //00:00 h01=01, //01:00 h02=02, //02:00 h03=03, //03:00 h04=04, //04:00 h05=05, //05:00 h06=06, //06:00 h07=07, //07:00 h08=08, //08:00 h09=09, //09:00 h10=10, //10:00 h11=11, //11:00 h12=12, //12:00 h13=13, //13:00 h14=14, //14:00 h15=15, //15:00 h16=16, //16:00 h17=17, //17:00 h18=18, //18:00 h19=19, //19:00 h20=20, //20:00 h21=21, //21:00 h22=22, //22:00 h23=23, //23:00 }; //--- Inputs extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||"; extern string MM_info = "L.F. ; 0.01 = HardRisk / 2.5 = SoftRisk"; input double LotFactor = 2.0; extern string Set = "|||||||||| Global SETTINGS ||||||||||"; input int EMA_Slow = 10; // extern double TakeProfit_ATR = 4 ; extern double StopLoss_ATR = 4 ; extern string Set2 = "|||||||||| Time SETTINGS ||||||||||"; input ENUM_HOUR StartHour = h07; // Start operation hour input ENUM_HOUR LastHour = h17; // Last operation hour input double Magic = 1; //+------------------------------------------------------------------+ string NAME = "MyEA_Lite"; static int ATR_TF; bool CheckActiveHours() { // Set operations disabled by default. bool OperationsAllowed = false; // Check if the current hour is between the allowed hours of operations. If so, return true. if ((StartHour == LastHour) && (Hour() == StartHour)) OperationsAllowed = true; if ((StartHour < LastHour) && (Hour() >= StartHour) && (Hour() <= LastHour)) OperationsAllowed = true; if ((StartHour > LastHour) && (((Hour() >= LastHour) && (Hour() <= 23)) || ((Hour() <= StartHour) && (Hour() > 0)))) OperationsAllowed = true; return OperationsAllowed; } //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ema; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ema=iMA(NULL,0,EMA_Slow,0,MODE_EMA,PRICE_CLOSE,0); //--- sell conditions if(Open[1]<ema) { res=OrderSend(Symbol(),OP_SELL,(AccountEquity() * 0.0001 /LotFactor),Bid,3,0,0,"Open SELL",Magic,0,Red); return; } //--- buy conditions if(Open[1]>ema) { res=OrderSend(Symbol(),OP_BUY,(AccountEquity() * 0.0001 /LotFactor),Ask,3,0,0,"Open BUY",Magic,0,Blue); return; } } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetStopLoss(); if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetTakeProfit(); } //+------------------------------------------------------------------+ //| init //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ int start() { return(0); } //+------------------------------------------------------------------+ //| SL_Decision | //+------------------------------------------------------------------+ int SL_Decision(string SYMBOL) { double SL = ATR(SYMBOL) * StopLoss_ATR / MarketInfo(SYMBOL,MODE_POINT) ; int Stoploss = SL; return(Stoploss); } //+------------------------------------------------------------------+ //| TP_Decision | //+------------------------------------------------------------------+ int TP_Decision(string SYMBOL) { double TP = (ATR(SYMBOL) * TakeProfit_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; int TakeProfit = TP; return(TakeProfit); } //+------------------------------------------------------------------+ //| ATR | //+------------------------------------------------------------------+ double ATR(string SYMBOL) { double ATR = iATR(SYMBOL,ATR_TF,14,1); return(ATR); } //+------------------------------------------------------------------+ //| SetStopLoss | //+------------------------------------------------------------------+ void SetStopLoss() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ //| SetTakeProfit | //+------------------------------------------------------------------+ void SetTakeProfit() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderTakeProfit() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice() + TP_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice() - TP_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ //| Deci Quote Adjuster | //+------------------------------------------------------------------+ int DeciQuoteAdjuster(string SYMBOL) { int DQADJ = 1; int DIGITS = MarketInfo(SYMBOL,MODE_DIGITS); if(DIGITS == 5 || DIGITS == 3 ) DQADJ = 10; return(DQADJ); } //+------------------------------------------------------------------+
  • arka3579 — en réponse à arka3579 dans son message #124843

    C'est ok. J'ai trouvé.
    --------------------------------------
    Add this to your variables.

    extern bool UseTimer = true; // Use start & end times in Hours
    extern int StartTime = 8; // Start hour of Trading day
    extern int EndTime = 18; // End hour of Trading day

    datetime CurrentTime;

    Then add this code before any Buy or Sell code .

    // Trading hours
    if(UseTimer == true)
    {
    CurrentTime = TimeLocal();

    int GetWeekday = TimeDayOfWeek(CurrentTime);
    int GetHour = TimeHour(CurrentTime);
    int GetMinute = TimeMinute(CurrentTime);

    if(GetHour > StartTime && GetHour < EndTime && GetWeekday <6)
    {
    bool TradeAllowed = true;

    }
    else TradeAllowed = false;
    }
    else TradeAllowed = true;
    Then in your Buy or Sell code add “&& TradeAllowed == true”

    exemple : if (FastMA>SlowMA && TradeAllowed == true)
  • arka3579

    Voici la version Final en ce 31 décembre 2021.

    Les nouveautés sont principalement :

    * Trading Horaire fonctionnel.
    * Trading au jour le jour fonctionnel.
    * Système martingale par coef si clôture déficit.
    * Take Profit par Basket au %age du capital.
    * Fermeture par ATR en fonction de la volatilité donc.
    * Ouverture par LotFixe ajustable.
    * Stop Loss et Trailing stop, avec fonction ON/OFF.
    * Commentaire du Terminal personnalisable.
    * Informations diverses quand E.A. Enclenché (en haut sur la Gauche)
    * Ouverture en L'état avec : MOVING AVERAGE + R.S.I. + KUMO BreakOut.

    Code
    //+------------------------------------------------------------------+ //| aRka3579 | //+------------------------------------------------------------------+ #property copyright "31 DEC 2021" #property version "7.00" string NAME = "My EA - MicLot"; enum ENUM_HOUR { h00=00, //00:00 h01=01, //01:00 h02=02, //02:00 h03=03, //03:00 h04=04, //04:00 h05=05, //05:00 h06=06, //06:00 h07=07, //07:00 h08=08, //08:00 h09=09, //08:00 h10=10, //10:00 h11=11, //11:00 h12=12, //12:00 h13=13, //13:00 h14=14, //14:00 h15=15, //15:00 h16=16, //16:00 h17=17, //17:00 h18=18, //18:00 h19=19, //19:00 h20=20, //20:00 h21=21, //21:00 h22=22, //22:00 h23=23, //23:00 }; //--- Inputs input int Magic = 1; extern int ATR_Period = 14; extern string MM = "|||||||||| MONEY MANAGEMENT Risk ||||||||||"; input double Lots = 0.01; extern double Martingale_X = 1.7; extern string _ = ""; extern string BP = "|||||||||| BASKET Profit_% ||||||||||"; extern bool UseProfitToClose = TRUE; extern double ProfitToClose = 6.0; extern bool AllSymbols = false; extern bool PendingOrders = true; extern string __1 = "|||||||||| SETTINGS ||||||||||"; extern string __2 = ""; extern bool StopLoss_ON = true; extern double StopLoss_ATR = 2.0; extern bool TrailingStep_ON = true; extern double TrailingStep_ATR = 0.04; extern string __3 = ""; extern string __4 = "|||||||||| MOVING AVERAGE ||||||||||"; extern string MA_info = "0 = sma, 1 = ema, 2 = smma, 3 = lwma"; input int MA_Filter = 120; input int MA_Mode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern string __5 = ""; extern string __6 = "|||||||||| R.S.I. ||||||||||"; extern int RSI_Period = 14; extern int RSI_Upper = 50; extern int RSI_Lower = 50; extern string __7 = ""; extern string __8 = "||||||||||||||||||||||| TERMINAL Comments ||||||||||||||||||||||||||||||"; input string Buy_Com = __FILE__; input string Sell_Com = __FILE__; extern string __9 = ""; extern string __10 = "|||||||||| DAY Settings ||||||||||"; extern bool Monday = true; extern bool Tuesday = true; extern bool Wednesday = true; extern bool Thursday = true; extern bool Friday = true; extern bool Sunday = false; extern string __11 = ""; extern string TIME_setting = "|||||||||| TIME Settings ||||||||||"; extern bool UseTimer = false; // Use start & end times in Hours input ENUM_HOUR StartHour = h06; // Start operation hour input ENUM_HOUR EndHour = h22; // Last operation hour extern string __12 = ""; extern string INFO = "||||||||||||||||||||||| 0.1 MicroLot pour 4000€ de capital ||||||||||||||||||||||||||||||"; //+------------------------------------------------------------------+ int last_bar = 0; double last_profit, last_lot; int last_tip; datetime CurrentTime; double pips2dbl, pips2point, pipValue, profit, profitnow; bool clear; bool DaytoTrade(){ bool daytotrade = false; if(DayOfWeek() == 0 && Sunday) daytotrade = true; if(DayOfWeek() == 1 && Monday) daytotrade = true; if(DayOfWeek() == 2 && Tuesday) daytotrade = true; if(DayOfWeek() == 3 && Wednesday) daytotrade = true; if(DayOfWeek() == 4 && Thursday) daytotrade = true; if(DayOfWeek() == 5 && Friday) daytotrade = true; return(daytotrade);} bool Trail(){ bool trailing = false; if(DayOfWeek() == 5 && TrailingStep_ON) trailing = true; return(trailing);} bool StopL(){ bool stopL = false; if(DayOfWeek() == 5 && StopLoss_ON) stopL = true; return(stopL);} //+------------------------------------------------------------------+ //| My TrailingStop | //+------------------------------------------------------------------+ void Trailingstop() { double SYMBOL; double MyPoint = (ATR(SYMBOL) * TrailingStep_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; for(int i=OrdersTotal()-1; i>=0;i--) { if (Trail() ) if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==Magic) if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>MyPoint) if(OrderStopLoss()<Bid-MyPoint) int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(MyPoint),OrderTakeProfit(),0,clrNONE); } else if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>MyPoint) if(OrderStopLoss()>Ask+MyPoint) int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(MyPoint),OrderTakeProfit(),0,clrNONE); } } } //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //--- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { // Martingale System +------------- double Lot = Lots; if( OrdersTotal() == 0 && OrdersHistoryTotal() == 0) Lot = Lots; else if( OrdersTotal() == 0&& OrdersHistoryTotal() > 0 ) last_history_profit(); if( last_profit < 0 ) Lot = Martingale_X*last_lot; if( last_profit > 0 ) Lot = Lots; //+-------- string ls_01 = " Levier: " + AccountLeverage() + "\n" + "\n" + " Heure du Server: " + TimeToStr(TimeCurrent(), TIME_SECONDS) + "\n" + " Heure Locale: " + TimeToStr(TimeLocal(), TIME_SECONDS) + "\n"; string ls_02 = "-------------------------------------\n"+"\n"; int Spread; Spread=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD); //--- Output values in three lines string ls_03 = (StringFormat(" Spread = %d", Spread)); string ls_04 = "\n" + "\n"; string ls_05 = "-------------------------------------\n"; string profitstr = DoubleToStr(profitnow,2); string ls_06 = "\n" + "\n"; string ls_07 = " Solde : " + AccountBalance() + "\n"; string ls_08 = " Equity : " + AccountEquity() + "\n"; string ls_09 = " Profits : " + AccountProfit() + "\n"; Comment( ls_01 + ls_02 + ls_03 + ls_04 + ls_05 + ls_06 + ls_07 + ls_08 + ls_09 ); int res; // Trading hours +-------------- if(UseTimer == true) { CurrentTime = TimeLocal(); int GetWeekday = TimeDayOfWeek(CurrentTime); int GetHour = TimeHour(CurrentTime); int GetMinute = TimeMinute(CurrentTime); if(GetHour >= StartHour && GetHour <= EndHour && GetWeekday <6) { bool TradeAllowed = true; } else TradeAllowed = false; } else TradeAllowed = true; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average double ssA=iIchimoku(NULL, 0,8,23,52, MODE_SENKOUSPANA,0); double ssB=iIchimoku(NULL, 0,8,23,52, MODE_SENKOUSPANB,0); //--- SELL conditions if(Open[1] < iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1)) if(iRSI(NULL,PERIOD_CURRENT,RSI_Period,PRICE_CLOSE,0) < RSI_Lower && TradeAllowed == true) if(Open[1]<ssA) if(Open[1]<ssB) if (DaytoTrade() ) { res=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,0,Sell_Com,Magic,0,Red); return; } //--- BUY conditions if(Open[1] > iMA(NULL,PERIOD_CURRENT,MA_Filter,0,MA_Mode,PRICE_CLOSE,1)) if(iRSI(NULL,PERIOD_CURRENT,RSI_Period,PRICE_CLOSE,0) > RSI_Upper && TradeAllowed == true) if(Open[1]>ssA) if(Open[1]>ssB) if (DaytoTrade() ) { res=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,Buy_Com,Magic,0,Blue); return; } } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { //--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else SetStopLoss(); if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else Trailingstop(); //--- Basket Profit/Lost profit = ProfitCheck(); if(UseProfitToClose) { if(profit>(AccountBalance() * ProfitToClose/100)) { if(AllSymbols) { if(PendingOrders) if(!CloseDeleteAll()) clear=false; if(!PendingOrders) if(!CloseDeleteAllNonPending()) clear=false; } if(!AllSymbols) { if(PendingOrders) if(!CloseDeleteAllCurrent()) clear=false; if(!PendingOrders) if(!CloseDeleteAllCurrentNonPending()) clear=false; } } } } //////////////////////////////////////////////////////////////////////////////////////////////////////// bool CloseDeleteAll() { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red)) return(false); }break; } if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) if(!OrderDelete(OrderTicket())) { Print("Error deleting " + OrderType() + " order : ",GetLastError()); return (false); } } } return (true); } //////////////////////////////////////////////////////////////////////////////////////////////////////// // delete all on current chart bool CloseDeleteAllCurrent() { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red)) return(false); }break; } if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) if(!OrderDelete(OrderTicket())) { return (false); } } } } return (true); } //////////////////////////////////////////////////////////////////////////////////////////////////////// // left pending orders bool CloseDeleteAllNonPending() { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red)) return(false); }break; } } } return (true); } //////////////////////////////////////////////////////////////////////////////////////////////////////// // delete all on current chart left pending bool CloseDeleteAllCurrentNonPending() { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Blue)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Red)) return(false); }break; } } } } return (true); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// double ProfitCheck() { double profit=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(AllSymbols) profit+=OrderProfit(); else if(OrderSymbol()==Symbol()) profit+=OrderProfit(); } return(profit); } //+------------------------------------------------------------------+ //| init //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ int start() { return(0); } //+------------------------------------------------------------------+ //| SL_Decision | //+------------------------------------------------------------------+ int SL_Decision(string SYMBOL) { double SL = (ATR(SYMBOL) * StopLoss_ATR) / MarketInfo(SYMBOL,MODE_POINT) ; int Stoploss = SL; return(Stoploss); } //+------------------------------------------------------------------+ //| ATR | //+------------------------------------------------------------------+ double ATR(string SYMBOL) { double ATR = iATR(SYMBOL,0,ATR_Period,1); return(ATR); } //+------------------------------------------------------------------+ //| SetStopLoss | //+------------------------------------------------------------------+ void SetStopLoss() { int i,Type; bool selected, success; for(i=0; i<OrdersTotal(); i++) { if (StopL() ) selected = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(selected && (OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderStopLoss() < 1 * MarketInfo(OrderSymbol(),MODE_POINT)) { Type = OrderType(); success = false; if(Type == OP_BUY) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if(Type == OP_SELL) success = OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + SL_Decision(OrderSymbol()) * MarketInfo(OrderSymbol(),MODE_POINT), OrderTakeProfit(), 0, CLR_NONE); if (!success) Print("Error code = " + GetLastError()); } } } // end of SetStopLoss //+------------------------------------------------------------------+ // Martingale //+------------------------------------------------------------------+ double last_history_profit() { double cpte_profit = 0; //int Magik_No = -1; if( OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY) ) { if( OrderMagicNumber() == Magic ) { last_profit = OrderProfit(); last_lot = OrderLots(); last_tip = OrderType(); } } return(0); }

    Remerciements aux programmeurs.
    Je n'ai pas inventé la musique mais vous me permettez de composé.

    Bon réveillons de nouvelle année.
    Je penserais a vous le 1er janvier 2022 !

    Yohan. (aRka)
    Modifié le 2021-12-31 14:32:02 par arka3579
  • Mikiburger

    Bonjour Yohan,

    Merci pour le partage.

    Le programme tourne correctement chez toi ?
    Moi j'ai des "OrderModify Error 130" et il ne fait que perdre
  • arka3579 — en réponse à Mikiburger dans son message #125631

    Bonsoir Mikibuger ;

    J'ai pas d 'erreur pour ma part, j'ai vérifier le code.
    Pour ce qui est du fait d être rentable, ca c'est autre chose.
    Vous avez une base :)
    Libre a vous après.
  • arka3579

    Voici une nouvelle version avec un nouveau système SL-TP ET Step !
    Il arrive dans un instant :).