MACD, backtest 2015+ only, cut in half and doubled

This is only a slight modification to the existing "MACD Strategy" strategy plugin!
found the default MACD strategy to be lacking, although impressive for its simplicity. I added "year>2014" to the IF buy/sell conditions so it will only backtest from 2015 and beyond**.
I also had a problem with the standard MACD trading late, per se. To that end I modified the inputs for fast/slow/signal to double. Example: my defaults are 10, 21, 10 so I put 20, 42, 20 in. This has the effect of making a 30min interval the same as 1 hour at 10,21,10. So if you want to backtest at 4hr, you would set your time interval to 2hr on the main chart. This is a handy way to make shorter time periods more useful even regardless of strategy/testing, since you can view 15min with alot less noise but a better response.

Used on BTCCNY OKcoin, with the chart set at 45 min (so really 90min in the strategy) this gave me a percent profitable of 42% and a profit factor of 1.998 on 189 trades.
Personally, I like to set the length/signals to 30,63,30. Meaning you need to triple the time, it allows for much better use of shorter time periods and the backtests are remarkably profitable. (i.e. 15min chart view = 45min on script, 30min= 1.5hr on script)

**If you want more specific time periods you need to try plugging in different bar values: replace "year" with "n" and "2014" with "5500". The bars are based on unix time I believe so you will need to play around with the number for n, with n being the numbers of bars.

本着真正的TradingView精神,该脚本的作者将其开源发布,因此交易者可以理解和验证它。为作者加油! 您可以免费使用它,但是在发布中重复使用此代码受网站规则的约束。您可以收藏它以在图表上使用。

strategy("MACDEEZNUTS", overlay=true)

fastLength = input(20)
slowlength = input(42)
MACDLength = input(20)

MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = sma(MACD, MACDLength)
delta = MACD - aMACD

if (crossover(delta, 0)) and (year>2014)
    strategy.entry("MacdLE", strategy.long, comment="MacdLlE")

if (crossunder(delta, 0))and (year>2014)
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)


Hi, I want to know, how to automatically send orders with strategy generated signals?
+4 回复
Hello friend, your strategy is very good, would not it be better if you just entered buy order? What is the command to send a buy and sell alert?
I thank the attention.
+1 回复
@abrakw, This strategy plugin is pretty outdated, but I think you may be misunderstanding or perhaps I am misunderstanding your question. Ideally, the strategy will issue a buy order when MACD is crossing into positive and issue sell when MACD turns < 0. I suppose you could write a strategy that only enters a buy when the signal value is >10 and only enters a sell when the signal is < -10--- so when: 10 > signal val >-10 no position is entered.
To be able to create an alert you would want to edit the code---since this is a simple MACD strategy I would just recommend loading a MACD indicator study (search "MACD" after clicking 'add indicator'), once you have one you like then click the little alarm clock to add an alert. For "condition" select the MACD indicator you just loaded. Then select the "histogram" (might have other name like 'cross') and select 'crossing up' (or down for sell or other variation) and create an alert. Now when the histogram drops below 0 you get the sell alert.
+1 回复
abrakw RyanMartin
@RyanMartin, I understand very well what the friend said, unfortunately I do not know how to put this in the programming language, I thank you for the attention.
I made edits to the text of this but I hit "submit" right as 15min passed, so it ignored my changes. If you have any questions just send me a message.
To be clear, it helps to have a MACD chart plugin on with the same values (20/42/20 or whatever you enter) so you can see what you are doing. This is meant to be used such that you set the time period to half of what you normally would: if you want to trade off 2 hour MACD at 10/21/20, set your trade view to 1 hour..
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 如何运作 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 私人消息 在线聊天 退出