0

I've been trying to make a new simple strategy based on Stoch RSI and it was successful with this simple code

strategy("Long Strategy", overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)

strategy.entry("Buy", strategy.long, when=(b and k > OverSold), comment="Buy")
strategy.close("Buy", when=(s and d < OverBought), comment="Sell")

But I wanted to edit it so that the strategy.close would be fulfilled only when above entry price. So, I edited the code, and I've been trying to find what's wrong with line 17 but I can't seem to.

The error says "line 17: Syntax error at input 'strategy.long'."

The code after editing is as follows:

strategy("Stoch. RSI", format=format.price, overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3

k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)

var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
    price := close`
    strategy.entry(id="buy", strategy.long , comment="Buy")

if (s and d < OverBought) and (price > close)
    strategy.close(id="buy", comment="Sell")

1 Answer 1

0
var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
    price := close
    strategy.entry("buy", strategy.long, comment="Buy")

I removed the "id=" and it worked.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot !! code doesn't do the job but at least it's working now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.