Hello,
I would like to save an entry signal and count the bars from that signal to get another signal within 120 bars from the first signal. Cant seem to get it right.
If c1 and c2 then
buysignal = barindex
Endif
distancebuysignal=Barindex-buysignal
/// then the entry
if distancebuysignal <120 and c3 then
buy 1 contract at market
endif
Because you are not checking if there is a buysignal older than 120 bars in your condition at line 1.
If distancebuysignal >120 and c1 and c2 then
buysignal = barindex
Endif
distancebuysignal=Barindex-buysignal
/// then the entry
if distancebuysignal <120 and c3 then
buy 1 contract at market
endif
Thank you, is this the correct way to do it? Im just weeks in my PRT “programingskills” =)
Yes, but on the first run, ‘buysignal’ is equal to 0, so you’ll have to wait for 120 bars before getting the first signal! So just check if that variable is equal to 0 too:
If (distancebuysignal >120 OR buysignal=0) and c1 and c2 then
buysignal = barindex
Endif
distancebuysignal=Barindex-buysignal
/// then the entry
if distancebuysignal <120 and c3 then
buy 1 contract at market
endif
Thank you, that worked perfectly! Is there also a way to save “signalprice” and to have a close over that for buysignal or is it just possible for number of bars?
You can save any value into a variable:
if condition then
signalprice = close
endif
if othercondition and close crosses over signalprice then
buy at market
endif