Heiken EMA Strategi

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #226586 quote
    PalicoPalico
    Participant
    New

    Hi,

    I need help to make this work:

    I want to trade when the Heiken changes  colour and EMA 2 crosses EMA 6.

    DEFPARAM CumulateOrders = False //MACD[12,26,9](close) Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the “FLATBEFORE” time.
    DEFPARAM FLATBEFORE = 093000
    // Cancel all pending orders and close all positions at the “FLATAFTER” time
    DEFPARAM FLATAFTER = 205000

    a = EMA[2](close)
    b = EMA[6](close)

    //heiken ashi
    xClose = (Open+High+Low+Close)/4
    if(barindex>2) then
    xOpen= (xOpen[1] + xClose[1])/2
    //xHigh= Max(xOpen, xClose)
    //xLow= Min(xOpen, xClose)
    endif
    xBullish = xClose > xOpen
    xBearish = xClose < xOpen
    ColorChange = (xBullish AND xBearish[1]) OR (xBullish[1] AND xBearish)

    // Conditions to enter long positions
    IF NOT LongOnMarket AND a crosses over b THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF

    // Conditions to exit long positions
    IF LongOnMarket AND Colorchange THEN
    SELL AT MARKET
    ENDIF

    // Conditions to enter short positions
    IF NOT ShortOnMarket AND a crosses under b THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF

    #226587 quote
    GraHalGraHal
    Participant
    Master

    Try below …

    a = ExponentialAverage[2](close)
    b = ExponentialAverage[6](close)
    Palico and Nicolas thanked this post
    #226937 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I made some changes to improve it, though a strategy based solely on EMAs is difficult to be turned into a profitable system:

    • I used the HA close (xClose) for the calculations of the two moving averages, replacing the regular close
    • I added the short exit
    • I changed the CROSSOVER condition with a retracement of the price to the lowest EMA,while the close must still be above both of them
    • I added a condition that the HA candle must be bullish for Long trades and Bearish for the short trades (but this should have been automatically the case, nonetheless)
    • I changed the periods for the two EMAs
    • I added both SL and TP
    DEFPARAM CumulateOrders = False //MACD[12,26,9](close) Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
    DEFPARAM FLATBEFORE = 093000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER  = 205000
    
    //heiken ashi
    xClose = (Open+High+Low+Close)/4
    if(barindex>2) then
       xOpen = (xOpen[1] + xClose[1])/2
       xHigh = Max(xOpen, xClose)
       xLow  = Min(xOpen, xClose)
    endif
    xBullish = xClose > xOpen
    xBearish = xClose < xOpen
    ColorChange = (xBullish AND xBearish[1]) OR (xBullish[1] AND xBearish)
    
    a = ExponentialAverage[5](xClose)//(close)
    b = ExponentialAverage[20](xClose)//(close)
    
    UP= xBullish AND (a > b) AND (xClose > a) AND (xLow  <= b)
    DN= xBearish AND (a < b) AND (xClose < a) AND (xHigh >= b)
    
    // Conditions to enter long positions
    IF NOT LongOnMarket AND UP THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    IF LongOnMarket AND Colorchange THEN
       SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND DN THEN
       SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND Colorchange THEN
       EXITSHORT AT MARKET
    ENDIF
    SET STOP   pLOSS   100
    SET TARGET pPROFIT 300

    you may also add a trailing stop (lines 17-56 at this link https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ are commonly used).

    MySystemHA.itf
    #226979 quote
    MaoRai54MaoRai54
    Participant
    Master

    Roberto, ciao.

    I’ve just tested your strategy but it’s not giving nice results.

    Just a question:

    is this line correct xOpen = (xOpen[1] + xClose[1])/ or it should be xOpen = (Open[1] + Close[1])/2  ??

    where do you get the value of xOpen[1] ?

    many thanks for your reply

    #226997 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    It’s correct.

    There should be this line, just before “if (barindex>2) then“:

    xOpen = open

    but it will work the same after the 3rd candle.

    MaoRai54 thanked this post
    #228265 quote
    PalicoPalico
    Participant
    New

    Hi Roberto!

    Thank you for your code. How do I change it so it goes long/short after the first change of color of the HA bar and rest the conditions mach?

    Best regards Patrick

    #228275 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    ColorChange triggers an exit.

    What do you mean?

    #228915 quote
    PalicoPalico
    Participant
    New

    Hi Roberto,

    Is it possible to change color after ONE HA bar has changed color not after 2 or 3.
    
    Regards Patrick
    #228922 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    That’s exactly what ColorChange does,

    x-13.jpg x-13.jpg
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Heiken EMA Strategi


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Palico @palico Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by robertogozzirobertogozzi
2 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/19/2024
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...