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

[Metastockusers] Projecting indicator direction into the future, v4.0



PureBytes Links

Trading Reference Links

And here is a centered Mov Avg version with future projection 
channels:


=============
MA - centered
=============
---8<--------------------------

{ Centered Moving Average v4.0 }
{ Uses forward-referencing to
   center Mov Avg and project future direction.}
{ Uses hindsight - do not trade! }

{ ©Copyright 2005 Jose Silva
  For personal use only.
  http://www.metastocktools.com }

{ User inputs }
fwPds:=Input("Forward-referencing periods  (automatic = -1)",-1,2600,-
1);
proj:=Input("Project last known MA:  [1]Direction,  [2]Value",1,2,1);
pds:=Input("Mov Avg periods",1,2600,21);
channel:=Input("Channel +/- boundary %",
 0,1000,5)/100;
type:=Input("[1]EMA [2]SMA [3]TmSr [4]Tri [5]Var [6]Vol [7]Wght",1,7,
2);

{ Choose MovAvg type:
  1 - Exponential MA
  2 - Simple MA
  3 - Time Series MA
  4 - Triangular MA
  5 - Variable MA
  6 - Volume adjusted MA
  7 - Weighted MA }
ma:=
 If(type=1,Mov(C,pds,E),
 If(type=2,Mov(C,pds,S),
 If(type=3,Mov(C,pds,T),
 If(type=4,Mov(C,pds,TRI),
 If(type=5,Mov(C,pds,VAR),
 If(type=6,Mov(C,pds,VOL),
 Mov(C,pds,W)))))));

{ Automatic period-centering }
center:=LastValue(If(fwPds<0,Int(pds/2),fwPds));

{ Forward-referenced MovAvg }
fwd:=Ref(ma,center);

{ Last valid MovAvg plot point }
valid:=Cum(IsDefined(fwd))
 =LastValue(Cum(IsDefined(fwd)));
valid:=valid AND Alert(valid=0,2);

{ Extend last MovAvg plot to future null zone }
xtend:=LastValue(fwd+PREV-PREV);

{ Restrict invalid initial MovAvg plot }
movAvg:=Ref(Ref(xtend,pds-1),-pds+1);

{ Last MA known direction & future projection }
init:=Cum(IsDefined(movAvg))=1;
direction:=movAvg+
 If(IsUndefined(fwd),
  ValueWhen(1,init OR valid,movAvg)-
  ValueWhen(1,init OR valid,Ref(movAvg,-1)),0)
 *BarsSince(init OR valid);

{ Choose Centered MovAvg type }
CMA:=If(proj=1,direction,movAvg);

{ Plot MovAvg on price chart }
If(BarsSince(valid),CMA,CMA)*(1+channel);
If(BarsSince(valid),CMA,CMA)*(1-channel);
CMA

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


Jose '-)
http://www.metastocktools.com





--- In Metastockusers@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxxx> 
wrote:
> Here's a concept I've thought about whilst on holidays:
> 
> Forward reference (shift backwards on charts) and center a Moving 
> Average, then extend and project the last known MA direction into
> the future.
> 
> This method gets around the no-plot in null (N/A) zone limitation in 
> MetaStock, and can apply to any indicator or oscillator on charts or 
> separate windows.
> 
> 
> MetaStock -> Tools -> Indicator Builder -> New ->
> Copy and paste complete formula between "---8<---" lines.
> 
> =============
> MA - centered
> =============
> ---8<--------------------------
> 
> { Centered Moving Average - v3.0 }
> { Uses forward-referencing to center Mov Avg
>   and project future direction.}
> { Uses hindsight - do not trade! }
> 
> { ©Copyright 2005 Jose Silva
>   For personal use only.
>   http://www.metastocktools.com }
> 
> { User inputs }
> fwPds:=Input("Forward-referencing periods  (automatic = -1)",-1,
> 2600,-1);
> proj:=Input("Project last known MA:  [1]Direction,  [2]Value",1,2,1
> );
> pds:=Input("Mov Avg periods",1,2600,21);
> type:=Input("[1]EMA [2]SMA [3]TmSr [4]Tri [5]Var [6]Vol [7]Wght",1,
> 7,2);
> 
> { Choose MovAvg type:
>   1 - Exponential MA
>   2 - Simple MA
>   3 - Time Series MA
>   4 - Triangular MA
>   5 - Variable MA
>   6 - Volume adjusted MA
>   7 - Weighted MA }
> ma:=
>  If(type=1,Mov(C,pds,E),
>  If(type=2,Mov(C,pds,S),
>  If(type=3,Mov(C,pds,T),
>  If(type=4,Mov(C,pds,TRI),
>  If(type=5,Mov(C,pds,VAR),
>  If(type=6,Mov(C,pds,VOL),
>  Mov(C,pds,W)))))));
> 
> { Automatic period-centering }
> center:=LastValue(If(fwPds<0,Int(pds/2),fwPds));
> 
> { Forward-referenced MovAvg }
> fwd:=Ref(ma,center);
> 
> { Last valid MovAvg plot point }
> lastVal:=IsUndefined(fwd)
>  AND Alert(IsUndefined(fwd)=0,2);
> 
> { Extend MovAvg plot into future null zone }
> xtend:=LastValue(fwd+PREV-PREV);
> 
> { Restrict invalid initial MovAvg plot }
> movAvg:=Ref(Ref(xtend,pds-1),-pds+1);
> 
> { Last MA known direction & future projection }
> init:=Cum(IsDefined(movAvg))=1;
> direction:=movAvg+
> ( ValueWhen(1,init OR lastVal,Ref(movAvg,-1))
>  -ValueWhen(1,init OR lastVal,Ref(movAvg,-2)))
>  *(BarsSince(init OR lastVal)+1);
> 
> { Plot MovAvg on price chart }
> If(proj=1,direction,movAvg)
> 
> ---8<--------------------------
> 
> 
> jose '-)
> http://www.metastocktools.com




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Help tsunami villages rebuild at GlobalGiving. The real work starts now.
http://us.click.yahoo.com/njNroD/KbOLAA/cosFAA/zMEolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/Metastockusers/

<*> To unsubscribe from this group, send an email to:
    Metastockusers-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/