How calculate a simple Angle ?

 

Hi ,

I would like to get the angle value bewteen last timeframe of J1 to current J1 ,the angle value should be from 90 to -90.

/--- buffers

double K[];

double D[];

double J[];

double J1[];

double RSV[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

extern int N=9;

extern int N1=3;

extern int M1=3;

extern int M2=3;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,K);

SetIndexStyle(1,DRAW_NONE);

SetIndexBuffer(1,D);

SetIndexStyle(2,DRAW_NONE);

SetIndexBuffer(2,J);

SetIndexStyle(3,DRAW_NONE);

SetIndexBuffer(3,RSV);

SetIndexStyle(4,DRAW_LINE);

SetIndexBuffer(4,J1);

SetLevelValue(1,10) ;

IndicatorShortName("KDJ1");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted=IndicatorCounted();

if(counted<0)return(-1);

if(counted>0)counted--;

int i=Bars-counted;

for(int m=0;m<i;m++)

{

RSV[m]=EMPTY_VALUE;

if(High-Low!=0)

RSV[m]=(Close[m]-Low)/(High-Low)*100;

}

for(m=0;m<i;m++)

{

K[m]=iMAOnArray(RSV,0,M1,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

D[m]=iMAOnArray(K,0,M2,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

J[m]=3*K[m]-2*D[m];

}

for(m=0;m<i;m++)

{

J1[m]=iMAOnArray(J,0,N1,0,MODE_EMA,m);

}

return(0);

}

Any help is very appreciate!!

Thanks

 

zhouyuwei

Take a look at this post for a possible solution : https://www.mql5.com/en/forum/173056/page3

zhouyuwei:
Hi ,

I would like to get the angle value bewteen last timeframe of J1 to current J1 ,the angle value should be from 90 to -90.

/--- buffers

double K[];

double D[];

double J[];

double J1[];

double RSV[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

extern int N=9;

extern int N1=3;

extern int M1=3;

extern int M2=3;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,K);

SetIndexStyle(1,DRAW_NONE);

SetIndexBuffer(1,D);

SetIndexStyle(2,DRAW_NONE);

SetIndexBuffer(2,J);

SetIndexStyle(3,DRAW_NONE);

SetIndexBuffer(3,RSV);

SetIndexStyle(4,DRAW_LINE);

SetIndexBuffer(4,J1);

SetLevelValue(1,10) ;

IndicatorShortName("KDJ1");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted=IndicatorCounted();

if(counted<0)return(-1);

if(counted>0)counted--;

int i=Bars-counted;

for(int m=0;m<i;m++)

{

RSV[m]=EMPTY_VALUE;

if(High-Low!=0)

RSV[m]=(Close[m]-Low)/(High-Low)*100;

}

for(m=0;m<i;m++)

{

K[m]=iMAOnArray(RSV,0,M1,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

D[m]=iMAOnArray(K,0,M2,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

J[m]=3*K[m]-2*D[m];

}

for(m=0;m<i;m++)

{

J1[m]=iMAOnArray(J,0,N1,0,MODE_EMA,m);

}

return(0);

}

Any help is very appreciate!!

Thanks
 

Thank you for your quick response, mladen.

To be honest I am not too familiar with MT4 coding, I just want to someone who can help me revise or append into my existence code.

 

zhouyuwei

Unfortunately the code you attached is simply not going to work so it is not just a matter of appending into existing code, and from the code itself it is not visible what is the exact "intention" of the code. What is exactly what you want to calculate with that code?

zhouyuwei:
Thank you for your quick response, mladen. To be honest I am not too familiar with MT4 coding, I just want to someone who can help me revise or append into my existence code.
 

Sorry, mladen !

I think missed some code.

I just re-paste the code as following:

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_color1 Green

#property indicator_color2 Yellow

#property indicator_color3 Blue

#property indicator_color4 Chocolate

#property indicator_color5 Red

//--- buffers

double K[];

double D[];

double J[];

double J1[];

double RSV[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

extern int N=9;

extern int N1=3;

extern int M1=3;

extern int M2=3;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_NONE);

SetIndexBuffer(0,K);

SetIndexStyle(1,DRAW_NONE);

SetIndexBuffer(1,D);

SetIndexStyle(2,DRAW_NONE);

SetIndexBuffer(2,J);

SetIndexStyle(3,DRAW_NONE);

SetIndexBuffer(3,RSV);

SetIndexStyle(4,DRAW_LINE);

SetIndexBuffer(4,J1);

IndicatorShortName("KDJ1");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted=IndicatorCounted();

if(counted<0)return(-1);

if(counted>0)counted--;

int i=Bars-counted;

for(int m=0;m<i;m++)

{

RSV[m]=EMPTY_VALUE;

if(High-Low!=0)

RSV[m]=(Close[m]-Low)/(High-Low)*100;

}

for(m=0;m<i;m++)

{

K[m]=iMAOnArray(RSV,0,M1,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

D[m]=iMAOnArray(K,0,M2,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

J[m]=3*K[m]-2*D[m];

}

for(m=0;m<i;m++)

{

J1[m]=iMAOnArray(J,0,N1,0,MODE_EMA,m);

}

return(0);

}

how to collect angle degree for yellow arrow in every timeframe ?

Files:
angle.png  5 kb
 

zhouyuwei

As you know, on time series we have 2 axes with 2 different types of values. on Y axes we have price or some value and on X axes we have time. The two values are not compatible and because of that you can calculate the angle. When the indicators values are "on chart" you can approximate time part with ATR (as it is done with angle of average) but with an indicator in a separate window you need to find out some other way of approximating X axis values

Or use simply a slope (current value - previous value = slope).

zhouyuwei:
Sorry, mladen !

I think missed some code.

I just re-paste the code as following:

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_color1 Green

#property indicator_color2 Yellow

#property indicator_color3 Blue

#property indicator_color4 Chocolate

#property indicator_color5 Red

//--- buffers

double K[];

double D[];

double J[];

double J1[];

double RSV[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

extern int N=9;

extern int N1=3;

extern int M1=3;

extern int M2=3;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_NONE);

SetIndexBuffer(0,K);

SetIndexStyle(1,DRAW_NONE);

SetIndexBuffer(1,D);

SetIndexStyle(2,DRAW_NONE);

SetIndexBuffer(2,J);

SetIndexStyle(3,DRAW_NONE);

SetIndexBuffer(3,RSV);

SetIndexStyle(4,DRAW_LINE);

SetIndexBuffer(4,J1);

IndicatorShortName("KDJ1");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted=IndicatorCounted();

if(counted<0)return(-1);

if(counted>0)counted--;

int i=Bars-counted;

for(int m=0;m<i;m++)

{

RSV[m]=EMPTY_VALUE;

if(High-Low!=0)

RSV[m]=(Close[m]-Low)/(High-Low)*100;

}

for(m=0;m<i;m++)

{

K[m]=iMAOnArray(RSV,0,M1,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

D[m]=iMAOnArray(K,0,M2,0,MODE_SMMA,m);

}

for(m=0;m<i;m++)

{

J[m]=3*K[m]-2*D[m];

}

for(m=0;m<i;m++)

{

J1[m]=iMAOnArray(J,0,N1,0,MODE_EMA,m);

}

return(0);

}

how to collect angle degree for yellow arrow in every timeframe ?
 

Yes, i just want to using simply a slope (current value - previous value) , but how to add them in my code ?

 

I suppose you want a slope on the "final" value, in which case you can do something like this (just the final loop changed a bit) :

for(m=i;m>=0;m--)

{

J1[m]=iMAOnArray(J,0,N1,0,MODE_EMA,m);

double slope = J1[m]-J1[m+1];

}

And you can do whatever you wish with the value stored in the slope variable in this case (it is containing the slope between the two consecutive values of J buffer)

zhouyuwei:
Yes, i just want to using simply a slope (current value - previous value) , but how to add them in my code ?
 

Thank you so much, man ! i figured out that value finally !