'How can get version@4 of this scripts with same result of version@2

strategy("P&F scalp strat", shorttitle="MEXlongOnly_strat", overlay=true)

timeframe = input('1')

box = input('Traditional')

boxsize = input(1, type=float)

reversal = input(1)

pnf = pointfigure(tickerid, 'close', box, boxsize, reversal)

pnf_open= security(pnf, timeframe , open)

pnf_close= security(pnf, timeframe , close)

p1 = plot(pnf_open, title="pnf_open", color=green)

p2 = plot(pnf_close, title="pnf_close",color=maroon)

base = pnf_close> pnf_open? pnf_close: pnf_open

p0 = plot(base, title="base", color=gray)

fill(p0, p1, color=green, transp=70)

fill(p0, p2, color=maroon, transp=70)

entry() => (base > pnf_open)

exit() => (base > pnf_close)

alertcondition(entry(), title='buy', message='buy!')

alertcondition(exit(), title='sell', message='sell!')

strategy.risk.allow_entry_in(strategy.direction.long)

strategy.entry("Long", long=true, when=entry())

strategy.entry("close", false, when=exit())



Solution 1:[1]

When posting code please post as a code block for clarity.

To change the script add the version number and make changes as necessary. This migration guide should help. The easiest way is go in order, and debug in order. This guide covers changes from version 2 to version 3, consider using the var keyword when appropriate, and for other more detailed changes go to the release notes page and try searching for anything that's giving you trouble.

https://www.tradingview.com/pine-script-docs/en/v4/appendix/Pine_version_3_migration_guide.html?highlight=converting

Solution 2:[2]

I have updated your strategy to version 4 and version 5. I hope I have been of some help.

VERSION 5:

//@version=5
strategy('P&F scalp strat', shorttitle='MEXlongOnly_strat', overlay=true)

timeframe = input('1')
box = input('Traditional')
boxsize = input.float(1)
reversal = input(1)
pnf = ticker.pointfigure(syminfo.tickerid, 'close', box, boxsize, reversal)
pnf_open = request.security(pnf, timeframe, open)
pnf_close = request.security(pnf, timeframe, close)
p1 = plot(pnf_open, title='pnf_open', color=color.new(color.green, 0))
p2 = plot(pnf_close, title='pnf_close', color=color.new(color.maroon, 0))
base = pnf_close > pnf_open ? pnf_close : pnf_open
p0 = plot(base, title='base', color=color.new(color.gray, 0))

fill(p0, p1, color=color.new(color.green, 70))
fill(p0, p2, color=color.new(color.maroon, 70))

entry() =>
    base > pnf_open
exit() =>
    base > pnf_close

//alertcondition(entry(), title='buy', message='buy!')
//alertcondition(exit(), title='sell', message='sell!')

strategy.risk.allow_entry_in(strategy.direction.long)
strategy.entry('Long', direction=strategy.long, when=entry())
strategy.entry('close', strategy.short, when=exit())

VERSION 4:

//@version=4
// This source code is subject to the terms of the Mozilla Public    License 2.0 at https://mozilla.org/MPL/2.0/

strategy("P&F scalp strat", shorttitle="MEXlongOnly_strat", overlay=true)

timeframe = input('1')
box = input('Traditional')
boxsize = input(1, type=input.float)
reversal = input(1)
pnf = pointfigure(syminfo.tickerid, 'close', box, boxsize, reversal)
pnf_open = security(pnf, timeframe, open)
pnf_close = security(pnf, timeframe, close)
p1 = plot(pnf_open, title="pnf_open", color=color.green)
p2 = plot(pnf_close, title="pnf_close", color=color.maroon)
base = pnf_close > pnf_open ? pnf_close : pnf_open
p0 = plot(base, title="base", color=color.gray)

fill(p0, p1, color=color.green, transp=70)
fill(p0, p2, color=color.maroon, transp=70)

entry() =>
    base > pnf_open
exit() =>
    base > pnf_close

alertcondition(entry(), title='buy', message='buy!')
alertcondition(exit(), title='sell', message='sell!')
strategy.risk.allow_entry_in(strategy.direction.long)
strategy.entry("Long", long=true, when=entry())
strategy.entry("close", false, when=exit())

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 bajaco
Solution 2 Alex