how to show indicator on chart

 
i need to know how to show standard or custom indicators on a chart when an ea attached to the chart . can u guys help me out ...
 

it's easy..

standar indicator like this:

double stoch=iStochastic(NULL,0,5,3,3,MODE_SMA, 1, MODE_MAIN,1); // for stoch indicator

custom indicator like this:

double stochh=iCustom(NULL,0,"indicator name",1,1); // 1 first is buffer, 1 end is shift

for more complete to some indicator, u can learn from this:

https://book.mql4.com/samples/shared


thx..

 
I think the examples above are not supposed to show the indicator on the chart
 

oh.. hehe..

maybe can drag indicator to a chart..

but i feel that he want show the indicator from ea..

maybe like that, like my first mission in study ea..

 
hardyyanto:

oh.. hehe..

maybe can drag indicator to a chart..

but i feel that he want show the indicator from ea..

maybe like that, like my first mission in study ea..


you got my point ..
 
  1. Attach the indicator to the chart for your use. The EA doesn't care, it uses the results from iCustom/iRSI/etc.
  2. Have the EA display the results
    //+------------------------------------------------------------------+
    //| EA equivalent of indicator buffers                               |
    //+------------------------------------------------------------------+
    /*  Example 1:
     *  if (...) Ordermodify(...);
     *  Polyline("SL"+(ticket%99), SL, Color.SL, 0);
     *
     *  Example 2:
     *  double  ELineCurr = iMA(NULL,0, ELine.Length, 0, MODE_EMA, PRICE_CLOSE, 1);
     *  Polyline("ELine", ELineCurr, Color.ELine, 1);
     ******************************************************************************/
    #define POLYLINE_MAX 20 // Must match priceMM
    double  price00[], price01[], price02[], price03[], price04[],  // \   Export
            price05[], price06[], price07[], price08[], price09[],  //  \  from
            price10[], price11[], price12[], price13[], price14[],  //  |  Polyline
            price15[], price16[], price17[], price18[], price19[];  //  |
    int     LRU[POLYLINE_MAX];                                      //   > Import to
    string  lineName[POLYLINE_MAX];                                 // _/  PLHelper
    void Polyline(string name, double price, color clr, int shift){
        if (!Show.Objects)  return;
        for (int idx=0; idx < POLYLINE_MAX; idx++){     LRU[idx]++; }
        for (idx=0; idx < POLYLINE_MAX; idx++){
            bool new = lineName[idx] != name;   if (!new) break;    }
        if (new)    idx=ArrayMaximum(LRU);
        switch (idx){
        case  0: PLHelper(name, price, clr, idx, new, shift, price00); return;
        case  1: PLHelper(name, price, clr, idx, new, shift, price01); return;
        case  2: PLHelper(name, price, clr, idx, new, shift, price02); return;
        case  3: PLHelper(name, price, clr, idx, new, shift, price03); return;
        case  4: PLHelper(name, price, clr, idx, new, shift, price04); return;
        case  5: PLHelper(name, price, clr, idx, new, shift, price05); return;
        case  6: PLHelper(name, price, clr, idx, new, shift, price06); return;
        case  7: PLHelper(name, price, clr, idx, new, shift, price07); return;
        case  8: PLHelper(name, price, clr, idx, new, shift, price08); return;
        case  9: PLHelper(name, price, clr, idx, new, shift, price09); return;
        case 10: PLHelper(name, price, clr, idx, new, shift, price10); return;
        case 11: PLHelper(name, price, clr, idx, new, shift, price11); return;
        case 12: PLHelper(name, price, clr, idx, new, shift, price12); return;
        case 13: PLHelper(name, price, clr, idx, new, shift, price13); return;
        case 14: PLHelper(name, price, clr, idx, new, shift, price14); return;
        case 15: PLHelper(name, price, clr, idx, new, shift, price15); return;
        case 16: PLHelper(name, price, clr, idx, new, shift, price16); return;
        case 17: PLHelper(name, price, clr, idx, new, shift, price17); return;
        case 18: PLHelper(name, price, clr, idx, new, shift, price18); return;
        case 19: PLHelper(name, price, clr, idx, new, shift, price19); return;
    }   }
    void PLHelper( string name, double price, color clr, int idx, bool new
                 , int shift, double& mem[] ){
        datetime    t0  = Time[shift];  int firstBar = ArraySize(mem)-1;
        if (new){   t0 += 60*Period();      firstBar = -1;  lineName[idx]=name;
            static int      segNo[POLYLINE_MAX];    segNo[idx]++;
            static datetime time1[POLYLINE_MAX];    time1[idx] = Time[shift];   }
        LRU[idx] = 0;   string objName=name+"-"+segNo[idx];
        static datetime time0[POLYLINE_MAX];    if (new || t0 != time0[idx]){
            ArraySetAsSeries(mem, true);        // Shift values m[2]=m[1]; m[1]=m[0]
            firstBar=ArrayResize(mem, firstBar+2)-1;    if (firstBar < 0){  Alert(
                "ArrayResize failed: ",GetLastError());                     return;}
            ArraySetAsSeries(mem, false);
            time0[idx]=t0;      mem[0]=price;
        }
        /**/ if(ObjectMove(objName, 1, t0,          price))
                ObjectMove(objName, 0, time1[idx],  mem[firstBar]); // New or tmplt.
        else if (!ObjectCreate( objName, OBJ_TREND, WINDOW_MAIN
                              , time1[idx], mem[firstBar], t0,  price )){   Alert(
            "ObjectCreate(", objName, "Trend) [1] failed: ",GetLastError());return;}
        else if (!ObjectSet( objName, OBJPROP_COLOR, clr ))                 Alert(
            "ObjectSet(", objName, "Color) [3] failed: ",   GetLastError());
        else if (!ObjectSet( objName, OBJPROP_RAY, false ))                 Alert(
            "ObjectSet(", objName, "Ray) [1] failed: ",     GetLastError());
    
        double maxError=0;  int maxBar;
        for (int pos=1; pos < firstBar; pos++){
            double error=MathAbs(ObjectGetValueByShift(objName, pos+shift)-mem[pos]);
            if (error > maxError){  maxError=error; maxBar=pos; }
        }
        if (maxError >= pips2dbl){  // Split the line into two segments at the max.
            if (!ObjectMove(objName, 1, Time[shift+maxBar], mem[maxBar]))   Alert(
                "ObjectMove(", objName, "Trend) failed: ",  GetLastError());
            segNo[idx]++; objName=name+"-"+segNo[idx];
            ArrayResize(mem, maxBar+1); // Drop firstBar..(maxBar+1)
            time1[idx] = Time[shift+maxBar];
            /**/ if(ObjectMove(objName, 0, time1[idx],  mem[maxBar]))
                    ObjectMove(objName, 1, t0,          price);
            else if (!ObjectCreate( objName, OBJ_TREND, WINDOW_MAIN
                                  , time1[idx], mem[maxBar], t0, price )){  Alert(
                "ObjectCreate(", objName, "Trend) [2] failed: ",GetLastError()); }
            else if (!ObjectSet( objName, OBJPROP_COLOR, clr ))             Alert(
                "ObjectSet(", objName, "Color) [4] failed: ",   GetLastError());
            else if (!ObjectSet( objName, OBJPROP_RAY, false ))             Alert(
                "ObjectSet(", objName, "Ray) [3] failed: ",     GetLastError());
        }   // Split the line into two segments at the max.
    }   // PLHelper
    

 

See updated code https://www.mql5.com/en/forum/130907 Updated to allow color changes, external modification, deletion