OPEN-SOURCE SCRIPT

AI-Inspired Trading Strategy

//version=6
strategy("AI-Inspired Trading Strategy", overlay=true)

// Step 1: Input parameters for indicators
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.float(70, title="RSI Overbought Level")
rsiOversold = input.float(30, title="RSI Oversold Level")
smaShortLength = input.int(20, title="Short SMA Length")
smaLongLength = input.int(50, title="Long SMA Length")
macdFast = input.int(12, title="MACD Fast Length")
macdSlow = input.int(26, title="MACD Slow Length")
macdSignal = input.int(9, title="MACD Signal Length")

// Step 2: Calculate indicators
rsi = ta.rsi(close, rsiLength)
smaShort = ta.sma(close, smaShortLength)
smaLong = ta.sma(close, smaLongLength)
macdLine = ta.ema(close, macdFast) - ta.ema(close, macdSlow)
signalLine = ta.ema(macdLine, macdSignal)

// Step 3: Store crossover and crossunder results
smaCrossUp = ta.crossover(smaShort, smaLong)
smaCrossDown = ta.crossunder(smaShort, smaLong)
macdCrossUp = ta.crossover(macdLine, signalLine)
macdCrossDown = ta.crossunder(macdLine, signalLine)

// Step 4: Define buy and sell conditions
buyCondition = (rsi < rsiOversold) and smaCrossUp and macdCrossUp
sellCondition = (rsi > rsiOverbought) or smaCrossDown or macdCrossDown

// Step 5: Plot buy and sell signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Step 6: Execute trades
if (buyCondition)
strategy.entry("Buy", strategy.long)

if (sellCondition)
strategy.close("Buy")
Bands and Channels

Skrip sumber terbuka

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai sumber terbuka supaya pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara percuma, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?

Penafian