Hi FP

 

 

What few MS users realize is that PREV can be eliminated when the variable
structure is the same as or very similar to S1 through S6. In these
variables PREV is equal to an already know value, so the known value can be
substituted for PREV. Depending on the number of bars loaded this code can
execute at least 50 times faster than the original; a more than worthwhile
gain under virtually any circumstances. The downside of using ValueWhen() as
a substitute for PREV is that the lead-in N/A period is generally going to
be longer.

 

Unfortunately, variables with more than one PREV are poor candidates for
this type of substitution.

 

{WSO}

 

S1:=If(Ref(L,-4)=LLV(L,9),Ref(L,-4), ValueWhen(1,Ref(L,-4)=LLV(L,9),
Ref(L,-4)));

S2:=If(S1=Ref(S1,-1), ValueWhen(1,S1<>Ref(S1,-1),Ref(S1,-1)), Ref(S1,-1));

S3:=If(S1=Ref(S1,-1), ValueWhen(1,S2<>Ref(S2,-1),Ref(S2,-1)), Ref(S2,-1));

S4:=If(S1=Ref(S1,-1), ValueWhen(1,S3<>Ref(S3,-1),Ref(S3,-1)), Ref(S3,-1));

S5:=If(S1=Ref(S1,-1), ValueWhen(1,S4<>Ref(S4,-1),Ref(S4,-1)), Ref(S4,-1));

S6:=If(S1=Ref(S1,-1), ValueWhen(1,S5<>Ref(S5,-1),Ref(S5,-1)), Ref(S5,-1));

WSO:=100*(1-(Int(S1/C)+Int(S2/C)+Int(S3/C)+Int(S4/C)+Int(S5/C)+Int(S6/C))/6)
;

Mov(WSO,30,E);

Mov(Mov(WSO,30,E),30,E);

Mov(WSO,81,E);

 

Regards

 

Roy

 

 

PS The PREV-free code above was modeled on some of the code you posted
recently on the MetaStock Forum. The only change I've made was to eliminate
6 PREVs from the "Sn" variables. 

 

 

  _____  

From: [email protected] [mailto:[email protected]]

Sent: Monday, 30 June 2014 2:31 p.m.
To: [email protected]
Subject: [EquisMetaStock Group] Mel Widner WRO WSO Automated Support
Resistance System

 

  

Mel Widner - "In my article "Automatic support and resistance" in this
issue, I present a computerized approach to finding support and resistance
levels on a chart. To recreate the indicators and system described in my
article using MetaStock for Windows, enter the following formulas:

Indicators:

S1: IF(Ref(LOW,-4)=LLV(LOW,9),Ref(LOW,-4),PREVIOUS) S2:
IF(Fml("S1")=Ref(Fml("S1"),-1),PREVIOUS,Ref(Fml("S1"),-1)) S3:
IF(Fml("S1")=Ref(Fml("S1"),-1),PREVIOUS,Ref(Fml("S2"),-1)) S4:
IF(Fml("S1")=Ref(Fml("S1"),-1),PREVIOUS,Ref(Fml("S3"),-1)) S5:
IF(Fml("S1")=Ref(Fml("S1"),-1),PREVIOUS,Ref(Fml("S4"),-1)) S6:
IF(Fml("S1")=Ref(Fml("S1"),-1),PREVIOUS,Ref(Fml("S5"),-1))

WSO:
100*(1?(Int(Fml("S1")/CLOSE)+Int(Fml("S2")/CLOSE)+Int(Fml("S3")/CLOSE)+Int(F
ml("S4")/CLOSE) +Int(Fml("S5")/CLOSE)+Int(Fml("S6")/CLOSE))/6)

R1: IF(Ref(HIGH,-4)=HHV(HIGH,9),Ref(HIGH,-4),PREVIOUS) R2:
IF(Fml("R1")=Ref(Fml("R1"),-1),PREVIOUS,Ref(Fml("R1"),-1)) R3:
IF(Fml("R1")=Ref(Fml("R1"),-1),PREVIOUS,Ref(Fml("R2"),-1)) R4:
IF(Fml("R1")=Ref(Fml("R1"),-1),PREVIOUS,Ref(Fml("R3"),-1)) R5:
IF(Fml("R1")=Ref(Fml("R1"),-1),PREVIOUS,Ref(Fml("R4"),-1)) R6:
IF(Fml("R1")=Ref(Fml("R1"),-1),PREVIOUS,Ref(Fml("R5"),-1))

WRO: 100*(1?(Int(Fml("R1")/CLOSE)+Int(Fml("R2")/CLOSE)
+Int(Fml("R3")/CLOSE)+Int(Fml("R4")/CLOSE)
+Int(Fml("R5")/CLOSE)+Int(Fml("R6")/CLOSE))/6)

The indicators S1 through S6 and R1 through R6 should be plotted as points
and not as a continuous line.

Trading System Formulas and Parameters: Enter long positions on either
building support or sustained uptrend and exit position using stops. No
short positions.

Enter Long: Fml("WSO") > Mov( Fml("WSO") , 4 , S ) OR Mov( Fml("WRO") , 30 ,
S ) > 95

Stop Out:

Breakeven stop: Floor level at 2%

Trailing stop: Profit risk of 10 Percent, ignoring 10 periods

Maximum loss stop: Maximum loss of 7%

Other Conditions:

Initial equity = 1000, Long positions only, Trade price = close, Trade delay
= 0, Entry commission = 0%, Exit commission = 0%, , Interest rate = 5%,
Margin req. 100%"


Code:


{WRO}

R1:=If(Ref(HIGH,-4)=HHV(HIGH,9),Ref(HIGH,-4),PREVIOUS); 

R2:=If(R1=Ref(R1,-1),PREVIOUS,Ref(R1,-1)); 

R3:=If(R1=Ref(R1,-1),PREVIOUS,Ref(R2,-1)); 

R4:=If(R1=Ref(R1,-1),PREVIOUS,Ref(R3,-1)); 

R5:=If(R1=Ref(R1,-1),PREVIOUS,Ref(R4,-1)); 

R6:=If(R1=Ref(R1,-1),PREVIOUS,Ref(R5,-1)); 

WRO:=100*(1-(Int(R1/CLOSE) + Int(R2/CLOSE) + 

Int(R3/CLOSE) + Int(R4/CLOSE) + 

Int(R5/CLOSE) + Int(R6/CLOSE))/6); 

WRO;

{WSO}

S1:=If(Ref(LOW,-4)=LLV(LOW,9),Ref(LOW,-4),PREVIOUS); 
S2:=If(S1=Ref(S1,-1),PREVIOUS,Ref(S1,-1)); 
S3:=If(S1=Ref(S1,-1),PREVIOUS,Ref(S2,-1)); 
S4:=If(S1=Ref(S1,-1),PREVIOUS,Ref(S3,-1)); 
S5:=If(S1=Ref(S1,-1),PREVIOUS,Ref(S4,-1)); 
S6:=If(S1=Ref(S1,-1),PREVIOUS,Ref(S5,-1)); 
WSO:=100*(1 - (Int(S1/CLOSE) + Int(S2/CLOSE) + 
Int(S3/CLOSE) + Int(S4/CLOSE) + 
Int(S5/CLOSE) + Int(S6/CLOSE))/6); 

WSO;

Mov(WRO,4,E);Mov(Mov(WRO,4,E),4,E);

Mov(WSO,30,E);Mov(Mov(WSO,30,E),30,E);

The above improved the results from the original article. Any improvement
suggestions are welcomed.

 



Reply via email to