Created
August 16, 2020 11:40
-
-
Save sooch/c360ea293852fc65c990f584c3b01b91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © sooch | |
// | |
// TradingViewのMACDストラテジーに期間指定パラメータを追加したPineScriptです. | |
// | |
//@version=4 | |
strategy("MACD Strategy", overlay=true) | |
// Input parameters | |
start_y = input(2020, minval=1900, maxval=2100, title="Start Year") | |
start_m = input(01, minval=01, maxval=12, title="Start Month") | |
start_d = input(01, minval=01, maxval=31, title="Start day") | |
end_y = input(2020, minval=1900, maxval=2100, title="End Year") | |
end_m = input(12, minval=01, maxval=12, title="End Month") | |
end_d = input(31, minval=01, maxval=31, title="End day") | |
ema1 = input(12, title="EMA1 length") | |
ema2 = input(26, title="EMA2 length") | |
signal = input(9, title="Signal length") | |
src = input(close, "source") | |
start_time = timestamp("Asia/Tokyo", start_y, start_m, start_d, 00, 00) | |
end_time = timestamp("Asia/Tokyo", end_y, end_m, end_d, 00, 00) | |
is_testing = time >= start_time and time <= end_time | |
bgcolor(is_testing ? color.black : color.white) | |
[macd, sig, hist] = macd(src, ema1, ema2, signal) | |
goldencross = crossover(macd, sig) | |
deadcross = crossunder(macd, sig) | |
if is_testing and goldencross | |
strategy.entry("MacdLE", strategy.long) | |
if is_testing and deadcross | |
strategy.entry("MacdSE", strategy.short) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment