PDA

View Full Version : Codeing help


gsandral
16th March 2007, 02:23 PM
I’m looking to assign a value to “factor” in Metastock, but require the “factor” to change depending on the level volatility experienced, hence I would like to code the following in MetaStock

IF volatility < 1.6 then factor =1
IF volatility > 1.6 and < 2 then factor =1.1
IF volatility > 2.0 then factor = 1.2

Where volatility=ATR(3)/ATR(100)

So factor will be 1.0, 1.1, or 1.2 depending on the level of volatility.

Any help would be appreciated

Regards Graeme

Jose
19th March 2007, 09:44 AM
You've practically already coded it yourself, Graeme.

---8<----------------------------

plot:=Input("plot: [1]Factor, [2]Volatility",1,2,1);

volatility:=ATR(3)/ATR(100);
factor:=
If(volatility<1.6,1,
If(volatility<2,1.1,1.2));

{plot}
If(plot=1,factor,volatility)

---8<----------------------------


I would do it this way, though:

---8<----------------------------

plot:=Input("plot: [1]Factor, [2]Volatility",1,2,1);

volatility:=ATR(3)/ATR(100);
factor:=Int((volatility/2+.2)*10+.5)/10;

{plot}
If(plot=1,factor,volatility)

---8<----------------------------


jose '-)

gsandral
29th March 2007, 02:57 AM
Thanks for that Jose :)