Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Syntax error at input 'strategy.long'." please help. thanks

So 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 for the past 3 hours I’ve been trying to find what’s wrong with line 17 but I can’t seem to.

error says "line 17: Syntax error at input ‘strategy.long’."

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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")

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading