Page 1 of 1

an indicator which shows a change of direction

Posted: 16 Apr 2014
by hendrix
Hi guys

I would create an indicator which show me when moving average changes direction.

For example : indicator=1 when moving average changes and going up
indicator=-1 when moving average is going down

I have written this code :

Code: Select all

Inputs: price(Close), length(10),
zeroLine(0.0), zeroVisible(false),
upColour(Green), downColour(Red), colourDeltaBar(1);

Variables: var0 (0) ;

var0 = jtHMA(price, length);

//when the average changes direction : (moving average is going down)
if var0[2] > var0[1] and var0[1] < var0 then
value2 = 1 ;

//when the average changes direction : (moving average is going up)
if var0[2] < var0[1] and var0[1] > var0 then
value2 = -1 ;

Plot1(Value2, "jtHMA");
I have posted a picture of this code here : http://www.heberger-image.fr/images/874 ... s.png.html

Anybody would have an idea please?

Re: an indicator which shows a change of direction

Posted: 16 Apr 2014
by TJ
Hi guys
I would create an indicator which show me when moving average changes direction.
::
Anybody would have an idea please?
First thing I can suggest to you is to avoid using generic variable names,
ie. var0, value1, value2, condition1, condition2, etc.,

You can give each variable a meaningful name, eg. jtHMA.dir, avg.dir, jtHMA.up, jtHMA.dn, etc.,
In the long run, it will save you lots of debugging time.

Re: an indicator which shows a change of direction

Posted: 17 Apr 2014
by hendrix
I revised the code like this :

Code: Select all

Inputs: price(Close), length(10),
zeroLine(0.0), zeroVisible(false),
upColour(Green), downColour(Red), colourDeltaBar(1);

Variables:
average_jtJMA (0) ,
indic (0) ;


//compute mobile average
average_jtJMA = jtHMA(price, length);

//when the average changes direction : (moving average is going down)
if average_jtJMA[2] > average_jtJMA[1] and average_jtJMA[1] < average_jtJMA then
indic = 1 ;

if indic[1] = 1 then
indic = 0 ;

//when the average changes direction : (moving average is going up)
if average_jtJMA[2] < average_jtJMA[1] and average_jtJMA[1] > average_jtJMA then
indic = -1 ;

if indic[1] = -1 then
indic = 0 ;


Plot1(indic, "change_direction");
you'll find a picture of this code here > http://www.heberger-image.fr/images/640 ... e.png.html

++

Re: an indicator which shows a change of direction

Posted: 17 Apr 2014
by TJ
Nice work. Thanks for sharing.

Here's my rendition; it runs slightly faster.

Code: Select all

Inputs: price(Close), length(10),
zeroLine(0.0), zeroVisible(false),
upColour(Green), downColour(Red), colourDeltaBar(1);

Variables:
average_jtJMA (0) ,
indic (0) ;


//compute mobile average
average_jtJMA = jtHMA(price, length);

//when the average changes direction : (moving average is going down)
if average_jtJMA[2] > average_jtJMA[1] and average_jtJMA[1] < average_jtJMA then
indic = 1

else

//when the average changes direction : (moving average is going up)
if average_jtJMA[2] < average_jtJMA[1] and average_jtJMA[1] > average_jtJMA then
indic = -1

else

indic = 0 ;

Plot1(indic, "change_direction");