Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
From http://www.metastocktools.com/#metastock :
[code:1:36ed8e009d]
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formula between "---8<---" lines.
===================================
Nth Highest/Lowest indicator values
===================================
---8<------------------------------
{ ©Copyright 2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }
{ User input }
Nth:=Input("Nth Highest/Lowest indicator values [1~8, 0=all]",0,8,0);
{ Indicator example }
x:=RSI(14);
{ Highest/Lowest values }
Hi1:=Highest(x);
Lo1:=Lowest(x);
{ 2~8 highest values }
Hi2:=Highest(If(x<Hi1,x,Lo1));
Hi3:=Highest(If(x<Hi2,x,Lo1));
Hi4:=Highest(If(x<Hi3,x,Lo1));
Hi5:=Highest(If(x<Hi4,x,Lo1));
Hi6:=Highest(If(x<Hi5,x,Lo1));
Hi7:=Highest(If(x<Hi6,x,Lo1));
Hi8:=Highest(If(x<Hi7,x,Lo1));
{ 2~8 lowest values }
Lo2:=Lowest(If(x>Lo1,x,Hi1));
Lo3:=Lowest(If(x>Lo2,x,Hi1));
Lo4:=Lowest(If(x>Lo3,x,Hi1));
Lo5:=Lowest(If(x>Lo4,x,Hi1));
Lo6:=Lowest(If(x>Lo5,x,Hi1));
Lo7:=Lowest(If(x>Lo6,x,Hi1));
Lo8:=Lowest(If(x>Lo7,x,Hi1));
{ Choose Nth highest value }
Hi:=
If(Nth=2,Hi2,
If(Nth=3,Hi3,
If(Nth=4,Hi4,
If(Nth=5,Hi5,
If(Nth=6,Hi6,
If(Nth=7,Hi7,
If(Nth=8,Hi8,
Hi1)))))));
{ Choose Nth lowest value }
Lo:=
If(Nth=2,Lo2,
If(Nth=3,Lo3,
If(Nth=4,Lo4,
If(Nth=5,Lo5,
If(Nth=6,Lo6,
If(Nth=7,Lo7,
If(Nth=8,Lo8,
Lo1)))))));
{ Plot in own window }
x;
If(Nth=0,Hi1,Hi);
If(Nth=0,Hi2,Hi);
If(Nth=0,Hi3,Hi);
If(Nth=0,Hi4,Hi);
If(Nth=0,Hi5,Hi);
If(Nth=0,Hi6,Hi);
If(Nth=0,Hi7,Hi);
If(Nth=0,Hi8,Hi);
If(Nth=0,Lo1,Lo);
If(Nth=0,Lo2,Lo);
If(Nth=0,Lo3,Lo);
If(Nth=0,Lo4,Lo);
If(Nth=0,Lo5,Lo);
If(Nth=0,Lo6,Lo);
If(Nth=0,Lo7,Lo);
If(Nth=0,Lo8,Lo)
---8<------------------------------
[/code:1:36ed8e009d]
jose '-)
http://www.metastocktools.com
.
|