MA20 cross MA50

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #145519 quote
    Andre Vorster
    Participant
    Senior

    Hello.

    I have been trying to get this working for some time now but to no avail. Tried this on various Indices with various time frames but still does not work.
    I logged a ticket with IG/PRTG but they don’t have an answer as well.

    Hope any of you can help with this please.
    Only thing I can think of why the code does not trigger at the right time is because I use MA ZeroLagExponential (-2) Horizontal shift and MA ZeroLagExponential (in general)
    Anyway… that’s just a thought…

    The idea is to have an Indicator and/or if possible a strategy using the parameters below.

    Indicators used:
    MA20 Zero Lag Exponential (Horizontal shift -2)
    MA50 Zero Lag Exponential (Horizontal shift 0)

    Strategy:
    Buy when MA20(-2) crosser over MA50 AND MACD Line > MACD Signal
    Sell when MA20(-2) crosser under MA50 AND MACD Line < MACD Signal

    Indicator:
    Draw arrow with txt when these occurs.

    Thank you.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[20](totalPrice)
    indicator2 = Average[50](totalPrice)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = MACDline[12,26,9](close)
    indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))
    c2 = (indicator3 > indicator4)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 10
    SET TARGET pPROFIT 1
    
    IF ExponentialAverage[20](close) CROSSES OVER ExponentialAverage[50](close) THEN
    DRAWTEXT("20 > 50", barindex, high, Dialog, Bold, 12) COLOURED(255,10,10,255)
    endif
    
    MA20-crossover-MA50-001-trade.jpg MA20-crossover-MA50-001-trade.jpg MA20-crossover-MA50-001A.jpg MA20-crossover-MA50-001A.jpg MA20.jpg MA20.jpg MA50.jpg MA50.jpg
    #145565 quote
    robertogozzi
    Moderator
    Master

    The main code uses SMA’s while the last three lines posted use EMA’s.

    Yes, there’s no shift coded in your strategy.

    Shifting cannot be coded automatically.

    What do you mean by shifted -2, that the current bar needs to use data from two bars ago (there’s no other shifting possible)?

    #145618 quote
    Andre Vorster
    Participant
    Senior

    Robert.

    Yes there are differences in the code published. Error on my side.
    I changed the code to use “ExponentialAverage” in all lines. Still the same results.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[20](totalPrice)
    indicator2 = ExponentialAverage[50](totalPrice)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = MACDline[12,26,9](close)
    indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))
    c2 = (indicator3 > indicator4)
     
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
     
    // Stops and targets
    SET STOP pLOSS 10
    SET TARGET pPROFIT 1
    
    #145624 quote
    Andre Vorster
    Participant
    Senior

    Robert.

    To answer your question “What do you mean by shifted -2, that the current bar needs to use data from two bars ago (there’s no other shifting possible)?”
    I set the horizontal shift to ‘-2’. Yes that changes it to 2 two bars ago.

    My thought is the code should read when the line crosses no matter the horizontal shit. Or do I want what’s not possible?

    Thank you.

    #145638 quote
    Nicolas
    Keymaster
    Master

    The EMA20 from 2 bars ago is:

    indicator1 = ExponentialAverage[20](totalPrice)[2]
    #145646 quote
    Vonasi
    Moderator
    Master

    no matter the horizontal shit.

    I hope that was a typo!

    #145659 quote
    Andre Vorster
    Participant
    Senior

    Nicolas.

    indicator1 = ExponentialAverage[20](totalPrice)[2]
    Now I get more accurate results but it does not seem to work all the time but there are still times when the code activates the indicator and/or buy signal when conditions are not met.

    Thank you.

    #145666 quote
    robertogozzi
    Moderator
    Master

    Topic moved to ProOrder support (Vonasi spotted the incorrect support forum).

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

MA20 cross MA50


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by robertogozzi
5 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/27/2020
Status: Active
Attachments: 4 files
Logo Logo
Loading...