0
votes

Hi all a bit new to trading view and pine, i have found a strategy i would like to use, and would like to convert it to be able to send signals instead. Tried following a guide online to convert to a study, but getting errors, hoping some one can help thanks. code is below.

//@version=2
strategy("GetTrendStrategy", overlay=true)
tim=input('160')
out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim, close)
plot(out1,color=red)
plot(out2,color=green)
longCondition = crossover(security(tickerid, tim, close),security(tickerid, tim, open))
if (longCondition)
    strategy.entry("long", strategy.long)
shortCondition = crossunder(security(tickerid, tim, close),security(tickerid, tim, open))
if (shortCondition)
    strategy.entry("short", strategy.short)
 

 This is my conversion. 

```//@Version.1 Signaler
study("GetTrendStrategy", overlay=true)
tim=input('160')
out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim, close)
plot(out1,color=red)
plot(out2,color=green)
buy = crossover(security(tickerid, tim, close),security(tickerid, tim, open))
alertcondition("buy", title="Buy Signal",message="Buy Sigbal Alertstrategy)
sell = crossunder(security(tickerid, tim, close),security(tickerid, tim, open))
alertcondition("buy", title="Buy Signal",message="Buy Sigbal Alertstrategy)
plot(close)
1

1 Answers

0
votes

This script will work.
Note that you only set the default value of a resolution input to a value from the pull-down menu.
See Setting the default value of a resolution input in TradingView for details.

//@version=4
study("GetTrendStrategy", overlay=true)

tim = input("180", type=input.resolution)

[out1, out2] = security(syminfo.tickerid, tim, [open,close])

buy  = crossover(out2,out1)
sell = crossunder(out2,out1)

alertcondition(buy,  title="Buy Signal",  message="Buy Signal Alertstrategy")
alertcondition(sell, title="Sell Signal", message="Sell Signal Alertstrategy")

plot(out1, color=color.red)
plot(out2, color=color.green)