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

HELP - Activer Désactiver un Indicateur dans un E.A. (Bool - True/False)

  • arka3579

    Hello !
    Je cherche pour pouvoir activer / désactiver un INDICATEUR.
    Si on a par exemple, EMA, MFI, RSI, BANDE BOLL . .. ...
    Je souhaite pouvoir choisir.

    Merci de modifier ce petit EA fonctionnelle avec ces conditions svp.
    Je trouve pas l'info.


    Remerciement.
    aRka.

    Code
    string NAME = "ExpertAdvisor"; input double Magic = 1; input double LotFactor =2.2; extern double StopLoss_ATR = 2.2 ; input double TrailingStep_ATR = 2.2; extern string Set = ""; extern string MA_setting = "|||||||||| M.A. Settings ||||||||||"; input int MA_Open = 22; // input bool MA_ON = True; extern string MFI_setting = "|||||||||| M.F.I. Settings ||||||||||"; extern int MFI_Upper = 51; //rsi period extern int MFI_Lower = 49; //rsi period input bool MFI_ON = True; //+------------------------------------------------------------------+ //| My TrailingStop | //+------------------------------------------------------------------+ void Trailingstop() { double SYMBOL; double MyPoint = (ATR(SYMBOL) * TrailingStep_ATR/100) / MarketInfo(SYMBOL,MODE_POINT) ; 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()>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); } } } //+------------------------------------------------------------------+ 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,MA_Open,0,MODE_EMA,PRICE_CLOSE,0); //--- sell conditions if(Open[1]>ma && Close[1]<ma) if(iMFI(NULL,0,14,0) < MFI_Lower) { 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) if(iMFI(NULL,0,14,0) > MFI_Upper) { 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() { 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,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 //+------------------------------------------------------------------+ //| 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

    J'ai trouvé !
    Exemple pour une fonction ON/OFF du Robot :
    ON = "True"

    Dans la partie supérieur mettre :
    extern bool EXPERT_Adv_ON = true;

    En dessous la liste supérieur du Robot mettre :
    bool EAon(){
    bool eaon = false;
    if(DayOfWeek() == 1 && EXPERT_Adv_ON) eaon = true;
    return(eaon);}

    Enfin dans la parti des conditions BUY & conditions SELL mettre la fonction if :

    void CheckForOpen()
    {

    if (EAon() )

    N.B. Cela peut fonctionner aussi pour activé un StopLoss, un TakeProfit, une méthode d'Exit .. ...