Error

 Previous Topic Next Topic
 MrMcChart #1 Posted : Wednesday, July 20, 2022 8:01:06 AM(UTC) Rank: NewbieGroups: Registered, Registered Users, SubscribersJoined: 7/8/2021(UTC)Posts: 4Location: SydneyThanks: 2 times Sorry for the re-post on this 'no PREV' ATRTS formula, but I cannot find the original post. The standard ATRTS formula uses (7x PREV functions) and slows down the loading of charts and scanning for signals a lot, like 20 minutes to do a scan of 2700 stocks. The (no PREV) modified Trailing Stop formula (found somewhere on this forum as shown below) produces no result of output i.e. blank indicator panel. I have spent enough time going over to no avail. Could someone please take a look to assess if the formula functions correctly, if it does I might need to clarify the software I use that uses MetaStock for its base as there might be an issue there. And thanks in advance, I would love a faster ATRTS. Pd:=Input("ATR Periods",1,100,10); Factor:=Input("Factor",1.00,10.00,2.0); Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Tn:= Cross(C,LLV(Up,13)); Tp:= Cross(HHV(Dn,13),C); Td:=ValueWhen(1,Tp-Tn,Tn-Tp); Dxx:=HighestSince(1,Cross(Td,0),Dn); Dnx:=ValueWhen(1,Dn=Dxx,Dn); Upp:=LowestSince(1,Cross(0,Td),Up); Upx:=ValueWhen(1,Up=Upp,Up); ST:=ValueWhen(1,Td,If(Td=1,Dnx,Upx)); ST;Edited by user Wednesday, July 20, 2022 8:03:41 AM(UTC)  | Reason: Not specified
 Wanna join the discussion?! Login to your Discussions forum accountor Register a new forum account.
 MS Support #2 Posted : Wednesday, July 20, 2022 8:57:07 PM(UTC) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,842Thanks: 79 timesWas thanked: 148 time(s) in 144 post(s) Originally Posted by: MrMcChart Sorry for the re-post on this 'no PREV' ATRTS formula, but I cannot find the original post. The standard ATRTS formula uses (7x PREV functions) and slows down the loading of charts and scanning for signals a lot, like 20 minutes to do a scan of 2700 stocks. The (no PREV) modified Trailing Stop formula (found somewhere on this forum as shown below) produces no result of output i.e. blank indicator panel. I have spent enough time going over to no avail. Could someone please take a look to assess if the formula functions correctly, if it does I might need to clarify the software I use that uses MetaStock for its base as there might be an issue there. And thanks in advance, I would love a faster ATRTS. Code:``````Pd:=Input("ATR Periods",1,100,10); Factor:=Input("Factor",1.00,10.00,2.0); Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Tn:= Cross(C,LLV(Up,13)); Tp:= Cross(HHV(Dn,13),C); Td:=ValueWhen(1,Tp-Tn,Tn-Tp); Dxx:=HighestSince(1,Cross(Td,0),Dn); Dnx:=ValueWhen(1,Dn=Dxx,Dn); Upp:=LowestSince(1,Cross(0,Td),Up); Upx:=ValueWhen(1,Up=Upp,Up); ST:=ValueWhen(1,Td,If(Td=1,Dnx,Upx)); ````ST;```` Hello,I did a quick test of the formula you provided and it is definitely outputting values, so appears to be fully functional within MetaStock.
 MrMcChart #3 Posted : Thursday, July 21, 2022 12:59:11 AM(UTC) Rank: NewbieGroups: Registered, Registered Users, SubscribersJoined: 7/8/2021(UTC)Posts: 4Location: SydneyThanks: 2 times Thanks for the quick code test. My post was edited with carriage returns but were deleted in the published post, not sure why? I will send the code to the software administrators to see why their system of MetaStock does not produce an output. Thanks.
 MS Support #4 Posted : Thursday, July 21, 2022 2:17:23 PM(UTC) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,842Thanks: 79 timesWas thanked: 148 time(s) in 144 post(s) Originally Posted by: MrMcChart Thanks for the quick code test. My post was edited with carriage returns but were deleted in the published post, not sure why? I will send the code to the software administrators to see why their system of MetaStock does not produce an output. Thanks. Hi again,Unfortunately formulas don't end up formatted very well when just using line breaks. However, in the message editor, there is a {....} code button along the top. It is recommended that when you want to put a formula in a message to click this button and paste the formula into the dialogue box that appears (I did this when quoting your reply just to make the formula a bit easier to read).
 MrMcChart #5 Posted : Saturday, July 23, 2022 9:12:14 AM(UTC) Rank: NewbieGroups: Registered, Registered Users, SubscribersJoined: 7/8/2021(UTC)Posts: 4Location: SydneyThanks: 2 times Can't see the {...} not only formulas but 'all' text too. I have an interesting response back from the software administrators as follows: Td := ValueWhen(1,Tp-Tn,Tn-Tp); "There is a problem with this line, it will always produce a result of -1. Because of that the rest of the formula does not action and you get a null result. We are unsure of how Metastock is logically processing this formula."Edited by user Saturday, July 23, 2022 9:17:01 AM(UTC)  | Reason: Not specified
 MS Support #6 Posted : Monday, July 25, 2022 2:33:59 PM(UTC) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,842Thanks: 79 timesWas thanked: 148 time(s) in 144 post(s) Originally Posted by: MrMcChart Can't see the {...} not only formulas but 'all' text too. I have an interesting response back from the software administrators as follows: Td := ValueWhen(1,Tp-Tn,Tn-Tp); "There is a problem with this line, it will always produce a result of -1. Because of that the rest of the formula does not action and you get a null result. We are unsure of how Metastock is logically processing this formula." Hi again,I am not sure why you would not have the code button. As far as I am aware, everyone should have the same message editor. When you create a new message, you should have 3 lines at the top, Subject, Description, Message. To the right of message you should have a series of editor controls. The "code" button should be on the right-hand side of these.As for the ValueWhen statement above, I just did a simple test on a Daily chart of IBM. It is definitely returning values other than -1. Here is a brief sampling of the output from that variable:Code:``````5/26/2022    1 5/27/2022    1 5/31/2022    1 6/1/2022    1 6/2/2022    1 6/3/2022    1 6/6/2022    1 6/7/2022    1 6/8/2022    1 6/9/2022    1 6/10/2022    -1 6/13/2022    -1 6/14/2022    -1 6/15/2022    -1 6/16/2022    -1 6/17/2022    -1 6/21/2022    -1 6/22/2022    -1 6/23/2022    -1 6/24/2022    1 6/27/2022    1 6/28/2022    1 6/29/2022    1 6/30/2022    1 7/1/2022    1 7/5/2022    1 7/6/2022    1 7/7/2022    1 7/8/2022    1 7/11/2022    1 7/12/2022    1 7/13/2022    1 7/14/2022    1 7/15/2022    1 7/18/2022    1 7/19/2022    -1 7/20/2022    -1 7/21/2022    -1 7/22/2022    -1 7/25/2022    -1``````
 MrMcChart #7 Posted : Tuesday, July 26, 2022 12:39:29 PM(UTC) Rank: NewbieGroups: Registered, Registered Users, SubscribersJoined: 7/8/2021(UTC)Posts: 4Location: SydneyThanks: 2 times Ok, I have a work around...(Courtesy of the code-boffins at Share Wealth Systems)... for the original code that now produces an output as follows: Hi J, We're still not sure how MetaStock is computing this. Let's evaluate each line of the code. Particularly Tn, Tp & Td. Tn & Tp are both cross functions meaning they can only return a 1 (For True, when the cross happens) or a 0 (for false, no crossover). Td uses ValueWhen(), which is structured as follows: ValueWhen(n, Expression, Data Array). ... The ValueWhen function says give me the value of the Data Array on the date the nth most recent occurrence of the Expression was true. In our example Td := ValueWhen(1,Tp-Tn,Tn-Tp). This equates to, give me the value of Tn-Tp when Tp-Tn was last true (or Tp-Tn =1). The only way Tp-Tn can = 1 is if Tp = 1 and Tn = 0. (Remember these are both cross functions and can only return a 1 or 0) So if Tp-Tn = 1, then Tn-Tp must = -1. The output will always be -1... It appears what MetaStock is doing is using an Absolute Value for the expression in the ValueWhen() statement. I can't see why they are doing this. That is fundamentally flawed logic in my opinion. But nevertheless, here is a work around of the code so it produces the same output as MetaStock. Pd:=Input("ATR Periods",1,100,10); Factor:=Input("Factor",1,10,2); Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Tn:= Cross(C,LLV(Up,13)); Tp:= Cross(HHV(Dn,13),C); Td:=ValueWhen(1,ABS(Tp-Tn),Tn-Tp); Dxx:=HighestSince(1,Cross(Td,0),Dn); Dnx:=ValueWhen(1,ABS(Dn=Dxx),Dn); Upp:=LowestSince(1,Cross(0,Td),Up); Upx:=ValueWhen(1,ABS(Up=Upp),Up); ST:=ValueWhen(1,ABS(Td),If(Td=1,Dnx,Upx)); ST; Kind Regards, Vincent ...Edited by user Tuesday, July 26, 2022 12:44:49 PM(UTC)  | Reason: Not specified
 MS Support #8 Posted : Tuesday, July 26, 2022 2:47:22 PM(UTC) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,842Thanks: 79 timesWas thanked: 148 time(s) in 144 post(s) Originally Posted by: MrMcChart Ok, I have a work around...(Courtesy of the code-boffins at Share Wealth Systems)... for the original code that now produces an output as follows: Hi J, We're still not sure how MetaStock is computing this. Let's evaluate each line of the code. Particularly Tn, Tp & Td. Tn & Tp are both cross functions meaning they can only return a 1 (For True, when the cross happens) or a 0 (for false, no crossover). Td uses ValueWhen(), which is structured as follows: ValueWhen(n, Expression, Data Array). ... The ValueWhen function says give me the value of the Data Array on the date the nth most recent occurrence of the Expression was true. In our example Td := ValueWhen(1,Tp-Tn,Tn-Tp). This equates to, give me the value of Tn-Tp when Tp-Tn was last true (or Tp-Tn =1). The only way Tp-Tn can = 1 is if Tp = 1 and Tn = 0. (Remember these are both cross functions and can only return a 1 or 0) So if Tp-Tn = 1, then Tn-Tp must = -1. The output will always be -1... It appears what MetaStock is doing is using an Absolute Value for the expression in the ValueWhen() statement. I can't see why they are doing this. That is fundamentally flawed logic in my opinion. But nevertheless, here is a work around of the code so it produces the same output as MetaStock. Pd:=Input("ATR Periods",1,100,10); Factor:=Input("Factor",1,10,2); Up:=MP()+(Factor*ATR(Pd)); Dn:=MP()-(Factor*ATR(Pd)); Tn:= Cross(C,LLV(Up,13)); Tp:= Cross(HHV(Dn,13),C); Td:=ValueWhen(1,ABS(Tp-Tn),Tn-Tp); Dxx:=HighestSince(1,Cross(Td,0),Dn); Dnx:=ValueWhen(1,ABS(Dn=Dxx),Dn); Upp:=LowestSince(1,Cross(0,Td),Up); Upx:=ValueWhen(1,ABS(Up=Upp),Up); ST:=ValueWhen(1,ABS(Td),If(Td=1,Dnx,Upx)); ST; Kind Regards, Vincent ... Hi again,"In our example Td := ValueWhen(1,Tp-Tn,Tn-Tp). This equates to, give me the value of Tn-Tp when Tp-Tn was last true (or Tp-Tn =1)."I think this is probably where the confusion is. Tp-Tn is not a conditional statement. It's just a simple mathematical operation. Plugging it into ValueWhen({Nth},{Expression},{Data Array}) does not turn it into a conditional statement, so being "True" is not required for the expression.You can make a conditional statement out of this (I'm not sure that is recommended but I haven't really looked at the full logic of the formula) by adding a condition to the expression.Tp-Tn=1 would be a conditional statement.Tp-Tn is simply returning the value of one variable minus the other.
 Users browsing this topic
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.