Pine Script v4 · Strategy
RSI W Pattern strategy
A Pine Script v4 strategy built on RSI (close, 5), EMA (close, 5) and Crossover (myRsi, 75). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 5 settings; defaults include RSI Period 5, look for W pattern bottom edges well below RSI level (BUY) 65 and Long Term EMA 50.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does RSI W Pattern strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
- How did RSI W Pattern strategy do on BTCUSDT 1D with default settings?
- +27.55%
- From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can RSI W Pattern strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does RSI W Pattern strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI W Pattern strategy run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- RSI
- Middle Line
- Overbought
- Oversold
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +27.55%
- $27,547.30
- Buy and hold
- +102.5%
- same period
- Closed trades
- 15
- 11 won · 4 lost
- Profitable
- 73.3%
- of closed trades
- Profit factor
- 2.32
- gross profit ÷ gross loss
- Max drawdown
- 14.42%
- −$16,214.10
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
ema(close, 5) ignores the settings line 19
Line 19 hard-codes 5 where line 20 uses “Short Term EMA”. Changing those settings moves one band but not this one.
ema(close,5)ema(close, emaS) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 35, 37, 68, 71. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 51
transp = on line 51, 52, 64. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 35
long = on line 35, 37. v5 writes it as direction = strategy.long or strategy.short.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames rsi → ta.rsi, ema → ta.ema, crossover → ta.crossover.
- 4 strategy calls use the when = argument (line 35, 37, 68, 71). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: rsi → ta.rsi
- Line 19: ema → ta.ema
- Line 20: ema → ta.ema
- Line 20: ema → ta.ema
- Line 35: long = true → direction = strategy.long
7 more edits
- Line 37: long = true → direction = strategy.long
- Line 37: crossover → ta.crossover
- Line 51: transp = 90 → color.new(#9915FF, 90)
- Line 52: transp = 0 → color.new(color.purple, 0)
- Line 64: transp = 40 → color.new(strategy.position_size>0?color.green:na, 40)
- Line 66: crossover → ta.crossover
- Line 68: crossover → ta.crossover
⋯// © mohanee-//@version=4+//@version=5strategy(title="RSI W Pattern strategy", pyramiding=2, shorttitle="RSI W Pattern", overlay = false)⋯//rsiWp1=false-myRsi = rsi(close,len)+myRsi = ta.rsi(close,len)//longEmaVal=ema(close,emaL)//shortEmaVal=ema(close,emaS)-entryEma=ema(close,5) // This is used as filetr for BUY+entryEma=ta.ema(close,5) // This is used as filetr for BUY-isEma20AboveEma50=ema(close,emaS)>ema(close,emaL) ? true : false +isEma20AboveEma50=ta.ema(close,emaS)>ta.ema(close,emaL) ? true : false //W Pattern⋯//initial entry-strategy.entry("RSI_W_LE", comment="Buy" , long=true, when=longCondition )+strategy.entry("RSI_W_LE", comment="Buy" , direction = strategy.long, when=longCondition )//legging in to existing -strategy.entry("RSI_W_LE",comment="Add", long=true, when=strategy.position_size>0 and crossover(myRsi,10 ))+strategy.entry("RSI_W_LE",comment="Add", direction = strategy.long, when=strategy.position_size>0 and ta.crossover(myRsi,10 ))//calculate stoploss value⋯osLevel = hline(30, title="Oversold", color=color.purple, linestyle=hline.style_dashed)-fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)+fill(obLevel, osLevel, title="Background", color=color.new(#9915FF, 90))plotshape(⋯ location=location.absolute,- color=color.purple,+ color=color.new(color.purple, 0),- textcolor=color.yellow,- transp=0+ textcolor=color.yellow ) -bgcolor(strategy.position_size>0?color.green:na, transp=40, title='In Long Position')+bgcolor(color.new(strategy.position_size>0?color.green:na, 40), title='In Long Position')//take profit or close when RSI reaches 75 -takeProfit=crossover(myRsi,75)+takeProfit=ta.crossover(myRsi,75)//close when RSi reaches profit level -strategy.close("RSI_W_LE", comment="TP Exit", qty=strategy.position_size,when=crossover(myRsi,75) and close>strategy.position_avg_price )+strategy.close("RSI_W_LE", comment="TP Exit", qty=strategy.position_size,when=ta.crossover(myRsi,75) and close>strategy.position_avg_price )//close everything when stoploss hit ⋯Same 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 35: when = longCondition → if block
3 more edits
- Line 37: when = strategy.position_size>0 and ta.crossover(myRsi,10 ) → if block
- Line 67: when = ta.crossover(myRsi,75) and close>strategy.position_avg_price → if block
- Line 70: when = longCloseCondition → if block
⋯//Exit when RSI reaches 75 -len = input(title="RSI Period", minval=1, defval=5)+len = input.int(title="RSI Period", minval=1, defval=5)-buyRsiEntry = input(title="look for W pattern bottom edges well below RSI level (BUY) ", minval=10, defval=65, maxval=70)+buyRsiEntry = input.int(title="look for W pattern bottom edges well below RSI level (BUY) ", minval=10, defval=65, maxval=70)//numberOfBars = input(title="Number of Bars in W pattern ", minval=4, defval=4, maxval=6)-emaL = input(title="Long Term EMA", minval=1, defval=50, maxval=200)+emaL = input.int(title="Long Term EMA", minval=1, defval=50, maxval=200)-emaS = input(title="Short Term EMA", minval=1, defval=20, maxval=200)+emaS = input.int(title="Short Term EMA", minval=1, defval=20, maxval=200)-stopLoss = input(title="Stop Loss %", minval=1, defval=8, maxval=10)+stopLoss = input.int(title="Stop Loss %", minval=1, defval=8, maxval=10)//rsiWp1=false⋯//initial entry-strategy.entry("RSI_W_LE", comment="Buy" , direction = strategy.long, when=longCondition )+if longCondition+ strategy.entry("RSI_W_LE", comment="Buy" , direction = strategy.long )//legging in to existing -strategy.entry("RSI_W_LE",comment="Add", direction = strategy.long, when=strategy.position_size>0 and ta.crossover(myRsi,10 ))+if strategy.position_size>0 and ta.crossover(myRsi,10 )+ strategy.entry("RSI_W_LE",comment="Add", direction = strategy.long)//calculate stoploss value⋯//close when RSi reaches profit level -strategy.close("RSI_W_LE", comment="TP Exit", qty=strategy.position_size,when=ta.crossover(myRsi,75) and close>strategy.position_avg_price )+if ta.crossover(myRsi,75) and close>strategy.position_avg_price+ strategy.close("RSI_W_LE", comment="TP Exit", qty=strategy.position_size )//close everything when stoploss hit longCloseCondition=close<(strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) ) //or crossunder(myRsi,30)-strategy.close("RSI_W_LE", comment="SL Exit", qty=strategy.position_size,when=longCloseCondition )+if longCloseCondition+ strategy.close("RSI_W_LE", comment="SL Exit", qty=strategy.position_size )Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 15 before, 7 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © mohanee-//@version=5+//@version=6strategy(title="RSI W Pattern strategy", pyramiding=2, shorttitle="RSI W Pattern", overlay = false)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| RSI Period | 5 | int · min 1 | myRsi |
| look for W pattern bottom edges well below RSI level (BUY) | 65 | int · min 10 · max 70 | longCondition |
| Long Term EMA | 50 | int · min 1 · max 200 | isEma20AboveEma50 |
| Short Term EMA | 20 | int · min 1 · max 200 | isEma20AboveEma50 |
| Stop Loss % | 8 | int · min 1 · max 10 | stopLossValue longCloseCondition |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, RSI Period (5)myRsi · line 16 - EMA (
ema,ta.emain v5)close, 5entryEma · line 19 - EMA (
ema,ta.emain v5)close, Short Term EMA (20)isEma20AboveEma50 · line 20 - Crossover (
crossover,ta.crossoverin v5)myRsi, 75takeProfit · line 66
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open RSI_W_LE long | longConditionisEma20AboveEma50 and rsiWp1 and (myRsi<=buyRsiEntry and myRsi>=30) | On | 35 |
| Open RSI_W_LE long | strategy.position_size>0 and crossover(myRsi,10 ) | On | 37 |
| Close RSI_W_LE | crossover(myRsi,75) and close>strategy.position_avg_price | On | 68 |
| Close RSI_W_LE | longCloseConditionclose<(strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) ) | On | 71 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +27.5% | +102.5% | 15 | 73% | 2.32 | 14.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.3% | +5.5% | 14 | 86% | 1.32 | 13.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.2% | +9.8% | 13 | 69% | 1.88 | 1.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.4% | +8.4% | 17 | 82% | 2.20 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 15 | 33% | 0.31 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 16 | 75% | 1.80 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 15 | 73% | 1.09 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 16 | 75% | 0.75 | 0.2% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (RSI Period 6, Long Term EMA 85) made +48.7% before 26 Dec 2025 and +17.2% after it, against +9.2% for the defaults. 85% of the 48 combinations made money in-sample and 100% out-of-sample.
| Long Term EMA ↓ · RSI Period → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 25 | +27% | +15% | +31% | +34% | +17% | −1% |
| 30 | +31% | +10% | +26% | +29% | +12% | −6% |
| 35 | +31% | +10% | +26% | +29% | +12% | −6% |
| 43 | +31% | +10% | +26% | +29% | +12% | −6% |
| 50 | +33% | +5% | +18% | +21% | +7% | −7% |
| 60 | +38% | +11% | +29% | +32% | +17% | −6% |
| 70 | +38% | +11% | +29% | +32% | +17% | −6% |
| 85 | +33% | +28% | +46% | +49% | +28% | +5% |
| Long Term EMA ↓ · RSI Period → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 25 | +10% | +11% | +9% | +17% | +17% | +17% |
| 30 | +10% | +11% | +9% | +17% | +17% | +17% |
| 35 | +10% | +11% | +9% | +17% | +17% | +17% |
| 43 | +10% | +11% | +9% | +17% | +17% | +17% |
| 50 | +10% | +11% | +9% | +17% | +17% | +17% |
| 60 | +10% | +11% | +9% | +17% | +17% | +17% |
| 70 | +10% | +11% | +9% | +17% | +17% | +17% |
| 85 | +10% | +11% | +9% | +17% | +17% | +17% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 7 | 71% | $17,648.00 |
| Sideways market | 8 | 75% | $9,899.23 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
15.7%
The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 7.8% to 15.7%; the tick is what actually happened, 10.3%. Order luck alone moves it this much.
All 15 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Apr 2024 63,793.40 | 2 May 2024 58,365.00 | 15 | −$5,428.43 |
| long | 19 Apr 2024 63,470.10 | 2 May 2024 58,365.00 | 13 | −$5,105.12 |
| long | 2 Jun 2024 67,766.80 | 5 Jun 2024 70,537.80 | 3 | $2,770.99 |
| long | 4 Jun 2024 68,809.90 | 5 Jun 2024 70,537.80 | 1 | $1,727.94 |
| long | 23 Oct 2024 67,426.00 | 30 Oct 2024 72,736.40 | 7 | $5,310.40 |
| long | 25 Oct 2024 68,198.30 | 30 Oct 2024 72,736.40 | 5 | $4,538.14 |
| long | 4 Dec 2024 95,849.70 | 16 Dec 2024 104,464.00 | 12 | $8,614.30 |
| long | 15 Feb 2025 97,500.50 | 26 Feb 2025 88,680.40 | 11 | −$8,820.08 |
| long | 16 Jun 2025 105,594.00 | 11 Jul 2025 116,010.00 | 25 | $10,416.00 |
| long | 23 Aug 2025 116,936.00 | 12 Sep 2025 115,483.00 | 20 | −$1,453.31 |
| long | 29 Aug 2025 112,567.00 | 12 Sep 2025 115,483.00 | 14 | $2,915.79 |
| long | 21 Sep 2025 115,686.00 | 2 Oct 2025 118,595.00 | 11 | $2,909.36 |
| long | 1 Sep 2026 78,581.30 | 4 Sep 2026 81,270.40 | 3 | $2,689.07 |
| long | 6 Sep 2026 79,831.80 | 20 Sep 2026 81,250.00 | 14 | $1,418.24 |
| long | 17 Sep 2026 76,206.00 | 20 Sep 2026 81,250.00 | 3 | $5,043.99 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| RSI W Pattern strategy this page | — | v4 strategy | +27.5% | 15 | 14.4% |
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
| Bitpanda Coinrule Template by joshuajcoop01 | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrule | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI of VWAP by mohanee | rsi ema | v4 strategy | No trades on this market | ||
| EMA SCALPEUR + RSi - SHORT by YukalMoon | rsi ema | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | With a workaround 1,000 bars in 39 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 35, 37) so the engine trades the way the script says.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © mohanee//@version=4strategy(title="RSI W Pattern strategy", pyramiding=2, shorttitle="RSI W Pattern", overlay = false)//Strategy Rules//ema20 is above ema50//RSI5 making W pattern in oversold area or just below 70 level , you can define the value for parameter buyRsiEntry --- dont go beyond 70//Exit when RSI reaches 75 len = input(title="RSI Period", minval=1, defval=5)buyRsiEntry = input(title="look for W pattern bottom edges well below RSI level (BUY) ", minval=10, defval=65, maxval=70)//numberOfBars = input(title="Number of Bars in W pattern ", minval=4, defval=4, maxval=6)emaL = input(title="Long Term EMA", minval=1, defval=50, maxval=200)emaS = input(title="Short Term EMA", minval=1, defval=20, maxval=200)stopLoss = input(title="Stop Loss %", minval=1, defval=8, maxval=10)//rsiWp1=falsemyRsi = rsi(close,len)//longEmaVal=ema(close,emaL)//shortEmaVal=ema(close,emaS)entryEma=ema(close,5) // This is used as filetr for BUYisEma20AboveEma50=ema(close,emaS)>ema(close,emaL) ? true : false //W Pattern//rsiWp1 = myRsi>myRsi[1] and myRsi>=30 and myRsi[1]<myRsi[2] and myRsi[2]>myRsi[3] and myRsi[3]<myRsi[4] //This is published onersiWp1 = myRsi>myRsi[1] and myRsi>=30 and myRsi[1]<myRsi[2] and myRsi[2]>myRsi[3] and myRsi[3]<myRsi[4] and (low[1]<=low[4] or low[3]<=low[4] ) // looking for recent low//rsiWp1 = myRsi>myRsi[1] and myRsi>=30 and myRsi[1]<myRsi[2] and myRsi[2]>myRsi[3] and myRsi[3]<myRsi[4] //Ths one has 92% win rate and 4.593 prfit factor//long condition filters//1. ema20 > ema50//2. Rsi5 has W pattern//3. current RSI <= 65 (parameter buyRsiEntry) (dont go beyond 70 , becuase that is already overbought area)//4. current price low/close is below 5 ema --- looking for pullback -- OptionallongCondition = isEma20AboveEma50 and rsiWp1 and (myRsi<=buyRsiEntry and myRsi>=30) //and (low<entryEma or close<entryEma) --- if this optional required , add it to above conditionpatternText=" W "barcolor(longCondition?color.yellow:na)//initial entrystrategy.entry("RSI_W_LE", comment="Buy" , long=true, when=longCondition )//legging in to existing strategy.entry("RSI_W_LE",comment="Add", long=true, when=strategy.position_size>0 and crossover(myRsi,10 ))//calculate stoploss valuestopLossValue=strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) rsiPlotColor=longCondition ?color.yellow:color.purpleplot(myRsi, title="RSI", linewidth=2, color=color.purple)// plot(myRsi, title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[1], title="RSI", linewidth=2, color=rsiWp1==true?color.yellow:color.purple) //plot(myRsi[2], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[3], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[4], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) hline(40, title="Middle Line", color=color.blue, linestyle=hline.style_dashed)obLevel = hline(75, title="Overbought", color=color.red, linestyle=hline.style_dashed)osLevel = hline(30, title="Oversold", color=color.purple, linestyle=hline.style_dashed)fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)plotshape( longCondition ? myRsi[1] : na, offset=-1, title="W Pattern", text=patternText, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.yellow, transp=0 ) bgcolor(strategy.position_size>0?color.green:na, transp=40, title='In Long Position')//take profit or close when RSI reaches 75 takeProfit=crossover(myRsi,75)//close when RSi reaches profit level strategy.close("RSI_W_LE", comment="TP Exit", qty=strategy.position_size,when=crossover(myRsi,75) and close>strategy.position_avg_price )//close everything when stoploss hit longCloseCondition=close<(strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) ) //or crossunder(myRsi,30)strategy.close("RSI_W_LE", comment="SL Exit", qty=strategy.position_size,when=longCloseCondition )