Pinescript Discussion

Hi all

I tried the same script in the lecture but when I add in chart there’s no result, nothing happens. I appreciate if anyone can help. Thank you

same happened to me… did you find the solution ?

@thecil , @dan-i,
maybe i’m missing something with the syntax here or something, but when i input the following into pine,

...
//@version=5
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)
x=sma(close, 10)
...

i get the folllwing error
"...Could not find function or function reference 'sma'..."
whaaat??? i MUST be missing something in the syntax (or the versioning is different?? or what else?? any help would be followed up on immediately! haha
thanks

1 Like

Hey @B_S, hope you are well.

Could you please share the entire code? would like to run it from my side and replicate the issue :nerd_face:

Carlos Z

for sure! thanks for following up
it’s the same (as far as i can tell) as what’s given in the lecture, except maybe the "//@version=5 "is where i’m going wrong?? (that was put in automatically when, in the “pine editor” pane, i “open” => “new blank strategy file”)

//@version=5
strategy("My Strategy")
x=sma(close, 10)
buy=close>m
sell=close<m
strategy.entry("buy", true, 5, when = buy)
strategy.close("buy", when = sell)

ok its all good with your script, the difference is on the pinescript version, since the course is using version 4, i advice to stick with it, the version 5 has change a little the syntax of the script so thats why your getting the error.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thecilsurf

//@version=5
strategy(title='Moving Average Crossing')
shortMa = ta.sma(close, 10)
buy = close > shortMa
sell = close < shortMa
strategy.entry('buy', strategy.long, 5, when=buy)
strategy.close('buy', when=sell)

So basically just stick with the version 4 to complete the course :nerd_face:

Carlos Z

1 Like

i see; where can i find the changes in version 5? if i want to implement my own algo, how important is it that i use the latest versions?

1 Like

Right top corner of the Pine Editor, more options:

I might advice you to stick with version 4 for the course, once you have the fundamentals of the pine programming, you could try to upgrade the existing project to the version 5, which could be just a click on the Pine Editor (convert).

Carlos Z

1 Like

i am not sure what is going on with trading view; but my code only display buy/sell when moving to a monthly time frame:

nevermind! a browse refresh on screen provided expected results!


1300% profit with 217 trades
also I noticed that trading using weekly or monthly has much better results than daily;
those the pine script adjust to the timeframe?
look at weekly results with SMA10 for BTCUSD
Profit of 2628% only 28 trades

look at monthly results with SMA 109 for BTCUSD
Profit of 2196% only 5 trades

probably a good strategy is to have something running in higher timeframes, 4hr trading is worst

1 Like