Heiken EMA Strategi

Forums ProRealTime English forum ProOrder support Heiken EMA Strategi

Viewing 9 posts - 1 through 9 (of 9 total)
  • #226586

    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

    Try below …

     

    2 users thanked author for this post.
    #226937

    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

    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).

     

     

    #226979

    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

    It’s correct.

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

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

     

     

    1 user thanked author for this post.
    #228265

    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

    ColorChange triggers an exit.

    What do you mean?

     

    #228915

    Hi Roberto,

     

    #228922

    That’s exactly what ColorChange does,

Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login