Help required converting Metastock latch function
Forums › ProRealTime English forum › ProScreener support › Help required converting Metastock latch function
- This topic has 8 replies, 3 voices, and was last updated 4 years ago by
idefix2709.
-
-
12/20/2016 at 12:21 PM #18848
Hi
Trying to create an indicator that will “latch” and lock when a buy is triggered and will only unlock/reset when the sell is triggered.
A simple example would be a moving average cross over to buy, forcing the indicator value to 1 and then remain at 1 until a close under supertrend to sell would return the indicator value to zero.
The reason I want the indicator is to use the screener to find all “open trades”. I do not want a trade system, just an indicator.
The example metastock code in question is what I am trying to convert.
N:=Fml(“buy signal”);
X:=Fml(“sell signal”);
I:=Cum(N+X>-1)=1;
Tr:=BarsSince(I OR N)<BarsSince(I OR X);
Tr;ProrealTime code so far;
N= Call “my buy signal”
X= cross under supertrend(2,10))
I= cumsum(N+X>-1)=1
Tr:=BarsSince(I OR N)<BarsSince(I OR X);
Tr;The metastock code uses the cum function so I assume ProrealTime cumsum function is the same. But Prorealtime does not have a barssince function to use in indicators.
So that is where I am stuck.
Maybe I am going about this latch thing the wrong way. Is there another way this can be done with an indicator?
Any help appreciate.
Thanks
01/04/2017 at 9:08 AM #19776Hi
Still trying to get this to work. Another variation does not use the barssince function, but uses PREV instead. The PREV function seems to
refer to the previous value of the same variable – i think. Replacing PREV with ref(tr,-1) in metastock returns an N/A output if that is any help.
So, does ProrealCode have any way of dealing with this Prev command? (As in the new line that is highlighted).
N= Call “my buy signal”
X= cross under supertrend(2,10))
Tr:=If(N,1,If(X,0,PREV));
Tr;
Again any help appreciated.
Thanks
01/04/2017 at 9:30 AM #19778A simple example would be a moving average cross over to buy, forcing the indicator value to 1 and then remain at 1 until a close under supertrend to sell would return the indicator value to zero.
Hi, you’ll find below the code for this request, instead of converting the Metastock formula which is different from your example IMO..
First part, define the indicators you need:
1234// indicatorsfastMA = average[10](close)slowMA = average[50](close)st = supertrend[3,10]Second part, set the variable “result” to 1 when a bullish crossover is met (result will remain to 1 until you set it to 0 or whatever, yourself later in the code):
123if fastMA crosses over slowMA thenresult = 1endifreset “result” to 0 if the fastMA cross under the supertrend:
123if fastMA crosses under st thenresult = 0endifreturn this whole code to an indicator with this line:
1RETURN resultor a screener with this line instead:
1SCREENER [result]Didn’t test it myself, but should do the job, please let us know and give feedback here.
1 user thanked author for this post.
01/05/2017 at 4:52 AM #19888Thanks Nicolas.
Works a treat. So simple really. I should have been able to figure it out.
Now I have a indicator (binary) and screener that gives matching results when result = 1.
Now I am trying to sort the screener result in days since “result” last changed to 1. I have writen a loop to count the “days”/”bars” but
my effort so far gives some correct and some very wrong count of days since result =1. I have referred to the indicator and screener pdf manuals
but still can not get consistent and correct results. My little loop as follows –
1234once Days = 0IF result = 1 THENDays = Days + 1ENDIFTo an experienced programmer it is probably very obvious what I am doing wrong.
Thanks
01/05/2017 at 9:25 AM #19891Yes you are not doing a loop with this code. Loops are made with FOR/NEXT and WHILE/WEND.
What you are requesting now is just an increment of a variable if the condition is met on each new bar, you can code it as follows:
123456once daycount = 0IF result = 1 and savedate<>Date THENdaycount = daycount + 1savedate = DateENDIFOf course if you need to reset the “daycount” to 0, you can do it each time a new moving average cross is detected:
1234if fastMA crosses over slowMA thenresult = 1daycount = 0endif1 user thanked author for this post.
01/06/2017 at 1:45 AM #19988Thanks again Nicolas.
Works as requested. I should have done some “programming” tutorials etc as a young fella.
One last question. Can you output more than 1 variable to the screener result – sorted or not?
I have browsed the Proscreener reference manual and can not find an answer, either it confirming or not. All reference just refers to 1 “criteria” for sorting.
Again thank you very much for your assistance. Love the ProRealTime platform – just will take me a while to develop the skills to utilize all its features.
Regards
01/06/2017 at 9:40 AM #20002You can only get results of 1 condition or a whole set of conditions all equal to 1 (true):
1SCREENER [result1 and result2 and result2]About sorting the results, only 1 criteria column is possible, but you can populate the column with any numeric informations you’d like:
Let’s say you are doing different search into your screener, to retrieve different patterns for instance, you can give a new variable called “pattern” the numeric value of the fetched pattern:
123456789if result1 thenpattern = 1elsif result2 thenpattern = 2elsif result3 thenpattern = 3endifSCREENER [result1 OR result2 OR result3] (pattern as "Pattern number")So in this example, because we are using the OR condition between the 3 patterns, we have 3 screeners in the same code. Results are sorted with the information of what is the found pattern for all listed instruments in the criteria column.
EDIT: Thread moved to Proscreener support, since it is now more a proscreener related topic.
1 user thanked author for this post.
01/06/2017 at 2:57 PM #20055Ok Thanks
Shame you can only add 1 extra column to the screener output. Had idea to have a number of shares and open profit column to display at the same time.
Kind of like a mini portfolio holding statement. I suppose I could run separate screens to give each of my desired outputs – no big problem really.
06/29/2020 at 10:57 PM #137584Hi,
I’m starting to program and I would convert this screener line from metastock language :
(H-L) = (LLV(H-L,5)) AND (H < REF (H,-1) AND L> REF(L,-1)
Could you helm me?
Thanks in advance!
-
AuthorPosts
Find exclusive trading pro-tools on