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

Problème indicateur coupé

  • (invité)

    Bonjour à tous,

    Alors voila, je viens de créer un indicateur mais il fait des gaps de temps en temps et je ne comprends pas pourquoi...
    Quelqu'un pourrait m'aider ?

    Merci et bonne journée à tous
    a joint une image
    probleme-indicateur-coupe-10892
  • kaliloup

    Bonjour, des gaps ? Il faudrait, si possible, être un petit peu plus explicite (fonctionnement de l'indicateur, calculs effectués...) et encore le mieux serait de pouvoir accéder au code pour vous aider.
  • (invité)

    Bonjour,

    Par "gaps" je voulais dire des "espaces" qui coupent mon indicateur, ce sont 3 moyennes mobiles. Le code est tiré d'une vidéo YouTube.

    Code :
    Code
    //+------------------------------------------------------------------+ //| Trend Reborn.mq4 | //+------------------------------------------------------------------+ #property copyright "FXChartWorks" #property description "Trend Reborn" #property strict #property indicator_chart_window #property indicator_buffers 4 //+------------------------------------------------------------------+ input int SignalMAPeriod = 5; input int FastMAPeriod = 13; input int SlowMAPeriod = 34; input ENUM_MA_METHOD MAMethod = MODE_EMA; double BufferFast[]; double BufferSlow[]; double BufferUp[]; double BufferDown[]; #define UpIndicator 0 #define DownIndicator 2 #define FastIndicator 3 #define SlowIndicator 1 //+------------------------------------------------------------------+ int OnInit(){ SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_SOLID, 1, clrRed); SetIndexBuffer(FastIndicator, BufferFast); SetIndexLabel(FastIndicator, "Fast"); SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_SOLID, 1, clrGreen); SetIndexBuffer(SlowIndicator, BufferSlow); SetIndexLabel(SlowIndicator, "Slow"); SetIndexStyle(UpIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrGreen); SetIndexBuffer(UpIndicator, BufferUp); SetIndexEmptyValue(UpIndicator, 0.0); SetIndexStyle(DownIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrRed); SetIndexBuffer(DownIndicator, BufferDown); SetIndexEmptyValue(DownIndicator, 0.0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ 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 limit; double signalMA, fastMA, slowMA; if(rates_total<=SlowMAPeriod){ return(0); } limit=rates_total-prev_calculated; if(prev_calculated>0){ limit++; } for(int i=limit-1; i>=0; i--){ signalMA = iMA(Symbol(), Period(), SignalMAPeriod, 0, MAMethod, PRICE_CLOSE, i); fastMA = iMA(Symbol(), Period(), FastMAPeriod, 0, MAMethod, PRICE_CLOSE, i); slowMA = iMA(Symbol(), Period(), SlowMAPeriod, 0, MAMethod, PRICE_CLOSE, i); if(signalMA<fastMA && fastMA>slowMA){ BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferUp[i]=fastMA; } else if(signalMA>fastMA && fastMA<slowMA){ BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferDown[i]=slowMA; } } return(rates_total); } //+------------------------------------------------------------------+
    a joint une vidéo
    Video
  • kaliloup

    Don j'ai jeté un coup d’œil et votre indicateur est basé sur 3 MA, je prend cet exemple dans votre code:
    if(signalMA>fastMA && fastMA<slowMA)
    Quand la plus petite est supérieur à la moyenne et que la moyenne est inférieur à la plus grande, il y a 2 conditions qui ne sont pas remplis dans votre indicateur, car c'est seulement au croisement de ces lignes que votre indicateur va dessiner vos buffer. Par exemple cette condition : if(signalMA>fastMA && fastMA>slowMA) devrait être rajouté. Il est compliqué de bien vous expliquer voici un code d'exemple.
    Code
    //+------------------------------------------------------------------+ //| Trend Reborn.mq4 | //+------------------------------------------------------------------+ #property copyright "FXChartWorks" #property description "Trend Reborn" #property strict #property indicator_chart_window #property indicator_buffers 4 //+------------------------------------------------------------------+ input int SignalMAPeriod = 5; input int FastMAPeriod = 13; input int SlowMAPeriod = 34; input ENUM_MA_METHOD MAMethod = MODE_EMA; double BufferFast[]; double BufferSlow[]; double BufferUp[]; double BufferDown[]; #define UpIndicator 0 #define DownIndicator 2 #define FastIndicator 3 #define SlowIndicator 1 //+------------------------------------------------------------------+ int OnInit(){ SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_SOLID, 1, clrRed); SetIndexBuffer(FastIndicator, BufferFast); SetIndexLabel(FastIndicator, "Fast"); SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_SOLID, 1, clrGreen); SetIndexBuffer(SlowIndicator, BufferSlow); SetIndexLabel(SlowIndicator, "Slow"); SetIndexStyle(UpIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrGreen); SetIndexBuffer(UpIndicator, BufferUp); SetIndexEmptyValue(UpIndicator, 0.0); SetIndexStyle(DownIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrRed); SetIndexBuffer(DownIndicator, BufferDown); SetIndexEmptyValue(DownIndicator, 0.0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ 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 limit; double signalMA, fastMA, slowMA; if(rates_total<=SlowMAPeriod){ return(0); } limit=rates_total-prev_calculated; if(prev_calculated>0){ limit++; } for(int i=limit-1; i>=0; i--){ signalMA = iMA(Symbol(), Period(), SignalMAPeriod, 0, MAMethod, PRICE_CLOSE, i); fastMA = iMA(Symbol(), Period(), FastMAPeriod, 0, MAMethod, PRICE_CLOSE, i); slowMA = iMA(Symbol(), Period(), SlowMAPeriod, 0, MAMethod, PRICE_CLOSE, i); if((signalMA<fastMA && fastMA>slowMA)||(signalMA<fastMA && fastMA<slowMA)) { BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferUp[i]=fastMA; Print("ok1"); } if((signalMA>fastMA && fastMA<slowMA)||(signalMA>fastMA && fastMA>slowMA)) { BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferDown[i]=slowMA; Print("ok2"); } } return(rates_total); } //+------------------------------------------------------------------+
  • kaliloup

    essayez ceci et tenez moi informé.
    Code
    //+------------------------------------------------------------------+ //| Trend Reborn.mq4 | //+------------------------------------------------------------------+ #property copyright "FXChartWorks" #property description "Trend Reborn" #property strict #property indicator_chart_window #property indicator_buffers 4 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "Label2" #property indicator_type2 DRAW_LINE #property indicator_color2 clrGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Label3 #property indicator_label3 "Label3" #property indicator_type3 DRAW_HISTOGRAM #property indicator_color3 clrLime #property indicator_style3 STYLE_DOT #property indicator_width3 1 #property indicator_label4 "Label4" #property indicator_type4 DRAW_HISTOGRAM #property indicator_color4 clrRed #property indicator_style4 STYLE_DOT #property indicator_width4 1 //+------------------------------------------------------------------+ input int SignalMAPeriod = 5; input int FastMAPeriod = 13; input int SlowMAPeriod = 34; input ENUM_MA_METHOD MAMethod = MODE_EMA; double BufferFast[]; double BufferSlow[]; double BufferUp[]; double BufferDown[]; #define UpIndicator 0 #define DownIndicator 2 #define FastIndicator 3 #define SlowIndicator 1 //+------------------------------------------------------------------+ int OnInit(){ SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_SOLID, 1, clrRed); SetIndexBuffer(FastIndicator, BufferFast); SetIndexLabel(FastIndicator, "Fast"); SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_SOLID, 1, clrGreen); SetIndexBuffer(SlowIndicator, BufferSlow); SetIndexLabel(SlowIndicator, "Slow"); SetIndexStyle(UpIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrGreen); SetIndexBuffer(UpIndicator, BufferUp); SetIndexEmptyValue(UpIndicator, 0.0); SetIndexStyle(DownIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrRed); SetIndexBuffer(DownIndicator, BufferDown); SetIndexEmptyValue(DownIndicator, 0.0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ 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 limit; double signalMA, fastMA, slowMA; if(rates_total<=SlowMAPeriod){ return(0); } limit=rates_total-prev_calculated; if(prev_calculated>0){ limit++; } for(int i=limit-1; i>=0; i--){ signalMA = iMA(Symbol(), Period(), SignalMAPeriod, 0, MAMethod, PRICE_CLOSE, i); fastMA = iMA(Symbol(), Period(), FastMAPeriod, 0, MAMethod, PRICE_CLOSE, i); slowMA = iMA(Symbol(), Period(), SlowMAPeriod, 0, MAMethod, PRICE_CLOSE, i); if((signalMA<fastMA && fastMA>slowMA)||(signalMA<fastMA && fastMA<slowMA)) { BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferUp[i]=fastMA; BufferDown[i]=slowMA; } if((signalMA>fastMA && fastMA<slowMA)||(signalMA>fastMA && fastMA>slowMA)) { BufferFast[i]=fastMA; BufferSlow[i]=slowMA; BufferUp[i]=fastMA; BufferDown[i]=slowMA; } } return(rates_total); } //+------------------------------------------------------------------+
  • (invité)

    Tout fonctionne à merveille merci beaucoup, je vais examiner le code de plus près pour voir mes erreurs !
  • kaliloup

    Bon courage à vous pour la suite.
  • kaliloup

    Pour pouvoir changer les couleurs des buffers remplacez:
    SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_SOLID, 1, clrRed)
    Par:
    SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_SOLID, 1) par exemple.