200 EMA & MACD Indicator

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

    Hello,

    Would it be possible to get code an indicator  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

    #233249 quote
    phoentzs
    Participant
    Master

    Haven’t you asked the question before?

    Classic MACD 200EMA Strategy

    #233256 quote
    Marketpunk
    Participant
    New

    Hi Thanks for replying,

    The previous request was for a strategy.

    This request is for an indicator that can be used as a screener.

    Best regards

    Brian

    #233265 quote
    Iván González
    Moderator
    Master

    Hi
    This could be something closed to that you are looking for:

    R=1.5 //risk ratio
    //-----------------------------------------------------------------//
    MyMACD = MACDline[12,26,9](close)
    MySLine = MACDSignal[12,26,9](close)
    MyHis = MACD[12,26,9](close)
    EMA200 = ExponentialAverage[200](close)
    //-----------------------------------------------------------------//
    //-----Long Trades-------------------------------------------------//
    C1 = MyMACD Crosses Over MySLine AND MyMACD < 0 AND MySLine < 0
    C2 = Close > EMA200
    BuyCondition = C1 AND C2
    //-----Buy 
    IF long=0 and BuyCondition THEN
    drawarrowup(barindex,low)coloured("green")
    
    long=1
    short=0
    
    SwingLow = lowest[10](low) 
    NearestLevel = Min(SwingLow, EMA200) //Stop loss
    TP=R*(close-Nearestlevel)+close //Take Profit
    ENDIF
    //-----Sell
    if long and (low<NearestLevel or high>TP) then
    drawarrowdown(barindex,high)coloured("green")
    long=0
    endif
    //-----------------------------------------------------------------//
    //-----Short Trades------------------------------------------------//
    C3 = MyMACD Crosses Under MySLine AND MyMACD > 0 AND MySLine > 0
    C4 = Close < EMA200
    SellCondition = C3 AND C4
    //-----Sell Short
    IF short=0 and SellCondition THEN
    drawarrowdown(barindex,high)coloured("red")
    
    long=0
    short=1
    
    SwingHigh = highest[10](high) // Assuming a 10-bar lookback for swing high
    NearestLevel = Max(SwingHigh, EMA200) // Selecting the nearest level to the current price
    TP=close - R*(NearestLevel-Close)
    ENDIF
    //-----Cover Short
    if short and (high>NearestLevel or low<TP) then
    drawarrowup(barindex,low)coloured("red")
    short=0
    endif
    //-----------------------------------------------------------------//
    //-----------------------------------------------------------------//
    if long then
    drawpoint(barindex,NearestLevel)coloured("red")
    drawpoint(barindex,TP)coloured("blue")
    elsif short then
    drawpoint(barindex,NearestLevel)coloured("red")
    drawpoint(barindex,TP)coloured("blue")
    endif
    //-----------------------------------------------------------------//
    return EMA200
    #233286 quote
    Marketpunk
    Participant
    New

    Hi Ivan,

    Thank you very much for this. It’s much appreciated.

    I have a couple of queries that you might be able to answer or provide a solution please.

    1. The indicator should be used on the price chart. How can this be done?
    2. Can the code be included in ProScreener to identify instruments that provide a signal generated by the indicator

    Best regards

    Brian

    #233300 quote
    Marketpunk
    Participant
    New

    Hi Iván,

    Thank you for your great work on the requested indicator.

    I have figured out how to get the indicator onto the price chart and I’ll see if it works.  The indicator is on TradingView so I can do a comparison. I’ll let you know after the test.

    Could the code for the indicator be used in ProScreener? Would it be possible to get the amended code to enable this to work in ProScreener?

    Thanks again for your assistance.

    Best regards

    #233325 quote
    Iván González
    Moderator
    Master

    Hi
    Yes it can work for a screener but you need to delete all drawing instructions and the last line should be screener[long or short] instead return

    #233328 quote
    robertogozzi
    Moderator
    Master

    In addition, Ema200 won’t work, as screeners with IG have a 256-bar lookback limit, but a 200-period EMA greatly exceeds that limit (I once tested an EMA and it worked fine with some 80 periods, if I remeber correctly). Lower those periods or switch to an SMA.

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

200 EMA & MACD Indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Marketpunk @marketpunk Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by robertogozzi
1 year, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/29/2024
Status: Active
Attachments: No files
Logo Logo
Loading...