Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

version=5@//

strategy("Binary Options Candle Prediction with Signals", overlay=true)

Input parameters //

smaLength = input.int(14, title="SMA Length")

rsiLength = input.int(14, title="RSI Length")

rsiOverbought = input.int(70, title="RSI Overbought Level")

rsiOversold = input.int(30, title="RSI Oversold Level")

Calculate indicators //

sma = ta.sma(close, smaLength)

rsi = ta.rsi(close, rsiLength)

Define conditions for prediction //

longCondition = close > sma and rsi < rsiOversold

shortCondition = close < sma and rsi > rsiOverbought

Plot indicators //

plot(sma, title="SMA", color=color.blue)

hline(rsiOverbought, title="RSI Overbought", color=color.red)

hline(rsiOversold, title="RSI Oversold", color=color.green)

plot(rsi, title="RSI", color=color.purple)

Execute trades //

if (longCondition)

strategy.entry("Long", strategy.long)

style=label.style_label_up, color=color.green, ,"‫="شراء‬bar_index, high, text(label.new


)textcolor=color.white, size=size.normal
if (shortCondition)

strategy.entry("Short", strategy.short)

style=label.style_label_down, color=color.red, ,"‫="بيع‬bar_index, low, text(label.new


)textcolor=color.white, size=size.normal

Plot signals for the next predicted candle //

if (longCondition)

label.new(bar_index + 1, close, text="🔼", color=color.green, textcolor=color.white,


style=label.style_label_up, size=size.large)

if (shortCondition)

label.new(bar_index + 1, close, text="🔽", color=color.red, textcolor=color.white,


style=label.style_label_down, size=size.large)

Close trades at the end of the candle //

if (strategy.opentrades > 0)

strategy.close("Long", when = not longCondition)

strategy.close("Short", when = not shortCondition)

You might also like