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!
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!
Hi, can you share your whole already made strategy code as I could implement the exit conditions in it please? 👍
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:
- 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).
- 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!
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?
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).
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]
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.