logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joy55  
#1 Posted : Saturday, April 18, 2015 6:17:28 PM(UTC)
Joy55

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/2/2010(UTC)
Posts: 18

Hi All,

I am trying to build exploration formula of Super Trend for buy/sell.I searched in forum and googled but in vain.

Please some body help me to formulate Super Trend formula.

Super Trend code:-

Factor:=Input("Factor",1.00,

10.00,3.00);
Pd:=Input("ATR Periods",1,100,10);
Up:=MP()+(Factor*ATR(Pd));
Dn:=MP()-(Factor*ATR(Pd));
Td:=If(Cross(C,LLV(Up,13)),1,If(Cross(HHV(Dn,13),C ),-1,PREV));
Dnx:=If(Dn=HighestSince(1,Cross(Td,0),Dn),Dn,PREV) ;
Upx:=If(Up=LowestSince(1,Cross(0,Td),Up),Up,PREV);
ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV));
ST
Your help will be appreciated.

Thanks & Regards.

Joy55

 

 

 

mstt  
#2 Posted : Saturday, April 18, 2015 9:59:53 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Joy55 There are a couple of common ways to incorporate an indicator into an exploration. If you want to include the entire indicator code into an exploration column (or filter) you must remove the Input () functions and replace them with a constant (while using the original variable name). {Super Trend} Factor:=Input("Factor",1.00,10.00,3.00); Pd:=Input("ATR Periods",1,100,10); Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Td:=If(Cross(C,LLV(Up,13)),1,If(Cross(HHV(Dn,13),C ),-1,PREV)); Dnx:=If(Dn=HighestSince(1,Cross(Td,0),Dn),Dn,PREV) ; Upx:=If(Up=LowestSince(1,Cross(0,Td),Up),Up,PREV); ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV)); ST; This formula should be changed to... {Column A} {Super Trend} Factor:=3; Pd:=10; Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Td:=If(Cross(C,LLV(Up,13)),1,If(Cross(HHV(Dn,13),C ),-1,PREV)); Dnx:=If(Dn=HighestSince(1,Cross(Td,0),Dn),Dn,PREV) ; Upx:=If(Up=LowestSince(1,Cross(0,Td),Up),Up,PREV); ST:=If(Td=1,Dnx,If(Td=-1,Upx,PREV)); ST; However you do not need to use the entire formula in your exploration. Instead you can use the Fml() fuction to call the indicator. The exploration will then use the default values of any Input() function in the indicator. See below. {Column A} Fml("Super Trend"). Be aware that comments are placed inside braces {}. Also be aware that your version of Super Trend has 4 PREV functions, and this means that it will run quite slow as an exploration. A much faster version with PREV eliminated is shown below. {Super Trend} Factor:=Input("Factor",1,10,3); Pd:=Input("ATR Periods",1,200,10); Up:=MP()+(factor*ATR(Pd)); Dn:=MP()-(factor*ATR(Pd)); Cu:=Cross(C,LLV(Up,13)); Cd:=Cross(HHV(Dn,13),C); I:=Cum(IsDefined(Cd+Cu))=1; Td:=ValueWhen(1,Cu+Cd+I,Cu-Cd); I:=Cum(IsDefined(Cd+Cu))=2; Hs:=Dn=HighestSince(1,I+Cross(Td,0),Dn); Ls:=Up=LowestSince(1,I+Cross(0,Td),Up); Dnx:=ValueWhen(1,Hs,Dn); Upx:=ValueWhen(1,Ls,Up); SuperTrend:=If(Td=1,Dnx,Upx); SuperTrend; Hope this helps. Roy
Joy55  
#3 Posted : Sunday, April 19, 2015 8:55:48 AM(UTC)
Joy55

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/2/2010(UTC)
Posts: 18

Hi Roy,

Thank you for your prompt reply and guidance .I have copy& pested your formula into explorer in Filter Tab result shows all securities are selected it doe not show buy/sell securities And if I pest your formula in Tab A it shows under reject-Filter reference to empty col A.

I accept my inability to understand your solution to my query.Please guide how to put your formula into explorer to get buy/sell securities who have crossed the Super Trend.

Thanks & Regards.

Joy55

mstt  
#4 Posted : Sunday, April 19, 2015 10:04:53 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Joy55 OK, I can see why the Filter tab shows all results. The Filter tab filters in or out the logical state of whatever criteria you use as your filter. The Super Trend indicator is actually a trailing stop, and when prices are moving up it will follow that uptrend while sitting below the price. Once the price moves down and crosses below the Super Trend plot the indicator repositions above the price and follows it down.. However, note that while the Super Trend plot always always has a positive value, you need to extract a LOGICAL (TRUE or FALSE) value. MetaStock theoretically regards 1 (one) as a TRUE and 0 (zero) as a FALSE when making logical decisions. For the Filter tab to work as intended it should be presented with a TRUE or FALSE (1 or 0), but what you have done is to feed the Filter tab with a variable positive number rather than the required TRUE or FALSE. What you probably don't know is that, with the exception of the EST, all MetaStock tools treat ALL numerical values as a TRUE, even negative values. So the Super Trend result fed to the Filter tab effectively generates a TRUE for every bar of every security, and fails to reject any securities whatsoever. To generate Buy signal in columns, what you need to do is to test the price (normally CLOSE) for a Cross() above Super Trend. And to generate a Sell signal you need to test Super Trend for a Cross() above CLOSE. Here's how I might code the exploration to get Buy and Sell signals from the Super Trend indicator. By comparing price to the Super Trend indicator value you end up with a simple TRUE or FALSE at the point of crossover. The Cross() will mainly return a FALSE, but will return a TRUE when the crossover occurs. Note that the Cross () function only registers a crossover in one direction. To register a crossover in the other direction the two parameters must be switched as shown in the example below There's much more that could be said but lets see if you can digest what I've said so far before adding to the discussion. {ColA: Buy} Trail=Fml("Super Trend"); Cross(Trail,CLOSE); {ColB: Sell} Trail=Fml("Super Trend"); Cross(CLOSE, Trail); {Filter} ColA OR ColB; Roy
Joy55  
#5 Posted : Sunday, April 19, 2015 2:29:57 PM(UTC)
Joy55

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/2/2010(UTC)
Posts: 18

Hi Roy,

Thanks for your valued help.Frankly I have not understood fully.I have written in Tab A & B within breaket{ }your formula and pasted your second formula of Super Trend in the Filter Tab and colA OR colB. Results-No securities to report Reject-Filter reference to empty colA .If I put colA OR colB in Filter Tab in bracket than it select all the securities without buy/sell.

I checked 50 securities in Super Trend Templet, only two have cross Super Trend and closed below it on 17-4-15. I have set this date for scanning in explorer but not getting the result.Please let me know where I make mistakes.

Your guidance will be appreciated.

Regards.

Joy55 

 

mstt  
#6 Posted : Sunday, April 19, 2015 7:39:33 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Joy55

Braces {} are treated quite differently than brackets () in MetaStock. Braces are used for creating comments within MetaStock. Placing braces around sections of code or complete formulas effectively makes the code invisible to MetaStock and it is ignored. Brackets, on the other hand, do have an active role in MetaStock formulas.

{ColA: Buy}, {ColB: Sell} and {Filter} are all comments. They are not essential in any MetaStock formula, and play no active part. They simply inform the reader where to place the code when copying it from an article, document (or whatever) into MetaStock.

I trust I've not added to your confusion.

Roy

PS:  I've just realized that the Super Trend indicator isn't based strictly on the CLOSE, so using the CROSS() function in your exploration isn't going to tally exactly with Super Trend crosses above or below particular price points. I have  substitute that might not be 100% accurate under all user settings but will certainly be an improvement over my initial suggestion.

{ColA: Buy}
Trail=Fml("Super Trend");
Cross(Trail,HIGH);

{ColB: Sell}
Trail=Fml("Super Trend");
Cross(LOW,Trail);

{Filter}
ColA OR ColB; 

 

Edited by user Monday, April 20, 2015 12:22:49 AM(UTC)  | Reason: Additional information

Joy55  
#7 Posted : Monday, April 20, 2015 7:52:27 AM(UTC)
Joy55

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/2/2010(UTC)
Posts: 18

Hi Roy,

Thanks for your guidance and reply. 

In Tab A I get this For Trail"This is not a recognized name, constant or operator."

Regards.

Joy55

mstt  
#8 Posted : Monday, April 20, 2015 8:21:36 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Joy55 Sorry, I missed out the colons when defining the "Trail" variable. Should have tested it first. I've tested the corrected version below and it works. Another problem that can catch people out is a misspelled indicator name inside the Fml() or FmlVar() functions. Roy {ColA: Buy} Trail:=Fml("Super Trend"); Cross(Trail,HIGH); {ColB: Sell} Trail:=Fml("Super Trend"); Cross(LOW,Trail); {Filter} ColA OR ColB;
Joy55  
#9 Posted : Tuesday, April 21, 2015 4:03:09 AM(UTC)
Joy55

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/2/2010(UTC)
Posts: 18

Hi Roy,

Thanks for your untiring efforts. Now it works and gives buy/sell results But as you said earlier it is not totally based on close so the result is not 100% accurate but it gives satisfactory result. 

Thanks & Regards.

Joy55

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.