-2

Hi i want a modified pine editor script of RSI STRATEGY INDICATOR ,I want to set the target and stoploss in percentage from the entry price . example Buy Entry price=100 then the stoploss should be -1% of entry price(100), and target should be +5% of entry price(100). similarly for short trade vice versa

strategy("RSI Strategy", overlay=true) length = input( 14 ) 
overSold = input( 30 ) 
overBought = input( 70 ) 
price = close 
vrsi = ta.rsi(price, length) 
co = ta.crossover(vrsi, overSold) 
cu = ta.crossunder(vrsi, overBought) 
if (not na(vrsi)) 
    if (co) 
         strategy.entry("RsiLE", strategy.long, comment="RsiLE") 
    if (cu) 
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
G.Lebret
  • 2,826
  • 2
  • 16
  • 27
Amer
  • 18
  • 3
  • 1
    It is the third time you open the same question, please delete the old one (https://stackoverflow.com/questions/74733057/need-modification-in-rsi-strategy-indicator-of-tradingview and https://stackoverflow.com/questions/74596784/rsi-strategy-indicator-tradingview) – G.Lebret Dec 09 '22 at 18:08

1 Answers1

0

You should modify your code like this :

// This source code is subject to the terms of the Mozilla Public 
License 2.0 at https://mozilla.org/MPL/2.0/
// © mentalRock19315

//@version=5

strategy("RSI Strategy", overlay=true) 
length = input( 14 ) 
overSold = input( 30 ) 
overBought = input( 70 ) 
price = close 
vrsi = ta.rsi(price, length) 
co = ta.crossover(vrsi, overSold) 
cu = ta.crossunder(vrsi, overBought) 
if (not na(vrsi)) 
    if (co) 
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        strategy.exit("My StopLoss", from_entry="RsiLE", stop = price*0.99, limit = price*0.99)
        strategy.exit("My Target", from_entry="RsiLE", stop = price*1.05, limit = price*1.05)
    if (cu) 
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        strategy.exit("My StopLoss", from_entry="RsiSE", stop = price*0.99, limit = price*0.99)
        strategy.exit("My Target", from_entry="RsiSE", stop = price*1.05, limit = price*1.05)

This code has no errors

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • Thanks alot sir but , I need a modification in this mentioned pine script as in this pine script i can't setup tar and sl in percentage,I want to set the target and stoploss in percentage from the entry price . example Buy Entry price=100 then the stop loss should be -1% of the entry price(100), and the target should be +5% of entry price(100). similarly for short trade vice versa https://kb.mycoder.pro/wp-content/uploads/2021/01/13.-RSI.txt – Amer Dec 12 '22 at 17:55
  • stop = price*0.99 set a stop loss at -1% of your entry price, you should try it – G.Lebret Dec 13 '22 at 02:11