Finding the intersection point

 
Hi,
I have fond the following indicator:

#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_color1 DodgerBlue
#property indicator_color2 Lime
#property indicator_buffers 2

extern int MoMPeriod = 14;
extern int MaType = MODE_EMA;
extern int MaPeriod = 50;
extern int TimeFrame = 60;

double mom[],
       ema[],
       momTF[],
       emaTF[];
       
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   
   SetIndexBuffer(0,mom);
   SetIndexBuffer(1,ema);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(2,momTF);
   SetIndexBuffer(3,emaTF);
   
   IndicatorShortName("MTF Momentum "+tf());
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
     int bbshift,limit,limitTF;
     limit=Bars;
     limitTF = iBars(Symbol(),TimeFrame);
     
     for(int i=0; i<limitTF; i++) momTF[i] = iMomentum(Symbol(),TimeFrame,MoMPeriod,PRICE_CLOSE,i);
     for(int j=0; j<limitTF; j++) emaTF[j] = iMAOnArray(momTF,0,MaPeriod,0,MaType,j);
     
     for(int t=0; t<limit; t++)
     {
         bbshift = iBarShift(Symbol(),TimeFrame,Time[t]);
         mom[t] = momTF[bbshift];
         ema[t] = emaTF[bbshift];
     }

//----
   return(0);
  }  

But I can't get the intersection point from this two lines with my ea, even I can't get the right value from the indicator, which is displayed.

I can calculate the normal Momentum-value with the indicator function, but how could I calculate the real value over the momTF-Array in my ea?


 
indicator_buffers 2

Did you try iCustom ??

and if so how did you use that function inside your EA for this indicator ??

 

I tried this in my ea, but the values were wrong:

double x1= iCustom(NULL,0,"MOM_EMA_MTF",14,MODE_EMA,50,60,0,0);     
double x2=iCustom(NULL,0,"MOM_EMA_MTF",14,MODE_EMA,50,60,0,10);
double y1=iCustom(NULL,0,"MOM_EMA_MTF",14,MODE_EMA,50,60,1,0);
double y2=iCustom(NULL,0,"MOM_EMA_MTF",14,MODE_EMA,50,60,1,10);
 
sunshineh:

I tried this in my ea, but the values were wrong:

You are using iCustom correctly,

but you can make your problem more clear if you show this with picture of the chart attached the indicator

(momentum with calculated average momentum) and the values you read in your EA

I think the problem is you are calculating values of bar 0 This is changing every tick.

Also iMAOnArray(momTF,0,MaPeriod,0,MaType,j); is that way not a constant value

and why do you compare value bar 0 with the value of bar 10.

Wouldn't it be the intersection will happen in two following bars ??

 

Is it possible to calculate the iMAOnArray-Value in my ea?

The part with the momentum-indicator can I calculate in my ea. My problem is only the moving average of the momentum results.

I also tried the bar 10 for testing. for intersection I wanted to use bar 1 and 2.

 
momTF[i] = iMomentum(Symbol(),TimeFrame,MoMPeriod,PRICE_CLOSE,i);

The "i" on the left is a bar on the current chart. The "i" on the right is a bar on the TimeFrame chart. Apples and oranges.

What you have is meaning less unless the TF of the chart matches TimeFrame's value. Look in the codebase for MTF indicators.

 

Hi,

thank you for your answer.

But the two buffers mom and ema are drawn on my current chart and I can see the values in the data-window. Why can't I get them and why they are different from my read values with iCustom?

Do I have to change the code from the indicator??

Reason: