[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Switching MAs according to the position of the Close.



PureBytes Links

Trading Reference Links

/*
Switching MAs according to the position of the Close.

In my code,
if the close is below yesterdays 20MA of the lows
I want to use the 20MA of the highs,
[ MA(H,20) ]
until a close above the 20MA of the highs,
then I want to switch to the 20MA of the lows.
[ MA(L,20) ]

I am using:
*/
//==================================================================

Designated_MA_Value=IIf(Close< Ref(MA(L,20),-1),  1,
                    IIf(Close> Ref(MA(H,20),-1), -1,
                                                  0));
								
Held_MA_Choice= ValueWhen(Designated_MA_Value !=0, 
                          Designated_MA_Value);

Current_Held_MA= IIf(Held_MA_Choice=  1, MA(H,20), 
                 IIf(Held_MA_Choice= -1, MA(L,20), 
                                               0 ));
				   
//====================================================================

/*
But the switch does *not* occur.
If I plot the 'Current_Held_MA'
against the 20MA of the Highs and
against the 20MA of the Lows
the graph shows the 'Current_Held_MA'
*always* only at the highs !
eg:
*/

//====================================================================

Plot( Current_Held_MA, "",  colorGreen, styleStaircase );

//=====HI + LO MAs==================================================

Upr20maBnd = Ref( MA( H, 20), -1);
Lwr20maBnd = Ref( MA( L, 20), -1);

Plot( Upr20maBnd , "", colorGreen, styleLine );
Plot( Lwr20maBnd , "", colorGreen, styleLine );

//====================================================================

Plot( Close, "", colorBlue, styleBar+ styleThick);

//====================================================================

/*
And when I run the code in AA
the results are always the same results 
as if only the 20MA of the High were used.

How can I make the switch occur ?
*/


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.28/672 - Release Date: 2/6/2007 10:22 AM