EMA Deep USD/JPY 1H

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #42545 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    //————————————————————————-

    // Morgan Pettersson 2017-08-06

    //————————————————————————-

    defparam preloadbars = 300
    DEFPARAM CumulateOrders = true // Cumulating positions activated

    mdays = 26
    myStoploss = 30
    myProfit = 48
    myLots = 1

    EMA20=ExponentialAverage[20](close)
    EMA50=ExponentialAverage[50](close)
    EMA200=ExponentialAverage[200](close)

    //UpTrend
    c1 = summation[mdays](ema20>ema50)=mdays
    c2 = summation[mdays](ema50>ema200)=mdays
    UpTrend = c1 and c2

    //Bullish Dip PinBar ema20
    c3 = low < ema20 and close > ema20
    c4 = close > open
    c5 = abs(open-close)/abs(open-low) <= 0.5
    BullishDipCondition = c3 and c4 and c5

    //*************************************
    //Conditions to enter long positions
    //*************************************

    IF UpTrend and BullishDipCondition THEN
    IF SHORTONMARKET THEN
    EXITSHORT AT MARKET
    ENDIF
    BUY myLots CONTRACT AT MARKET
    SET STOP pTRAILING myStopLoss
    SET TARGET pPROFIT myProfit
    ENDIF

    //DownTrend
    d1 = summation[mdays](ema20<ema50)=mdays
    d2 = summation[mdays](ema50<ema200)=mdays
    DownTrend = d1 and d2

    //Bearish dip
    d3 = high > ema20 and close < ema20
    d4 = close < open
    d5 = abs(close-open)/abs(high-open) <= 0.5
    BearishDipCondition = d3 and d4 and d5

    //*************************************
    //Conditions to enter short positions
    //**************************************
    IF DownTrend and (BearishDipCondition) THEN
    IF LONGONMARKET THEN
    SELL AT MARKET
    ENDIF
    SELLSHORT myLots CONTRACT AT MARKET
    SET STOP pTRAILING myStopLoss
    SET TARGET pPROFIT myProfit
    ENDIF

    screen-1502033226cpl84.png screen-1502033226cpl84.png
    #42552 quote
    NicolasNicolas
    Keymaster
    Legend

    Hi, thanks for sharing your automated trading strategy on USD/JPY. Because your post do not has any explanation, I only tried to simulate the same period on my own platform. Unfortunately, I do not get the same results as yours. Could you please explain us a bit how it works, the timeframe used, spread and any other useful information you could share. Thanks gain for sharing your code with the community, much appreciated 🙂

    #42677 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    Hello!

    Is it because i did not write enough explanation that it did not fit in the library?

    Should i do another post with more explanation or put my text here?

    /Morgan

    #42701 quote
    NicolasNicolas
    Keymaster
    Legend

    I need to review the code and obtain the same results as you, because a lot of people will download it and try it, I want to be sure everything is ok. I also need some explanations of coursen thanks in advance 🙂

    #42711 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    USA/JPY mini 1 Hour

    Trades from 1 jan 2017 08:00 to 4 aug 22:00.

    Spread IG 0.7.

    I define an uptrend if EMA20 >EMA>50EMA200

    downtrend EMA20<EMA50<EMA200

    If there is a pullback in an uptrend back to EMA20 and with a bullish pinbar I buy.

    And the precise opposite in an downtrend.

    I have had some problems with devisionwith zero that I dont really understand.

    Some small changes in this code:

     

    // Definition of code parameters
    defparam preloadbars = 600
    DEFPARAM CumulateOrders = true // Cumulating positions deactivated
    
    mydays = 26
    myStoploss = 30
    myProfit = 48
    myLots = 1
    
    var = 0.2
    
    EMA20=ExponentialAverage[20](close)
    EMA50=ExponentialAverage[50](close)
    EMA200=ExponentialAverage[200](close)
    
    //UpTrend
    c1 = summation[mydays](ema20>ema50)=mydays
    c2 = summation[mydays](ema50>ema200)=mydays
    UpTrend = c1 and c2
    
    //Bullish Dip PinBar ema20
    c3 = low < ema20 and close > ema20
    c4 = close > open
    if(open-low > 0) then
    c5 = abs(open-close)/abs(open-low) <= var
    endif
    BullishDipCondition = c3 and c4 and c5
    
    //DownTrend
    d1 = summation[mydays](ema20<ema50)=mydays
    d2 = summation[mydays](ema50<ema200)=mydays
    DownTrend = d1 and d2
    //Bearish dip
    d3 = high > ema20 and close < ema20
    d4 = close < open
    if(high-open > 0) then
    d5 = abs(close-open)/abs(high-open) <= var
    endif
    
    BearishDipCondition = d3 and d4 and d5
    
    
    
    //*************************************
    //Conditions to enter long positions
    //*************************************
    IF UpTrend and (BullishDipCondition) THEN
    IF SHORTONMARKET THEN
    EXITSHORT AT MARKET
    ENDIF
    
    BUY myLots CONTRACT AT MARKET
    SET STOP pTRAILING myStopLoss
    //SET STOP ploss myStopLoss
    SET TARGET pPROFIT myProfit
    
    ENDIF
    //*************************************
    //Conditions to enter short positions
    //**************************************
    IF DownTrend and (BearishDipCondition) THEN
    IF LONGONMARKET THEN
    SELL AT MARKET
    ENDIF
    
    SELLSHORT myLots CONTRACT AT MARKET
    SET STOP pTRAILING myStopLoss
    //SET STOP ploss myStopLoss
    SET TARGET pPROFIT myProfit
    
    ENDIF
    usajpy1hour.jpg usajpy1hour.jpg
    #42718 quote
    DespairDespair
    Blocked
    Master

    Your strategy does great from november 2015 onward. Before it doesn’t work so well. Have you optimized over this period?

    #42720 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    Yes that sounds about right. I only have a demo account at IG so i think thats all the data i got.

    #42731 quote
    DespairDespair
    Blocked
    Master

    Which parameters did you optimize?

    #42736 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    None. The trend check is some standard values for ema that i use when i manuelly trade.

    I developed the strategy and then tested it on different intrument. It worked best on USA/JPY and its my favourite for manuell trading so i used it.

    I have changed the size of the pinbar to 0.2 from 0.5. The var varible. But I’m not sure if it’s for the better or not 🙂

    /Morgan

    #42740 quote
    DespairDespair
    Blocked
    Master

    I see. Like I said, the last 18 months or so it worked great but before it didn’t. I will have a closer look at it when I have time. Thanks for sharing.

    #42790 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    Yesterday i got division by zero again. I dont know why?

    #42835 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    Hi, having a quick read at your code, you have c5 and d5 with respectively open-low and high-open at denominator. So just a guess with good probability: your division by zero message probably matches candles for which open=low or open=high

    #50824 quote
    M. PetterssonM. Pettersson
    Participant
    Average

    What more can I do to avoid division with zero?

    This coding language is really limited. No error handeling ..

    c = abs(close-open)
    d = abs(high-open)

    if d > 0 then
    b = (c/d) <= 0.5
    endif

    #50832 quote
    NicolasNicolas
    Keymaster
    Legend

    ” Graph d” to view your variable in the backtest window.

Viewing 14 posts - 1 through 14 (of 14 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

EMA Deep USD/JPY 1H


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by NicolasNicolas
9 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/06/2017
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...