Count bars since given signal

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #128939 quote
    dnystrom
    Participant
    Average

    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
    #128999 quote
    Nicolas
    Keymaster
    Master

    Because you are not checking if there is a buysignal older than 120 bars in your condition at line 1.

    #129040 quote
    dnystrom
    Participant
    Average
    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” =)

    #129045 quote
    Nicolas
    Keymaster
    Master

    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
    dnystrom thanked this post
    #129125 quote
    dnystrom
    Participant
    Average

    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?

    #129209 quote
    Nicolas
    Keymaster
    Master

    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
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Count bars since given signal


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
dnystrom @dnystrom Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Nicolas
5 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/30/2020
Status: Active
Attachments: No files
Logo Logo
Loading...