Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- //@version=4
- strategy("sma cross", overlay=true)
- sma_length = input(200, "SMA Time Horizon")
- use_fract = input(false, "Use Fraction Strategy")
- fract = input(0.02, "Fraction to Close")
- longCondition = use_fract? close < sma(close, sma_length) * (1.0 - fract) : crossover(close, sma(close, sma_length))
- if (longCondition)
- strategy.entry("buy", strategy.long)
- shortCondition = use_fract? close > sma(close, sma_length) * (1.0 + fract) : crossunder(close, sma(close, sma_length))
- if (shortCondition)
- strategy.exit("buy")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement