'I confuse convert Tradingview Strategy to study strategy.position_size and strategy.position_avg_price to study

I try to convert Strategty to study I don't know it right?

if Long 
    strategy.entry("L", strategy.long)
if Short
    strategy.entry("S", strategy.short)

I convert to this

alertcondition(Long,"Long","Take Long position")    
alertcondition(Short,"Short","Take Short position")
plotshape(Long, text = "Long",color=color.green)
plotshape(Short, text = "Short",color=color.red)   

//I think it is wrong because pyramiding=1  

And die on this line too

per(pcnt) =>
    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)
stoploss=input(title=" stop loss", defval=9, minval=0.01)
los = per(stoploss)
q=input(title=" qty percent", defval=100, minval=1)

tp=input(title=" Take profit", defval=1.3, minval=0.01)

strategy.exit("tp", qty_percent = q, profit = per(tp), loss = los)

I don't know how to convert please tell me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source