5-Bar Run (Help)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #147182 quote
    April O’Neil
    Participant
    Average

    Hello,

    I need help to find error in the strategy bellow, the code do not enter position.

    here is strategy’s rules :

    • Wait for 5 bar down in a row
    • Confirm with RSI<10
    • Wait for doji
    • Take Profit in funtion of the entry price (50% of the downward move represented by the 5 precedents bars)

    Hourly or Daily Datas.

    //////////inputs
    minbarsdown = 5
    RSIthreshold = 10
    dojispan = 0.10
    proftarget = 0.50
    exitbars=5
    exitRSI=50
    count = 0
    n = 1
    
    ///////vars
    mom = RSI[14](close)
    doji = abs(open - close)/(high - low)
    
    
    if close > close[1] then
    count = count + 1
    elsif close < close[1] then
    count = 0
    endif
    
    
    //ENTRY
    if count >= minbarsdown and mom <= RSIthreshold and doji < dojispan then
    buy n shares at market
    SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
    endif
    
    //exit
    if longonmarket  and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
    sell n shares at market
    ENDIF
    
    #147191 quote
    robertogozzi
    Moderator
    Master

    Your code could be:

    //////////inputs
    minbarsdown = 5
    RSIthreshold = 10
    dojispan = 0.10
    proftarget = 0.50
    exitbars=5
    exitRSI=50
    n = 1
     
    ///////vars
    mom = RSI[14](close)
    doji = abs(open - close)/(high - low)
     
    //ENTRY
    if summation[5](close > close[1]) = minbarsdown and mom <= RSIthreshold and doji < dojispan then
       buy n shares at market
       SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
    endif
     
    //exit
    if longonmarket  and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
       sell n shares at market
    ENDIF

    using SUMMATION is simpler and faster.

    #147192 quote
    robertogozzi
    Moderator
    Master

    You wrote BARS DOWN, but actually your code (and mine) is counting BARS UP.

    If you want to scan bearish bars, you just need to replace “>” with “<” at line 15 with SUMMATION.

    #147197 quote
    April O’Neil
    Participant
    Average

    Thanks Roberto,

    But still doesn’t resolve the problem

    attached.png attached.png
    #147200 quote
    robertogozzi
    Moderator
    Master

    Parameters are too strict, when DOJI is < 0.10 MOM is never below 10 (in my test). Try to test it with a higher value for RSIthreshold.

    In my code you will be reported COUNT as not exixting. I don’t know what you are exactly using it for, but this is your original code with the addition of my solution:

    //////////inputs
    minbarsdown = 5
    RSIthreshold = 10
    dojispan = 0.10
    proftarget = 0.50
    exitbars=5
    exitRSI=50
    count = 0
    n = 1
     
    ///////vars
    mom = RSI[14](close)
    doji = abs(open - close)/(high - low)
     
     
    if close > close[1] then
    count = count + 1
    elsif close < close[1] then
    count = 0
    endif
     
     
    //ENTRY
    if summation[5](close > close[1]) = minbarsdown and mom <= RSIthreshold and doji < dojispan then
    buy n shares at market
    SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
    endif
     
    //exit
    if longonmarket  and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
    sell n shares at market
    ENDIF

    moreover, your stop loss will never be reached because it’s a price, not a difference between prices which is what LOSS requires, on DAX it would be ove 13000 pips!, you should compute a difference, such as abs(HIGH – TradePrice(1)) or the like.

    #147203 quote
    April O’Neil
    Participant
    Average

    Perfect, i spotted the problem,

    Thanks for your great help.

    Gonna work on it and post results if they give something of interest.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

5-Bar Run (Help)


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
April O'Neil @loyaso Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by April O’Neil
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/12/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...