Help on MACD Strategy

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #101114 quote
    Abz
    Participant
    Veteran

    Hello,trying out an simple macd strategy. If someone coud help , much appreciated.

    for Long:

    1. once macd crosses over 0 and the next 3 bars on macd line is green
    2. then place and buy order “x”pips below the close price of the 3rd bar

     

    For short:

    1. once macd crosses under 0 and the next 3 bars are red
    2. then place a short order “x”pips over the close price of the 3rd bar

     

    see also attached screen

     

    // Definition of code parameters
    DEFPARAM Preloadbars = 10000
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // indicators
    mac = MACDline[12,26,9](close)
    
    Positions = 10
    
    
    IF not onmarket and mac crosses over 0  THEN
    buy Positions SHARES AT MARKET
    ENDIF
    
    IF not onmarket and mac crosses under 0  THEN
    sellshort Positions SHARES AT MARKET
    ENDIF
    
    
    Set target pprofit 50
    set stop ploss 50
    macd.png macd.png
    #101124 quote
    jebus89
    Participant
    Master

    3 red / green candles:

     

    redcandle1 = close < open
    redcandle2 = close[1] < open[1]
    redcandle3 = close[2] < open[2]
    
    threeredcandle = redcandle1 and redcandle2 and redcandle3
    
    greencandle1 = close > open
    greencandle2 = close[1] > open[1]
    greencandle3 = close[2] > open[2]
    
    threegreencandle = greencandle1 and greeencandle2 and greencandle3
    

    And heres the “place an order below/above closed candle:

    y2 = close - (10*pointsize)
    
    if buytime then
    buy 1 contract at y limit
    endif
    
    y1 = close + (10*pointsize)
    
    if shorttime then
    sellshort 1 contract at y2 limit
    endif

     

     

    So your entire code would look like this:

    // Definition of code parameters
    DEFPARAM Preloadbars = 10000
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // indicators
    mac = MACDline[12,26,9](close)
    
    redcandle1 = close < open
    redcandle2 = close[1] < open[1]
    redcandle3 = close[2] < open[2]
    threeredcandle = redcandle1 and redcandle2 and redcandle3
     
    greencandle1 = close > open
    greencandle2 = close[1] > open[1]
    greencandle3 = close[2] > open[2]
     
    threegreencandle = greencandle1 and greeencandle2 and greencandle3
     
    Positions = 10
    
    macbuy = mac crosses over 0 
    macshort = mac crosses under 0  
    
    buytime = macbuy[2] and threegreencandle
    shorttime = macshort[2] and threeredcandle
    
    
    y1 = close + (10*pointsize)
    y2 = close - (10*pointsize)
     
    IF not onmarket and buytime THEN
    buy Positions SHARES AT y2 limit
    ENDIF
     
    IF not onmarket and shorttime THEN
    sellshort Positions SHARES AT y1 limit
    ENDIF
     
     
    Set target pprofit 50
    set stop ploss 50
    Nicolas, Abz and nonetheless thanked this post
    #101128 quote
    jebus89
    Participant
    Master

    Just noticed you might have asked for 3 red macd bars and not 3 red candles in photo. Do you want the 3 bars to be lower/higher then the last one? or does it only matter that they are red/green?

     

    This is for 3 red macd histogram bars that goes lower and lower: (just do the “>” for higher and higher for long trades)

    indicator1 = MACD[12,26,9](close)
    c1 = (indicator1 < 0)
    indicator2 = MACD[12,26,9](close)
    c2 = (indicator2[1] < 0)
    indicator3 = MACD[12,26,9](close)
    c3 = (indicator3[2] < 0)
    indicator4 = MACD[12,26,9](close)
    c4 = (indicator4 < indicator4[1])
    indicator5 = MACD[12,26,9](close)
    c5 = (indicator5[1] < indicator5[2])

    If you only want 3 red bars and it dosnt matter which is bar is lower then the other then just remove c4 and c5

    Abz thanked this post
    #101135 quote
    GraHal
    Participant
    Master

    I’m watching with interest … please post curve and stats on here Abz  and thanks goes to  jebus89 for the coding!

    #101180 quote
    Abz
    Participant
    Veteran

    Thanks Jebus , i will do some backtests and report back

    GraHal thanked this post
    #155524 quote
    Andrea
    Participant
    Average

    Good post. How about to filter signals of sideways market? Thx

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

Help on MACD Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Abz @abbas_sadiq Participant
Summary

This topic contains 5 replies,
has 4 voices, and was last updated by Andrea
5 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/20/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...