'How to convert strategy to study pinescript V5
I need to figure out how to turn my strategy into a study for V5 Pinescript.
I cannot seem to find any info about it online.
Im pretty sure for v3 you have to change strategy.entry to study.entry but this doesnt work on V5 and been trying to figure this out for hours.
Here are some sections of my script that will most probably be the sections needed to be updated.
Any tips and tricks will help!
strategy('v5 USOIL strat EMA', shorttitle='v5 USOIL strat EMA', overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
strategy.entry('Buy', strategy.long)
alert("e=oanda a=localhost s=west texas oil b=long q=38 t=market d=5", alert.freq_all)
alert("e=oanda a=localhost s=west texas oil q=38 t=market c=position", alert.freq_all)
Solution 1:[1]
Im pretty sure for v3 you have to change strategy.entry to study.entry
That is not quite true. There is no study.entry
function in any versions.
An indicator is an indicator. You don't buy or sell. You just display some information.
What you can do is, plot your buy and sell signals on chart, set alerts for them. So, have a variable for your buy condition, which you are using for your strategy, then plot it whenever it is true
.
To upgrade from v3
to v5
, you can read this guideline.
Solution 2:[2]
As far as I know. In version v5 there is no study, only (indicator or strategy).
You must specify this in the script header.
An example of Indicator or Strategy header in v5.
//@version=5
indicator(title="My Indicator", shorttitle="My Indicator", overlay=true, timeframe="", timeframe_gaps=true)
or
//@version=5
strategy(title="BackTest Strategy", shorttitle="BackTest Strategy", overlay=true, default_qty_value=100, default_qty_type=strategy.cash, initial_capital=100, currency=currency.USD)
If I understood. So you just want to convert between versions of Pine Script, ie from v3 to v4 or v5.
The Pine Script editor already has a built-in converter button to convert between different versions.
Image Pine Script editor: Functions menu.
Image Pine Script editor: Button to convert between different versions of the pine script.
Just select the version and click and the conversion will start automatically.
But remember that you must first specify a header containing a specific version v3, v4, v5, so that the converter knows where to start the conversion.
//@version=5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vitruvius |
Solution 2 |