Classic MACD 200EMA Strategy
Forums › ProRealTime English forum › ProOrder support › Classic MACD 200EMA Strategy
- This topic has 4 replies, 3 voices, and was last updated 10 months ago by Marketpunk.
-
-
05/11/2023 at 11:25 AM #214512
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
05/11/2023 at 12:12 PM #214527Hi, I think I this response may be for someone else. Thanks
05/12/2023 at 12:07 PM #214600I 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 😊
12345678910111213141516171819DEFPARAM CumulateOrders = FalseMyMACD = 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 MySLineC2 = MyMACD < 0 AND MySLine < 0C3 = Close < EMA200BuyCondition = C1 AND C2 AND C3IF BuyCondition THENBuy 1 Shares AT MarketSET STOP pLOSS 20ENDIF1 user thanked author for this post.
07/13/2023 at 11:18 PM #217632I 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)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546DEFPARAM CumulateOrders = FalseMyMACD = 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 < 0C2 = Close > EMA200BuyCondition = C1 AND C2IF BuyCondition THENBuy 1 Shares AT MarketSwingLow = lowest[10](low) // Assuming a 10-bar lookback for swing lowNearestLevel = Min(SwingLow, EMA200) // Selecting the nearest level to the current priceslosslevel = Tradeprice - NearestLevelset stop ploss slosslevelset stop %trailing 0.5ENDIFC3 = MyMACD Crosses Under MySLine AND MyMACD > 0 AND MySLine > 0C4 = Close < EMA200SellCondition = C3 AND C4IF SellCondition THENSellshort 1 Shares AT MarketSwingHigh = highest[10](high) // Assuming a 10-bar lookback for swing highNearestLevel = Max(SwingHigh, EMA200) // Selecting the nearest level to the current priceslosslevel = Tradeprice - NearestLevelset stop ploss slosslevelset stop %trailing 0.5ENDIF// Take Profit optionsOption1RiskReward = 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 distanceTakeProfitOption1 = NearestLevel + (NearestLevel - NearestStopLoss) * Option1RiskRewardif (open < TakeProfitOption1 and close > TakeProfitOption1) or (open > TakeProfitOption1 and close < TakeProfitOption1) thensell at marketexitshort at marketendif1 user thanked author for this post.
01/24/2024 at 10:30 AM #226824Hi,
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.
-
AuthorPosts
Find exclusive trading pro-tools on