put indicator into EA

 

Dear Community.


At first let me thank you for all those helping hands posts of other topics which made me learn a lot here.

 

Iam using following "simple" indicator in MT4

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double Buf_0[],Buf_1[];

int init() {
  
        SetIndexBuffer(0,Buf_0);
        SetIndexStyle (0,DRAW_LINE,STYLE_DASHDOT,1);
        SetIndexBuffer(1,Buf_1);
        SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1);

        return;
}

int start(){

        int     Counted_bars=IndicatorCounted(),i=Bars-Counted_bars-1;
        while(i>=1) {
                Buf_0[i]=my_func( 0, 14, Open[i] ) ;         //      Buffer Line_1
                Buf_1[i]=my_func( 1, 28, Open[i] ) ;         // Buffer Line_2
                i--;
        }

        return;
}


double my_func(int ind_0 ,double zz_val, double value_2) {

  //calculations here
  result=value_2 + zz_val ;

  return(result) ;

}

 

I want the "drawings" made inside my ea. So if i change values it recalculates the history_data

So both, optic and ea behavior are matching. I tried so simply adopt this buffer arrays into my ea, which leads into "Array out of range".

Is there an Easy way to get this done?  It should take action on new bar creation. Inside existing EA there is allready an logic wich does only once per bar:

last_bars = Bars; and if (last_bars != Bars){....}


Thanks!

derdigge 

 
WHRoeder:
  1. Post the real code because that won't compile

  2. Why are your buffer values dependent on future values?
  3. Do your lookbacks correctly.

 

Sorry its an verry big function my_func. That dosent matter here it returns valid numbers 

on 1. Fixed that. compile error.

on 2. > because i am an Idiot ;)

on 4. Thats not what i want to do. I just want to draw these two lines in the fly while ea is working without having this inside an seperate indicator.

 

i simply want to draw two lines by the values my_func is giving me.

 

Thanks for Your help Sir! 

 
  1. Post the real code because that won't compile
    double my_func(int ind_0 ,double zz_val, double value_2) {
      result=Close[i-1] + zz_val No such variable "i" 
      return(result) ;           'return' semicolon expected
    }

  2. Why are your buffer values dependent on future values?
  3. Do your lookbacks correctly.
  4. I tried so simply adopt this buffer arrays into my ea, which leads into "Array out of range".Is there an Easy way to get this done?
    Don't do that. Just get the value of the indicator. Detailed explanation of iCustom - MQL4 forum
Reason: