Well pinescript is not AI, but a programming language. So you need to provide logic to how you would like the stop loss to be hit at or logic for any other variables that you want it to evaluate.
So your idea needs to be a complete idea , and not just i need profit of 100% and boom you have pinescript do the rest by itself.
I am attaching a script snippet by "theCrypster 2020" , in this you define the inputs for stop loss % and take profit and than it uses simple ema crosses to get the long buy.
Code: Select all
// © theCrypster 2020
//@version=4
strategy("Fixed Percent Stop Loss & Take Profit %", overlay=true)
eg1 = ema(close, 5)
eg2 = ema(close, 32)
long = crossover(eg1, eg2)
short = crossunder(eg1, eg2)
strategy.entry("LONG", strategy.long, when=long)
strategy.entry("SHORT", strategy.short, when=short)
stopPer = input(5.0, title='Stop Loss %', type=input.float) / 100
takePer = input(10.0, title='Take Profit %', type=input.float) / 100
longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)
if strategy.position_size > 0
strategy.exit(id="Close Long", stop=longStop, limit=longTake)
if strategy.position_size < 0
strategy.exit(id="Close Short", stop=shortStop, limit=shortTake)