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
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
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:
// indicators
fastMA = 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):
if fastMA crosses over slowMA then
result = 1
endif
reset “result” to 0 if the fastMA cross under the supertrend:
if fastMA crosses under st then
result = 0
endif
return this whole code to an indicator with this line:
RETURN result
or a screener with this line instead:
SCREENER [result]
Didn’t test it myself, but should do the job, please let us know and give feedback here.
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 –
once Days = 0
IF result = 1 THEN
Days = Days + 1
ENDIF
To an experienced programmer it is probably very obvious what I am doing wrong.
Thanks
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:
once daycount = 0
IF result = 1 and savedate<>Date THEN
daycount = daycount + 1
savedate = Date
ENDIF
Of course if you need to reset the “daycount” to 0, you can do it each time a new moving average cross is detected:
if fastMA crosses over slowMA then
result = 1
daycount = 0
endif
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
You can only get results of 1 condition or a whole set of conditions all equal to 1 (true):
SCREENER [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:
if result1 then
pattern = 1
elsif result2 then
pattern = 2
elsif result3 then
pattern = 3
endif
SCREENER [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.
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.
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!