Help required converting Metastock latch function

Forums ProRealTime English forum ProScreener support Help required converting Metastock latch function

Viewing 9 posts - 1 through 9 (of 9 total)
  • #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

    #19776

    Hi

    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

    #19778

    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.

    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:

    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):

    reset “result” to 0 if the fastMA cross under the supertrend:

    return this whole code to an indicator with this line:

    or a screener with this line instead:

    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.
    #19888

    Thanks 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 –

    To an experienced programmer it is probably very obvious what I am doing wrong.

    Thanks

    #19891

    Yes 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:

    Of course if you need to reset the “daycount” to 0, you can do it each time a new moving average cross is detected:

     

    1 user thanked author for this post.
    #19988

    Thanks 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

    #20002

    You can only get results of 1 condition or a whole set of conditions all equal to 1 (true):

    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:

    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.
    #20055

    Ok 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.

    #137584

    Hi,

    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!

Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login