Classic MACD 200EMA Strategy

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #214512 quote
    Marketpunk
    Participant
    New

    Hello,

    Would it be possible to get code for a strategy please as follows:-

    The trading timeframe is open to accommodate trading on all timeframes.

    A buy signal is generated when the MACD crosses up over the MACD Signal line and the signal line and MACD are below the Zero line, and price closes above the 200 Exponential Moving Average.

    Stop loss for a buy signal is based on the most recent swing low and/or the 200 period Exponential Moving Average whichever is nearest the price when the trade is taken.

    A sell signal is generated when the MACD crosses under the MACD signal line and the signal line and MACD are above the MACD Zero line, and price closes below the 200 EMA.

    Stop loss for a sell signal is based on the most recent swing high and/or the 200 period Exponential Moving average whichever is nearest the price when the trade is taken.

    Take Profit can be based on either Option 1 an adjustable Risk/Reward ratio (Trailing Stop loss to be at 0) or Option 2 an adjustable Trailing Stop loss percentage (risk /reward ratio to be at 0).

    Appreciate any assistance. Thank you

    #214527 quote
    Marketpunk
    Participant
    New

    Hi, I think I this response may be for someone else. Thanks

    #214600 quote
    ZeroCafeine
    Participant
    Senior

    I think that what you are asking for is not very complicated, here is the beginning of a code that may help you for the next step 😊

    DEFPARAM CumulateOrders = False
    
    MyMACD = MACDline[12,26,9](close)
    MySLine = MACDSignal[12,26,9](close)
    MyHis = MACD[12,26,9](close)
    EMA200 = ExponentialAverage[200](close)
    
    C1 = MyMACD Crosses Over MySLine
    
    C2 = MyMACD < 0 AND MySLine < 0
    
    C3 = Close < EMA200
    
    BuyCondition = C1 AND C2 AND C3
    
    IF BuyCondition THEN
    Buy 1 Shares AT Market
    SET STOP pLOSS 20
    ENDIF
    Nicolas thanked this post
    #217632 quote
    ProRealAlgos
    Participant
    Junior

    I took some time to add the final conditions of the strategy based on ZeroCafeines start.

    Here’s the code. Looks pretty good on DAX Daily (backtest for 200k units attached)

    DEFPARAM CumulateOrders = False
    
    MyMACD = MACDline[12,26,9](close)
    MySLine = MACDSignal[12,26,9](close)
    MyHis = MACD[12,26,9](close)
    EMA200 = ExponentialAverage[200](close)
    
    C1 = MyMACD Crosses Over MySLine AND MyMACD < 0 AND MySLine < 0
    C2 = Close > EMA200
    BuyCondition = C1 AND C2
    
    IF BuyCondition THEN
    Buy 1 Shares AT Market
    SwingLow = lowest[10](low) // Assuming a 10-bar lookback for swing low
    NearestLevel = Min(SwingLow, EMA200) // Selecting the nearest level to the current price
    
     slosslevel = Tradeprice - NearestLevel
    set stop ploss slosslevel
    set stop %trailing 0.5
    ENDIF
    
    
    
    C3 = MyMACD Crosses Under MySLine AND MyMACD > 0 AND MySLine > 0
    C4 = Close < EMA200
    SellCondition = C3 AND C4
    
    IF SellCondition THEN
    Sellshort 1 Shares AT Market
    SwingHigh = highest[10](high) // Assuming a 10-bar lookback for swing high
    NearestLevel = Max(SwingHigh, EMA200) // Selecting the nearest level to the current price
    slosslevel = Tradeprice - NearestLevel
    set stop ploss slosslevel
    set stop %trailing 0.5
    ENDIF
    
    // Take Profit options
    Option1RiskReward = 2 // Adjustable Risk/Reward ratio (e.g., 2 means 2:1)
    Option2TrailStopPercent = 0.5 // Adjustable Trailing Stop loss percentage (e.g., 0.5%)
    NearestStopLoss = 10 // minimum stop distance
    TakeProfitOption1 = NearestLevel + (NearestLevel - NearestStopLoss) * Option1RiskReward
    
    if (open < TakeProfitOption1 and close > TakeProfitOption1) or (open > TakeProfitOption1 and close < TakeProfitOption1) then
    sell at market
    exitshort at market
    endif 
    
    
    Marketpunk and NeoTrader thanked this post
    MACD200EMA.png MACD200EMA.png
    #226824 quote
    Marketpunk
    Participant
    New

    Hi,

    Thank you for your code for back testing the strategy. Just wondering would it be possible to get code to use this as an indicator please.  Thanks again for your assistance.

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

Classic MACD 200EMA Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Marketpunk @marketpunk Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Marketpunk
2 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/11/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...