Entry and Exit based on MACD Bull or Bear

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #10257 quote
    siaoman
    Participant
    Average

    Hi,

    I’m wondering if it’s possible to exit trades based on when the MACD Signal line goes into a DOWNTREND or UPTREND.

    I’m looking to add this condition into my system to enter when MACD goes above zero (UPTREND) and then exit the next bar when the MACD Signal line shows a DOWNTREND. Vice versa for a SHORT trade.

    Also, if possible, for a LONG trade to exit on the next bar when two DOWNTREND lines appear on the MACD Signal line.

    I’ll attach a screenshot to give an idea of what I’m looking for.

    Thanks!

    PRT-MACD-Entry-Exit-1.png PRT-MACD-Entry-Exit-1.png
    #10390 quote
    siaoman
    Participant
    Average

    Forgot to mention in the screenshot that the 2 MACD indicators are; 1) the standard MACD with values 8/16/6 and 2) ZeroLag MACD with values 8/16/6. Also, shoutout to Nicolas for creating this indicator for us.


    @Nicolas
    , do you have an idea on how I can go about what I’m trying to achieve? If you need more info, let me know.

    Thanks!

    #10397 quote
    Nicolas
    Keymaster
    Master

    Hi, can you share your whole already made strategy code as I could implement the exit conditions in it please?  👍

    #10413 quote
    siaoman
    Participant
    Average

    Hey Nicolas,

    Thanks for responding.

    I’m currently not running it as an automated system until I can work out how to exit trades based on a decreasing/increasing value on MACD. That being said, I’m just trading the idea manually, however, below is a very basic system which would be the basis of where I’ll start creating my system from.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1, ignored = CALL "ZeroLag MACD"[8, 16, 6]
    c1 = (indicator1 >= 0)
    
    IF c1 THEN
    BUY 2 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    
    indicator2, ignored = CALL "ZeroLag MACD"[8, 16, 6]
    c2 = (indicator2 <= 0)
    
    IF c2 THEN
    SELL 2 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator3, ignored = CALL "ZeroLag MACD"[8, 16, 6]
    c3 = (indicator3 <= 0)
    
    IF c3 THEN
    SELLSHORT 2 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    
    indicator4, ignored = CALL "ZeroLag MACD"[8, 16, 6]
    c4 = (indicator4 >= 0)
    
    IF c4 THEN
    EXITSHORT 2 CONTRACT AT MARKET
    ENDIF
    

    Other things that I’ll be adding to this system will be:

    1. Only place LONG or SHORT trades based on MA Crossover; SMA46 cross TMA94; LONG when SMA46 above TMA94, SHORT when SMA46 below TMA94. You can see this in my screenshot. BLUE = SMA46 / TEAL = TMA94 / RED = TMA19 (this is used for other reasons).
    2. Look into incorporating the awesome GRID system that Nicolas helped develop from cfta’s idea.

    The time frame I used for the 2nd screenshot is 14:00 GMT+8 (AWST) to Real Time.

    My biggest reason for exploring this request is to determine whether it is possible or not to close based on when MACD changes from incline to decline (and vice versa). Just some more knowledge to add to when thinking of new ideas for systems. Also, I’m starting to really like the ZeroLag MACD indicator that Nicolas created. It helps to reduce MACD fakeouts, which has led to me pursuing this idea on closing trades based on the ZeroLag MACD indicator.

    If you need anything else, shoot me a message. I’m very active on the computer so can respond quite quickly.

    Thanks!

    PRT-MACD-Entry-Exit-2.png PRT-MACD-Entry-Exit-2.png
    #10492 quote
    Nicolas
    Keymaster
    Master

    So let me sum up what you want to add to your trading strategy:

    1/ A filter for long/short conditions made by SMA/TMA above or below

    2/ Close trades when MACD decline/incline

    Am I right?

    #10494 quote
    siaoman
    Participant
    Average

    Spot on Nicolas.

    My objective is to test a simple strategy to close the trade when the MACD declines/inclines. Once I get a feel of how that plays out, I’ll look to add additional conditions, such as entering a trade based on SMA/TMA (like you specified in point 1).

    #10498 quote
    Nicolas
    Keymaster
    Master

    Ok so you just have to test if the actual MACD is superior or inferior to the previous one:

    decline = myMACD<myMACD[1]
    incline = myMACD>myMACD[1]
    #10658 quote
    siaoman
    Participant
    Average

    Hey Nicolas,

    I’ve given it a shot, but can’t seem to figure out how to insert that logic into the code. Could you expand on it a bit more for me please?

    Thanks.

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

Entry and Exit based on MACD Bull or Bear


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
siaoman @siaoman Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by siaoman
9 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/06/2016
Status: Active
Attachments: No files
Logo Logo
Loading...