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

Programmer un indicateur via d'autres indicateurs !

  • billyTom

    Bonjour,

    Je souhaiterai faire un indicateur en utilisant les information de d’autres indicateurs (ci-joint)
    Je n’arrive pas à utiliser les informations de ces indicateurs dans mon propre indicateur !
    Je pense qu'il faut utiliser #include ou #import mais... ?!?

    de plus si le code des indicateurs dont je souhaiterais utiliser les informations n'est pas accessible (.ex4) c'est faisable aussi ? ou faut il obligatoirement avoir un mq4 dispo comme ici ?

    Merci de votre aide.

    Ci-joint ce que je recherche à faire

    flèche rouge Sell :
    SI
    1/ Croisement Stochastic sur bougie 2
    - Signal passe au-dessus de Stochastic
    - Niveau > 80%
    ET

    2/ Croisement ZérolagMACD sur bougie 0
    - Signal passe au-dessus de ZérolagMACD
    - Niveau > 0.00
    ET
    3/ RSI > 70% sur bougie 2

    ALORS

    Afficher flèche rouge (vente) sur bougie 2
    --------------------------------------------------------------------------
    Flèche verte Buy :
    SI
    1/ Croisement Stochastic sur bougie 2
    - Signal passe en-dessous de Stochastic
    - Niveau < 20%
    ET
    2/ Croisement ZérolagMACD sur bougie 0
    - Signal passe en-dessous de ZérolagMACD
    - Niveau < 0.00
    ET
    3/ RSI < 30% sur bougie 2
    ALORS
    Afficher une flèche verte (achat) sur bougie 2

    Ci-joint une image pour les conditions de vente.
    Modifié le 2021-01-05 16:55:16 par billyTom
    billyTom a joint une image
    prog-indicateur-via-d-autres-indicateurs-12536
  • billyTom

    Ci-joint le code de l'indicateur ZerolagMACD.mq4
    Code
    //+------------------------------------------------------------------+ //| ZeroLag MACD.mq4 | //| RD | //| [email protected] | //+------------------------------------------------------------------+ #property copyright "RD" #property link "[email protected]" //---- #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red //---- input parameters extern int FastEMA = 12; extern int SlowEMA = 24; extern int SignalEMA = 9; //---- buffers double MACDBuffer[]; double SignalBuffer[]; double FastEMABuffer[]; double SlowEMABuffer[]; double SignalEMABuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(5); SetIndexBuffer(0, MACDBuffer); SetIndexBuffer(1, SignalBuffer); SetIndexBuffer(2, FastEMABuffer); SetIndexBuffer(3, SlowEMABuffer); SetIndexBuffer(4, SignalEMABuffer); // SetIndexStyle(0, DRAW_HISTOGRAM); SetIndexStyle(0, DRAW_LINE,EMPTY); SetIndexStyle(1, DRAW_LINE,EMPTY); SetIndexDrawBegin(0, SlowEMA); SetIndexDrawBegin(1, SlowEMA); IndicatorShortName("ZeroLag MACD(" + FastEMA + "," + SlowEMA + "," + SignalEMA + ")"); SetIndexLabel(0, "MACD"); SetIndexLabel(1, "Signal"); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; double EMA, ZeroLagEMAp, ZeroLagEMAq; for(int i = 0; i < limit; i++) { FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i); SlowEMABuffer[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i); } for(i = 0; i < limit; i++) { EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i); ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA; EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i); ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA; MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq; } for(i = 0; i < limit; i++) SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i); for(i = 0; i < limit; i++) { EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i); SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA; } return(0); } //+------------------------------------------------------------------+
    Modifié le 2021-01-05 16:50:45 par billyTom
  • billyTom

    ci-joint le code de l'indicateur RSI.mq4
    Code
    //+------------------------------------------------------------------+ //| RSI.mq4 | //| Copyright 2005-2014, MetaQuotes Software Corp. | //| http://www.mql4.com | //+------------------------------------------------------------------+ #property copyright "2005-2014, MetaQuotes Software Corp." #property link "http://www.mql4.com" #property description "Relative Strength Index" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 1 #property indicator_color1 DodgerBlue #property indicator_level1 30.0 #property indicator_level2 70.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //--- input parameters input int InpRSIPeriod=14; // RSI Period //--- buffers double ExtRSIBuffer[]; double ExtPosBuffer[]; double ExtNegBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; //--- 2 additional buffers are used for counting. IndicatorBuffers(3); SetIndexBuffer(1,ExtPosBuffer); SetIndexBuffer(2,ExtNegBuffer); //--- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtRSIBuffer); //--- name for DataWindow and indicator subwindow label short_name="RSI("+string(InpRSIPeriod)+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //--- check for input if(InpRSIPeriod<2) { Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod); return(INIT_FAILED); } //--- SetIndexDrawBegin(0,InpRSIPeriod); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Relative Strength Index | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i,pos; double diff; //--- if(Bars<=InpRSIPeriod || InpRSIPeriod<2) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(ExtRSIBuffer,false); ArraySetAsSeries(ExtPosBuffer,false); ArraySetAsSeries(ExtNegBuffer,false); ArraySetAsSeries(close,false); //--- preliminary calculations pos=prev_calculated-1; if(pos<=InpRSIPeriod) { //--- first RSIPeriod values of the indicator are not calculated ExtRSIBuffer[0]=0.0; ExtPosBuffer[0]=0.0; ExtNegBuffer[0]=0.0; double sump=0.0; double sumn=0.0; for(i=1; i<=InpRSIPeriod; i++) { ExtRSIBuffer[i]=0.0; ExtPosBuffer[i]=0.0; ExtNegBuffer[i]=0.0; diff=close[i]-close[i-1]; if(diff>0) sump+=diff; else sumn-=diff; } //--- calculate first visible value ExtPosBuffer[InpRSIPeriod]=sump/InpRSIPeriod; ExtNegBuffer[InpRSIPeriod]=sumn/InpRSIPeriod; if(ExtNegBuffer[InpRSIPeriod]!=0.0) ExtRSIBuffer[InpRSIPeriod]=100.0-(100.0/(1.0+ExtPosBuffer[InpRSIPeriod]/ExtNegBuffer[InpRSIPeriod])); else { if(ExtPosBuffer[InpRSIPeriod]!=0.0) ExtRSIBuffer[InpRSIPeriod]=100.0; else ExtRSIBuffer[InpRSIPeriod]=50.0; } //--- prepare the position value for main calculation pos=InpRSIPeriod+1; } //--- the main loop of calculations for(i=pos; i<rates_total && !IsStopped(); i++) { diff=close[i]-close[i-1]; ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod; ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod; if(ExtNegBuffer[i]!=0.0) ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]); else { if(ExtPosBuffer[i]!=0.0) ExtRSIBuffer[i]=100.0; else ExtRSIBuffer[i]=50.0; } } //--- return(rates_total); } //+------------------------------------------------------------------+


    ci-joint le code de l'indicateur Stochastic.mq4
    Code
    //+------------------------------------------------------------------+ //| Stochastic.mq4 | //| Copyright 2005-2014, MetaQuotes Software Corp. | //| http://www.mql4.com | //+------------------------------------------------------------------+ #property copyright "2005-2014, MetaQuotes Software Corp." #property link "http://www.mql4.com" #property description "Stochastic Oscillator" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 2 #property indicator_color1 LightSeaGreen #property indicator_color2 Red #property indicator_level1 20.0 #property indicator_level2 80.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //--- input parameters input int InpKPeriod=5; // K Period input int InpDPeriod=3; // D Period input int InpSlowing=3; // Slowing //--- buffers double ExtMainBuffer[]; double ExtSignalBuffer[]; double ExtHighesBuffer[]; double ExtLowesBuffer[]; //--- int draw_begin1=0; int draw_begin2=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; //--- 2 additional buffers are used for counting. IndicatorBuffers(4); SetIndexBuffer(2, ExtHighesBuffer); SetIndexBuffer(3, ExtLowesBuffer); //--- indicator lines SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0, ExtMainBuffer); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1, ExtSignalBuffer); //--- name for DataWindow and indicator subwindow label short_name="Sto("+IntegerToString(InpKPeriod)+","+IntegerToString(InpDPeriod)+","+IntegerToString(InpSlowing)+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); SetIndexLabel(1,"Signal"); //--- draw_begin1=InpKPeriod+InpSlowing; draw_begin2=draw_begin1+InpDPeriod; SetIndexDrawBegin(0,draw_begin1); SetIndexDrawBegin(1,draw_begin2); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Stochastic oscillator | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i,k,pos; //--- check for bars count if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(ExtMainBuffer,false); ArraySetAsSeries(ExtSignalBuffer,false); ArraySetAsSeries(ExtHighesBuffer,false); ArraySetAsSeries(ExtLowesBuffer,false); ArraySetAsSeries(low,false); ArraySetAsSeries(high,false); ArraySetAsSeries(close,false); //--- pos=InpKPeriod-1; if(pos+1<prev_calculated) pos=prev_calculated-2; else { for(i=0; i<pos; i++) { ExtLowesBuffer[i]=0.0; ExtHighesBuffer[i]=0.0; } } //--- calculate HighesBuffer[] and ExtHighesBuffer[] for(i=pos; i<rates_total && !IsStopped(); i++) { double dmin=1000000.0; double dmax=-1000000.0; for(k=i-InpKPeriod+1; k<=i; k++) { if(dmin>low[k]) dmin=low[k]; if(dmax<high[k]) dmax=high[k]; } ExtLowesBuffer[i]=dmin; ExtHighesBuffer[i]=dmax; } //--- %K line pos=InpKPeriod-1+InpSlowing-1; if(pos+1<prev_calculated) pos=prev_calculated-2; else { for(i=0; i<pos; i++) ExtMainBuffer[i]=0.0; } //--- main cycle for(i=pos; i<rates_total && !IsStopped(); i++) { double sumlow=0.0; double sumhigh=0.0; for(k=(i-InpSlowing+1); k<=i; k++) { sumlow +=(close[k]-ExtLowesBuffer[k]); sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]); } if(sumhigh==0.0) ExtMainBuffer[i]=100.0; else ExtMainBuffer[i]=sumlow/sumhigh*100.0; } //--- signal pos=InpDPeriod-1; if(pos+1<prev_calculated) pos=prev_calculated-2; else { for(i=0; i<pos; i++) ExtSignalBuffer[i]=0.0; } for(i=pos; i<rates_total && !IsStopped(); i++) { double sum=0.0; for(k=0; k<InpDPeriod; k++) sum+=ExtMainBuffer[i-k]; ExtSignalBuffer[i]=sum/InpDPeriod; } //--- OnCalculate done. Return new prev_calculated. return(rates_total); } //+------------------------------------------------------------------+
  • billyTom

    Bonjour,
    Personne ne peux m'aider ? :(
  • stani

    Salut billy

    Tu n'as pas besoin du code des indics, dans ton indic tu les utilises exactement comme dans un EA, ni plus ni moins.

    MonRSI=iRSI(..... etc
    Modifié le 2021-01-09 09:54:25 par stani
  • billyTom — en réponse à stani dans son message #120473

    Bonjour Stani,

    Avant tout merci d'avoir pris le temps de répondre ;)

    Bon ça je veux bien mais j'avoue pas trop comprendre comment récupérer l'information d'un d'indic X pour le coller dans un indicateur perso...

    Humm désolé je comprend pas... par exemple :

    Croisement ZérolagMACD sur bougie 0
    - Signal passe en-dessous de ZérolagMACD
    - Niveau < 0.00

    c'est la syntax de récupération qui m’échappe !

    Cordialement,
  • billyTom — en réponse à stani dans son message #120473

    stani, le 09/01/2021 dit :
    Salut billy Tu n'as pas besoin du code des indics, dans ton indic tu les utilises exactement comme dans un EA, ni plus ni moins. MonRSI=iRSI(..... etc


    Bonjour,
    en cherchant suite à ton message je viens de comprendre quelque info que je vous partage ici :

    double rsi1,rsi2;
    rsi1 = iRSI(Symbol(),t,14,PRICE_CLOSE,shift);
    rsi2 = iRSI(Symbol(),t,14,PRICE_CLOSE,shift+1);

    est egale à :

    double rsi1,rsi2;
    double rsi1custom = iCustom(NULL,Symbol(),"RSI",0,shift);
    double rsi2custom = iCustom(NULL,Symbol(),"RSI",0,shift+1);
    rsi1 = rsi1custom;
    rsi2 = rsi2custom;

    et ça c'est ce que je voulais !!! :)

    maintenant ma question est avec un indicateur autre que le RSI par exemple le ZérolagMACD qui lui à plusieurs "courbes" (signal et MACD) comment faire la différence dans le iCustom pour par exemple dire si croisement de ces 2 courbes faire ceci cela?

    Cordialement,