Pro back-testing bullish / bearish heikin-ashi simple signal / variable

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #199923 quote
    jonpt88
    Participant
    New

    Dear all,

    Apologies, first of all, for my ignorance in this subject:

    I am trying to simply combine the bullish heikin-ashi (green candle) closure with one moving average overcrossing (for longs) and a bearish heikin-ashi (red candle) clousure with moving average undercrossing (for bearish). The application does not have the variables to back-test on the basis of such condition of a heikin-ashi signal (bullish or bearish signal -first green or red candle) – (case by case). Hence, I would like to ask if any of you could be so kind to let me know how would the variable in the backtesting code should read to that effect. Thank you very much in advance.

    #199924 quote
    jonpt88
    Participant
    New

    Apologies for the second post in a row (unfortunately I could not amend the previous one, sorry for this).

    Meanwhile, I found a previous topic dealing partly with my question (pending to be answered; how to combine heikin-ashi with crossing (over and/or under a simple moving average): https://www.prorealcode.com/topic/heikin-ashi-auto-buy-sell-based-on-collor-change/

    Based on that information I came up with the below “back test code” for the SP500 but it is not showing any results when I ask the application to generate the report, (I must be missing something due to my ignorance):

    // Festlegen der Code-Parameter
    DEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviert
    
    // Heikin Ashi setup
    once xOpen = open
    xClose = (open + close + high + low) / 4
    if barindex > 0 then
    xOpen = (xOpen + xClose[1]) / 2
    endif
    xLow = min(low,min(xClose,xOpen))
    xHigh = max(high,max(xClose,xOpen))
    //
    Bullish = xClose > xOpen
    Bearish = xClose < xOpen
    
    // Bedingungen zum Einstieg in Long-Positionen
    indicator1 = CALL Average[50](close) 
    c1 = (Bullish AND Bearish[1]CROSSES OVER indicator1)
    IF C1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // exit LONG trade on a Bearish candlestick
    indicator1 = CALL Average[50] (close)
    c2 = (Bearish CROSSES UNDER indicator1)
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    
    // Heikin Ashi setup
    once xOpen = open
    xClose = (open + close + high + low) / 4
    if barindex > 0 then
    xOpen = (xOpen + xClose[1]) / 2
    endif
    xLow = min(low,min(xClose,xOpen))
    xHigh = max(high,max(xClose,xOpen))
    //
    Bullish = xClose > xOpen
    Bearish = xClose < xOpen
    
    // SHORT trades when switching from bullish to bearish
    indicator1 = CALL Average[50] (close)
    c3 = (Bearish AND Bullish [1] CROSSES UNDER indicator1)
    IF c3 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // exit SHORT trade on a Bullish candlestick
    indicator1 = CALL Average[50] (close)
    c4 = (Bullish CROSSES UNDER indicator1)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    #199927 quote
    JS
    Participant
    Senior
    1. Delete the Call instructions
    2. Bullish = xClose > xOpen is always equal to 1 or 0 and a 1 or a zero cannot cross with an average. Use “xClose crosses over indicator1”
    3. Same for Bearish
    jonpt88 thanked this post
    #199991 quote
    jonpt88
    Participant
    New

    Thank you for your reply.

    May you be so kind to repost the code with the recommended amendments / corrections for my easier guidance. Thank you in advance.

    #199996 quote
    JS
    Participant
    Senior
    Hi @jonpt88

    When you use 1 moving average and you want to go both long and short, your base code is limited to:

    (xClose = (Open + Close + High + Low) / 4)

    If xClose crosses over Average[50](Close) then

    Buy 1 contract at Market

    EndIf

    If xClose crosses under Average[50](close) then

    SellShort 1 contract at Market

    EndIf

    jonpt88 thanked this post
    #199997 quote
    jonpt88
    Participant
    New
    Thank you.
    #200975 quote
    jonpt88
    Participant
    New
    Is there anyway to add to the back test a third variable? What would be the continuation of the CODE if I may ask? Thank you.
    #200976 quote
    JS
    Participant
    Senior

    Hi @jonpt88

    What do you want to do with that third variable?

    What feature do you want to add?

    jonpt88 thanked this post
    #201224 quote
    jonpt88
    Participant
    New
    Hi, a simple RSI. There must a code to allow back test to be subject to overbought / oversold umm
    #201232 quote
    JS
    Participant
    Senior

    Hi @jonpt88

    I have modified your first code, Heikin Ashi + Moving Average

    You can now back test the code

    For optimization, you can run the period of the Moving Average, for example, between 1 and 100
    // Festlegen der Code-Parameter
    DEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviert
    
    Once n=16
    
    // Heikin Ashi setup
    once xOpen = open
    xClose = (open + close + high + low) / 4
    if barindex > 0 then
    xOpen = (xOpen + xClose[1]) / 2
    endif
    xLow = min(low,min(xClose,xOpen))
    xHigh = max(high,max(xClose,xOpen))
    //
    Bullish = xClose > xOpen
    Bearish = xClose < xOpen
     
    // Bedingungen zum Einstieg in Long-Positionen
    indicator1 = Average[n](close)
    c1 = (Bullish AND Bearish[1]) and xClose Crosses Over indicator1
    IF C1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
     
    // exit LONG trade on a Bearish candlestick
    c2 = (Bearish and xClose Crosses Under indicator1)
    IF c2 THEN
    SELL AT MARKET
    ENDIF
      
    // SHORT trades when switching from bullish to bearish
    c3 = (Bearish AND Bullish[1]) and xClose Crosses Under indicator1
    IF c3 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
     
    // exit SHORT trade on a Bullish candlestick
    c4 = (Bullish and xClose Crosses Over indicator1)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    jonpt88 thanked this post
    Schermafbeelding-2022-09-23-om-09.29.46.png Schermafbeelding-2022-09-23-om-09.29.46.png
    #201254 quote
    jonpt88
    Participant
    New
    Looks like a profitable one 🙂
    #201255 quote
    SnorreDK
    Participant
    Junior
    Many algos is profitable without stoploss, but u need to swing a big d**k😉
    #201256 quote
    jonpt88
    Participant
    New
    Do you know how to add a third variable like I ask – an RSI for example?
    #201257 quote
    JS
    Participant
    Senior

    You can add an extra condition with RSI for example:

    C1 = (Bullish and Bearish[1]) and xClose Crosses Over indicator 1 and RSI(16) Crosses Over 20

    C3 = (Bearish and Bullish[1] and xClose Crosses Under indicator 1 and RSI(16) Crosses Under 80

    jonpt88 thanked this post
    #201258 quote
    jonpt88
    Participant
    New
    Nice – would it be possible for you to add that to the code with such variable – regardless of the back test result 🙂 That would be very much appreciated.
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.

Pro back-testing bullish / bearish heikin-ashi simple signal / variable


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jonpt88 @jonpt88 Participant
Summary

This topic contains 17 replies,
has 3 voices, and was last updated by JS
3 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/31/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...