2023-01-15 18:43:01
Как и обещал несколько стратегий для PineScript:strategy("Two Moving Average Strategy", overlay=true)
// Define the moving average settings
_fastMA = 12
_slowMA = 26
// Calculate the moving average values
fastMA = ta.sma(close, _fastMA)
slowMA = ta.sma(close, _slowMA)
// Define the crossover conditions
fastCross = ta.crossover(fastMA, slowMA)
slowCross = ta.crossunder(fastMA, slowMA)
// Define the buy and sell conditions
if fastCross
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry = "Long", stop = strategy.position_avg_price * 0.99)
else if slowCross
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", from_entry = "Short", stop = strategy.position_avg_price * 1.025)
strategy(«MACD v1», overlay=true)// Check for drops and rises
fast_ma = 9
slow_ma = 14
macd_ma = 5
[macd, signal,hist] = ta.macd(close, fast_ma, slow_ma,9)
//signal = ta.sma(macd, macd_ma)
// Buy rule
// strategy.entry("Buy", strategy.long)
// Sell rule
//strategy.close("Sell")
IsLong() =>
strategy.position_size > 0
IsShort() =>
strategy.position_size < 0
isNoPosition() =>
strategy.position_size == 0
//i=1
//if close[i+3] > close[i+2] and close[i+2] > close[i+1] and close[i+1] < close[i]
if ta.crossunder(signal,macd)
if IsLong()
strategy.close("Buy")
if isNoPosition()
strategy.entry("Sell", strategy.short)
if ta.crossunder(macd,signal)
if IsShort()
strategy.close("Sell")
if isNoPosition()
strategy.entry("Buy", strategy.long)
308 viewsedited 15:43