Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy

A Pine Script v4 strategy built on SMA (close, 21), Stdev (close, 21) and Crossover or Crossunder (close, lowerBand). It has 5 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 1000 in cash and pays 0.1 commission. 48 settings; defaults include Simple bot simple, Base order size 10 and Safety order size 400.

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 [laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did [laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Can [laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does [laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does [laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy run in Zeal Terminal?
Yes
It compiles in 74 ms and runs 1,000 bars in 135 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (48)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$900$1,823Equity from $900
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $900 starting capital, commission as the script sets it. 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

    The “over” option calculates CROSSOVER line 46

    Choosing over in “Entrry at Cross Over/Under Lower” runs ta.crossover, not ta.over. Anyone picking over gets a different average from the one they asked for.

    cross == 'over' ? ta.crossover(cross == 'over' ? ta.over(
  • Likely bug

    crossover(close, lowerBand) ignores the settings line 46

    Line 46 hard-codes close where line 115 uses “Offset”. Changing those settings moves one band but not this one.

    crossover(close, lowerBand)crossover(macd, lowerBand)
  • Likely bug

    crossover(high, upperBand) ignores the settings line 50

    Line 50 hard-codes high where line 115 uses “Offset”. Changing those settings moves one band but not this one.

    crossover(high, upperBand)crossover(macd, upperBand)
  • Likely bug

    crossunder(close, lowerBand) ignores the settings line 46

    Line 46 hard-codes close where line 116 uses “Offset”. Changing those settings moves one band but not this one.

    crossunder(close, lowerBand)crossunder(macd, lowerBand)
  • Check

    1 setting does nothing

    “Use long?” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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 156, 158. The upgraded version below moves each call inside an if block.

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 sma → ta.sma, stdev → ta.stdev, crossover → ta.crossover, crossunder → ta.crossunder, ema → ta.ema, wma → ta.wma, rma → ta.rma, hma → ta.hma, pow → math.pow, linreg → ta.linreg, change → ta.change, rsi → ta.rsi.
  • 2 strategy calls use the when = argument (line 156, 158). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 1: //@version=4 → //@version=5
  • Line 35: sma → ta.sma
  • Line 36: sma → ta.sma
  • Line 37: stdev → ta.stdev
  • Line 46: crossover → ta.crossover
  • Line 46: crossunder → ta.crossunder
89 more edits
  • Line 50: crossover → ta.crossover
  • Line 78: input(type = input.integer) → input.int()
  • Line 79: input(type = input.integer) → input.int()
  • Line 80: input(type = input.source) → input.source()
  • Line 81: input(type = input.integer) → input.int()
  • Line 86: type is reserved in v5: renamed type_
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: ema → ta.ema
  • Line 87: sma → ta.sma
  • Line 87: wma → ta.wma
  • Line 87: rma → ta.rma
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: ema → ta.ema
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: sma → ta.sma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: wma → ta.wma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: rma → ta.rma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: hma → ta.hma
  • Line 87: ema → ta.ema
  • Line 99: pow → math.pow
  • Line 105: linreg → ta.linreg
  • Line 111: change → ta.change
  • Line 112: change → ta.change
  • Line 115: crossover → ta.crossover
  • Line 116: crossunder → ta.crossunder
  • Line 119: change → ta.change
  • Line 120: change → ta.change
  • Line 125: rsi → ta.rsi
  • Line 128: change → ta.change
  • Line 128: change → ta.change
  • Line 129: change → ta.change
  • Line 129: change → ta.change
  • Line 139: change → ta.change
  • Line 139: change → ta.change
  • Line 140: change → ta.change
  • Line 140: change → ta.change
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯// VARS-short_sma        = sma(close, sma_short_val)+short_sma        = ta.sma(close, sma_short_val)-long_sma         = sma(close, sma_long_val)+long_sma         = ta.sma(close, sma_long_val)-stdDev           = stdev(close, sma_short_val)+stdDev           = ta.stdev(close, sma_short_val)upperBand        = short_sma + (stdDev * ubOffset)⋯// Market Conditions-goodBuy    = cross=="over"?crossover(close, lowerBand):crossunder(close, lowerBand) // Buy when close crossing lower band+goodBuy    = cross=="over"?ta.crossover(close, lowerBand):ta.crossunder(close, lowerBand) // Buy when close crossing lower bandsafety     = initial_deviation and (1-(close/strategy.position_avg_price))/.01 > strategy.opentrades-1 * safety_step and strategy.opentrades <= safety_max // SO when price deviates below SO threshold %⋯takeprofit = close >= takeprofit_value // Take profit condition - true if closing price for current bar is >= take profit percentage-goodSell = crossover(high, upperBand)+goodSell = ta.crossover(high, upperBand)// goodSell is currently unused for any practical purpose. If you wish to try it, switch these two values. ⋯// Getting inputs-fast_length = input(title="Fast Length", type=input.integer, defval=23,group="MACD")+fast_length = input.int(title="Fast Length", defval=23,group="MACD")-slow_length = input(title="Slow Length", type=input.integer, defval=16,group="MACD")+slow_length = input.int(title="Slow Length", defval=16,group="MACD")-src = input(title="Source", type=input.source, defval=open,group="MACD")+src = input.source(title="Source", defval=open,group="MACD")-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9,group="MACD")+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group="MACD")sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")⋯// Calculating-ma(source,length,type)=>+ma(source,length,type_)=>-    type=="FEMA"?4*ema(source,length)-ema(ema(ema(ema(source,length),length),length),length):type=="FSMA"?4*sma(source,length)-sma(sma(sma(sma(source,length),length),length),length):type=="FWMA"?4*wma(source,length)-wma(wma(wma(wma(source,length),length),length),length):type=="FRMA"?4*rma(source,length)-rma(rma(rma(rma(source,length),length),length),length):type=="TEMA"?3*ema(source,length)-ema(ema(ema(source,length),length),length):type=="TSMA"?3*sma(source,length)-sma(sma(sma(source,length),length),length):type=="TWMA"?3*wma(source,length)-wma(wma(wma(source,length),length),length):type=="TRMA"?3*rma(source,length)-rma(rma(rma(source,length),length),length):type=="EMA"?ema(source,length):type=="SMA"?sma(source,length):type=="WMA"?wma(source,length):type=="RMA"?rma(source,length):type=="DEMA"?2*ema(source,length)-ema(ema(source,length),length):type=="DSMA"?2*sma(source,length)-sma(sma(source,length),length):type=="DWMA"?2*wma(source,length)-wma(wma(source,length),length):type=="DRMA"?2*rma(source,length)-rma(rma(source,length),length):type=="HMA"?hma(source,length):type=="DHMA"?2*hma(source,length)-hma(hma(source,length),length):type=="THMA"?3*hma(source,length)-hma(hma(hma(source,length),length),length):type=="FHMA"?4*hma(source,length)-hma(hma(hma(hma(source,length),length),length),length):ema(source,length)+    type_=="FEMA"?4*ta.ema(source,length)-ta.ema(ta.ema(ta.ema(ta.ema(source,length),length),length),length):type_=="FSMA"?4*ta.sma(source,length)-ta.sma(ta.sma(ta.sma(ta.sma(source,length),length),length),length):type_=="FWMA"?4*ta.wma(source,length)-ta.wma(ta.wma(ta.wma(ta.wma(source,length),length),length),length):type_=="FRMA"?4*ta.rma(source,length)-ta.rma(ta.rma(ta.rma(ta.rma(source,length),length),length),length):type_=="TEMA"?3*ta.ema(source,length)-ta.ema(ta.ema(ta.ema(source,length),length),length):type_=="TSMA"?3*ta.sma(source,length)-ta.sma(ta.sma(ta.sma(source,length),length),length):type_=="TWMA"?3*ta.wma(source,length)-ta.wma(ta.wma(ta.wma(source,length),length),length):type_=="TRMA"?3*ta.rma(source,length)-ta.rma(ta.rma(ta.rma(source,length),length),length):type_=="EMA"?ta.ema(source,length):type_=="SMA"?ta.sma(source,length):type_=="WMA"?ta.wma(source,length):type_=="RMA"?ta.rma(source,length):type_=="DEMA"?2*ta.ema(source,length)-ta.ema(ta.ema(source,length),length):type_=="DSMA"?2*ta.sma(source,length)-ta.sma(ta.sma(source,length),length):type_=="DWMA"?2*ta.wma(source,length)-ta.wma(ta.wma(source,length),length):type_=="DRMA"?2*ta.rma(source,length)-ta.rma(ta.rma(source,length),length):type_=="HMA"?ta.hma(source,length):type_=="DHMA"?2*ta.hma(source,length)-ta.hma(ta.hma(source,length),length):type_=="THMA"?3*ta.hma(source,length)-ta.hma(ta.hma(ta.hma(source,length),length),length):type_=="FHMA"?4*ta.hma(source,length)-ta.hma(ta.hma(ta.hma(ta.hma(source,length),length),length),length):ta.ema(source,length)fast_ma = ma(src,fast_length,sma_source1)  ⋯    if not na(macd[1])-        macd:=pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])+        macd:=math.pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")⋯if use_linreg-    macd:=linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))+    macd:=ta.linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)⋯on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")-aperturaLong = change(macd)>0//crossover(macd,signal)+aperturaLong = ta.change(macd)>0//crossover(macd,signal)-aperturashort=not (change(macd)>0)//crossunder(macd,signal)+aperturashort=not (ta.change(macd)>0)//crossunder(macd,signal)if on_cross    on_minmax:=false-    aperturaLong := crossover(macd,signal)+    aperturaLong := ta.crossover(macd,signal)-    aperturashort := crossunder(macd,signal)+    aperturashort := ta.crossunder(macd,signal)if on_minmax    on_cross:=false-    aperturaLong := change(macd)>0//crossover(macd,signal)+    aperturaLong := ta.change(macd)>0//crossover(macd,signal)-    aperturashort:=change(macd)<0//crossunder(macd,signal)+    aperturashort:=ta.change(macd)<0//crossunder(macd,signal)rsiFilter = input(false,title="Use RSI filter?",group="RSI")⋯srcr=input(close,title="RSI source",group="RSI")-rsi=rsi(srcr,len)+rsi=ta.rsi(srcr,len)ovb=input(90,title="Overbought height",group="RSI") ovs=input(45,title="Oversold height",group="RSI")-okLong=rsi<ovb and change(macd)>0 and change(macd)[1]<=0+okLong=rsi<ovb and ta.change(macd)>0 and ta.change(macd)[1]<=0-okShort=rsi>ovs and change(macd)<0 and change(macd)[1]>=0+okShort=rsi>ovs and ta.change(macd)<0 and ta.change(macd)[1]>=0if not rsiFilter⋯if rsiTP-    aperturaLong := change(macd)>0 and change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)+    aperturaLong := ta.change(macd)>0 and ta.change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)-    aperturashort:=change(macd)<0 and change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)+    aperturashort:=ta.change(macd)<0 and ta.change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)if not rsiTP⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 10: input() → input.string()
  • Line 11: input() → input.string()
  • Line 12: input() → input.string()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.float()
40 more edits
  • Line 16: input() → input.float()
  • Line 17: input() → input.int()
  • Line 18: input() → input.float()
  • Line 19: input() → input.int()
  • Line 20: input() → input.float()
  • Line 22: input() → input.int()
  • Line 23: input() → input.int()
  • Line 24: input() → input.float()
  • Line 25: input() → input.float()
  • Line 26: input() → input.string()
  • Line 28: input() → input.int()
  • Line 29: input() → input.int()
  • Line 30: input() → input.int()
  • Line 31: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 82: input() → input.string()
  • Line 83: input() → input.string()
  • Line 84: input() → input.string()
  • Line 93: input() → input.bool()
  • Line 94: input() → input.float()
  • Line 95: input() → input.int()
  • Line 100: input() → input.bool()
  • Line 102: input() → input.int()
  • Line 102: input() → input.string()
  • Line 103: input() → input.bool()
  • Line 105: input() → input.int()
  • Line 105: input() → input.int()
  • Line 109: input() → input.bool()
  • Line 110: input() → input.bool()
  • Line 121: input() → input.bool()
  • Line 122: input() → input.bool()
  • Line 123: input() → input.int()
  • Line 124: input() → input.source()
  • Line 126: input() → input.int()
  • Line 127: input() → input.int()
  • Line 134: input() → input.bool()
  • Line 135: input() → input.bool()
  • Line 156: when = strategy.opentrades <= 0 → if block
  • Line 158: when = strategy.opentrades > 0 → if block
⋯// 3Commas Bot settinsg-bot_type                = input(title="Simple bot", defval="simple", options=["simple", "composite"])+bot_type                = input.string(title="Simple bot", defval="simple", options=["simple", "composite"])-bot_id                  = input(title="3Commas Bot ID", defval="")+bot_id                  = input.string(title="3Commas Bot ID", defval="")-email_token             = input(title="Bot Email Token", defval="")+email_token             = input.string(title="Bot Email Token", defval="")-base_order_size         = input(title="Base order size",minval=10, step=1, defval=10)+base_order_size         = input.int(title="Base order size",minval=10, step=1, defval=10)-safety_order_size       = input(title="Safety order size", minval=15, step=1, defval=400)+safety_order_size       = input.int(title="Safety order size", minval=15, step=1, defval=400)-volume_scale            = input(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)+volume_scale            = input.float(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)-safety_step             = input(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)+safety_step             = input.float(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)-safety_max              = input(title="Max Number of Safety Orders", minval=0, step=1, defval=2)+safety_max              = input.int(title="Max Number of Safety Orders", minval=0, step=1, defval=2)-initial_deviation_input = input(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=1.54) * 0.01+initial_deviation_input = input.float(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=1.54) * 0.01-stoploss_input          = input(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01+stoploss_input          = input.int(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01-takeprofit_input        = input(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01+takeprofit_input        = input.float(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01// USER INPUTS-sma_short_val           = input(title="Short MA Window", defval=21)+sma_short_val           = input.int(title="Short MA Window", defval=21)-sma_long_val            = input(title="Long MA Window", defval=100)+sma_long_val            = input.int(title="Long MA Window", defval=100)-ubOffset                = input(title="Upper Band Offset", defval=2.2, step=0.5)+ubOffset                = input.float(title="Upper Band Offset", defval=2.2, step=0.5)-lbOffset                = input(title="Lower Band Offset", defval=2.40, step=0.5)+lbOffset                = input.float(title="Lower Band Offset", defval=2.40, step=0.5)-cross                   = input(title="Entrry at Cross Over/Under Lower", defval="under", options=["over", "under"])+cross                   = input.string(title="Entrry at Cross Over/Under Lower", defval="under", options=["over", "under"])// Backtesting Date Ranges-startDate  = input(title="Start Date", defval=1, minval=1, maxval=31)+startDate  = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear  = input(title="Start Year", defval=2016, minval=1800, maxval=2100)+startYear  = input.int(title="Start Year", defval=2016, minval=1800, maxval=2100)-endDate    = input(title="End Date", defval=31, minval=1, maxval=31)+endDate    = input.int(title="End Date", defval=31, minval=1, maxval=31)-endMonth   = input(title="End Month", defval=12, minval=1, maxval=12)+endMonth   = input.int(title="End Month", defval=12, minval=1, maxval=12)-endYear    = input(title="End Year", defval=2022, minval=1800, maxval=2100)+endYear    = input.int(title="End Year", defval=2022, minval=1800, maxval=2100)// VARS⋯signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group="MACD")-sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_source1 = input.string(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")-sma_source2 = input(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_source2 = input.string(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")-sma_signal = input(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")+sma_signal = input.string(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")// Calculating⋯hist = macd - signal //Differenza tra la differenza precedente e la media mobile della differenza-use_stress=input(true,title="Use stress on recent bars",group="Stress")+use_stress=input.bool(true,title="Use stress on recent bars",group="Stress")-recent_stress=input(0.41,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)+recent_stress=input.float(0.41,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)-level=input(6,title="Level of stress",group="Stress")+level=input.int(6,title="Level of stress",group="Stress")if use_stress ⋯        macd:=math.pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])-use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")+use_ma= input.bool(true,title="Use moving average (MACD)?",group="Moving Average")if use_ma-    macd:=ma(macd,input(36,title="Length",group="Moving Average"),input(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))+    macd:=ma(macd,input.int(36,title="Length",group="Moving Average"),input.string(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))-use_linreg= input(true,title="Use linear regression (MACD)?",group="Linear Regression")+use_linreg= input.bool(true,title="Use linear regression (MACD)?",group="Linear Regression")if use_linreg-    macd:=ta.linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))+    macd:=ta.linreg(macd,input.int(10,title="Length",group="Linear Regression"),input.int(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)⋯//hist == istogramma (differenza tra macd e media mobile)-on_cross = input(false,title="Use cross macd and signal",group="Condition entry/exit")+on_cross = input.bool(false,title="Use cross macd and signal",group="Condition entry/exit")-on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")+on_minmax = input.bool(true,title="Use min/max macd",group="Condition entry/exit")aperturaLong = ta.change(macd)>0//crossover(macd,signal)⋯    aperturashort:=ta.change(macd)<0//crossunder(macd,signal)-rsiFilter = input(false,title="Use RSI filter?",group="RSI")+rsiFilter = input.bool(false,title="Use RSI filter?",group="RSI")-rsiTP = input(true,title="Use RSI Take Profit?",group="RSI")+rsiTP = input.bool(true,title="Use RSI Take Profit?",group="RSI")-len=input(22,title="RSI period",group="RSI")+len=input.int(22,title="RSI period",group="RSI")-srcr=input(close,title="RSI source",group="RSI")+srcr=input.source(close,title="RSI source",group="RSI")rsi=ta.rsi(srcr,len)-ovb=input(90,title="Overbought height",group="RSI") +ovb=input.int(90,title="Overbought height",group="RSI") -ovs=input(45,title="Oversold height",group="RSI")+ovs=input.int(45,title="Oversold height",group="RSI")okLong=rsi<ovb and ta.change(macd)>0 and ta.change(macd)[1]<=0⋯    -usiLong=input(true,title="Use long?")+usiLong=input.bool(true,title="Use long?")-usiShort=input(true,title="Use short?")+usiShort=input.bool(true,title="Use short?")chiusuraShort=rsi<ovs or (aperturaLong)⋯if inDateRange and goodBuy-    strategy.entry("Good Buy", strategy.long, base_order_size, when = strategy.opentrades <= 0, alert_message=enter_msg)+    if strategy.opentrades <= 0+        strategy.entry("Good Buy", strategy.long, base_order_size, alert_message=enter_msg)if inDateRange and safety-    strategy.order("Good Buy", strategy.long, actual_safety_size, when = strategy.opentrades > 0, comment = "safety order", alert_message=enter_msg)+    if strategy.opentrades > 0+        strategy.order("Good Buy", strategy.long, actual_safety_size, comment = "safety order", alert_message=enter_msg)// Sell⋯

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Simple botsimplestring · options ["simple", "composite"]line 63 line 67
3Commas Bot IDstringenter_msg exit_msg close_all line 62
Bot Email Tokenstringenter_msg exit_msg close_all line 62
Base order size10int · min 10 · step 1actual_safety_size entry Good Buy
Safety order size400int · min 15 · step 1actual_safety_size
Safety Order Vol Scale (%)1.83float · min 0.00 · step 0.01actual_safety_size
Safety Order Step Scale (%)1.55float · min 0.00 · step 0.1safety
Max Number of Safety Orders2int · min 0 · step 1safety
Initial SO Deviation (%)1.54float · min 0 · step 0.01initial_dev_val
Long Stop Loss (%)15int · min 0 · step 1stoploss_value
Long Take Profit (%)1.4float · min 0 · step 1takeprofit_value
Short MA Window21intshort_sma stdDev
Long MA Window100intlong_sma
Upper Band Offset2.2float · step 0.5upperBand
Lower Band Offset2.40float · step 0.5lowerBand
Entrry at Cross Over/Under Lowerunderstring · options ["over", "under"]goodBuy
Start Date1int · min 1 · max 31inDateRange
Start Month1int · min 1 · max 12inDateRange
Start Year2016int · min 1800 · max 2100inDateRange
End Date31int · min 1 · max 31inDateRange
End Month12int · min 1 · max 12inDateRange
End Year2022int · min 1800 · max 2100inDateRange
Use long?trueboolunused
Use short?trueboolclose_all line 166
MACD
Fast Length23int (written input.integer)fast_ma
Slow Length16int (written input.integer)slow_ma
Sourceopensourcefast_ma slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Simple MA FAST (Oscillator)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]fast_ma
Simple MA SLOW (Oscillator)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]slow_ma
Simple MA(Signal Line)EMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]signal
Stress
Use stress on recent barstrueboolline 96
Stress on recent bars0.41float · min 0.01 · max 0.99 · step 0.01macd
Level of stress6intmacd
Moving Average
Use moving average (MACD)?trueboolline 101
Length36intsignal hist aperturaLong aperturashort okLong okShort line 98
Type MATHMAstring · options ["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"]signal hist aperturaLong aperturashort okLong okShort line 98
Linear Regression
Use linear regression (MACD)?trueboolline 104
Length10intsignal hist aperturaLong aperturashort okLong okShort line 98
Offset1intsignal hist aperturaLong aperturashort okLong okShort line 98
Condition entry/exit
Use cross macd and signalfalseboolline 113
Use min/max macdtrueboolline 117
RSI
Use RSI filter?falseboolline 130
Use RSI Take Profit?trueboolline 138 line 141
RSI period22intrsi
RSI sourceclosesourcersi
Overbought height90intaperturaLong okLong chiusuraLong
Oversold height45intaperturashort okShort chiusuraShort

What it calculates

  • SMA (sma, ta.sma in v5)close, Short MA Window (21)short_sma · line 35
  • SMA (sma, ta.sma in v5)close, Long MA Window (100)long_sma · line 36
  • Stdev (stdev, ta.stdev in v5)close, Short MA Window (21)stdDev · line 37
  • Crossover / Crossunder (crossover, ta.crossover in v5)close, lowerBand · chosen by Entrry at Cross Over/Under LowergoodBuy · line 46
  • Crossover (crossover, ta.crossover in v5)high, upperBandgoodSell · line 50
  • RSI (rsi, ta.rsi in v5)RSI source (close), RSI period (22)rsi · line 125

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.

The script has 67 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Good Buy longstrategy.opentrades <= 0On156
order Good Buy longstrategy.opentrades > 0On158
Close inDateRange and goodSellOn161
Close inDateRange and stoplossOn163
Close usiShort and strategy.position_size>=0 and okShort and aperturashortOn167

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
[laoowai]BNB_USDT_3m_3Commas_Bollinger_MACD_RSI_Strategy this page—v4 strategy0.0%00.0%
Bottom catch strategy by footlzsma stdev rsiv4 strategy+3.9%37.1%
Madri by Mdemoiorsi sma stdevv4 strategy+25.0%436.4%
Bollinger Bands and RSI Short Selling (by Coinrule) by Coinrulesma stdev rsiv5 strategy+7.6%34.3%
Shorting when Bollinger Band Above Price with RSI (by Coinrule) by Coinrulesma stdev rsiv5 strategyNo trades on this market
RSI_Boll-TP-SL by BigCoinHuntersma stdev rsiv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 74 msWith a workaround 1,000 bars in 135 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © tedwardd// This strategy is intended to help users of the 3commas.io platform backtest bot performance based on a Bollinger Strategy.// It can also be used to signal a bot to open a deal by providing the Bot ID, email token and trading pair in the strategy settings screen.// As currently written, this strategy uses a basic Bollinger Band strategy, recommening a deal start when the closing price crosses under the lower band.// The thick red line plotted on the chart shows the average entry price of the current deal.strategy("[v1.3laoowai]BNB_USDT_3m_3Commas_Bollinger_Strategy_by_tedwardd", overlay=true, default_qty_type=strategy.cash, default_qty_value=1000, initial_capital=900, currency="USD", commission_value=0.1)// 3Commas Bot settinsgbot_type                = input(title="Simple bot", defval="simple", options=["simple", "composite"])bot_id                  = input(title="3Commas Bot ID", defval="")email_token             = input(title="Bot Email Token", defval="")base_order_size         = input(title="Base order size",minval=10, step=1, defval=10)safety_order_size       = input(title="Safety order size", minval=15, step=1, defval=400)volume_scale            = input(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)safety_step             = input(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)safety_max              = input(title="Max Number of Safety Orders", minval=0, step=1, defval=2)initial_deviation_input = input(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=1.54) * 0.01stoploss_input          = input(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01takeprofit_input        = input(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01// USER INPUTSsma_short_val           = input(title="Short MA Window", defval=21)sma_long_val            = input(title="Long MA Window", defval=100)ubOffset                = input(title="Upper Band Offset", defval=2.2, step=0.5)lbOffset                = input(title="Lower Band Offset", defval=2.40, step=0.5)cross                   = input(title="Entrry at Cross Over/Under Lower", defval="under", options=["over", "under"])// Backtesting Date RangesstartDate  = input(title="Start Date", defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)startYear  = input(title="Start Year", defval=2016, minval=1800, maxval=2100)endDate    = input(title="End Date", defval=31, minval=1, maxval=31)endMonth   = input(title="End Month", defval=12, minval=1, maxval=12)endYear    = input(title="End Year", defval=2022, minval=1800, maxval=2100)// VARSshort_sma        = sma(close, sma_short_val)long_sma         = sma(close, sma_long_val)stdDev           = stdev(close, sma_short_val)upperBand        = short_sma + (stdDev * ubOffset)lowerBand        = short_sma - (stdDev * lbOffset)stoploss_value   = strategy.position_avg_price * (1 - stoploss_input)takeprofit_value = strategy.position_avg_price * (1 + takeprofit_input)initial_dev_val  = strategy.position_avg_price * (1 - initial_deviation_input)inDateRange      = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))initial_deviation = close < initial_dev_val// Market ConditionsgoodBuy    = cross=="over"?crossover(close, lowerBand):crossunder(close, lowerBand) // Buy when close crossing lower bandsafety     = initial_deviation and (1-(close/strategy.position_avg_price))/.01 > strategy.opentrades-1 * safety_step and strategy.opentrades <= safety_max // SO when price deviates below SO threshold %stoploss   = close <= stoploss_value // Stoploss condition - true if closing price for current bar drops below stoploss %takeprofit = close >= takeprofit_value // Take profit condition - true if closing price for current bar is >= take profit percentagegoodSell = crossover(high, upperBand)// goodSell is currently unused for any practical purpose. If you wish to try it, switch these two values. // Doing so will make sell suggestions at high crossover upper bollinger but it does not trigger the bot to sell as written but may affect backtest results// Plot some linesplot(short_sma, color=color.green)plot(upperBand)plot(lowerBand, color=color.yellow)plot(strategy.position_avg_price, color=color.red, linewidth=3)// Webhook message. Defaults to string. To signal 3c bot, fill in bot_id and email_token in user settingsvar enter_msg = "Enter Position"var exit_msg  = "Exit Position"var close_all = "Exit Position"if bot_id != "" and email_token != ""    if bot_type == "composite"        enter_msg := '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "' + email_token + '", "delay_seconds": 0, "pair": "' + syminfo.currency + "_" + syminfo.basecurrency + '"}'    else        enter_msg := '{"message_type": "bot", "bot_id": ' + bot_id + ',  "email_token": "' + email_token + '", "delay_seconds": 0}'    if bot_type == "composite"        exit_msg := '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "' + email_token + '", "delay_seconds": 0, "pair": "' + syminfo.currency + "_" + syminfo.basecurrency + '", "action": "close_at_market_price"}'    else        exit_msg := '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "' + email_token + '", "delay_seconds": 0, "action": "close_at_market_price"}'    close_all := '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "' + email_token + '", "delay_seconds": 0, "action": "close_at_market_price_all"}'actual_safety_size = float(safety_order_size) // Set safety order size to starting safetyif strategy.opentrades > 1 // If we have more than two open trades we need to start scaling the safety size by the volume_scale    actual_safety_size := (strategy.position_size - base_order_size) * volume_scale // Remove base order from total position size and scale it for next safety order// Momentum Strategy (BTC/USDT; 1h) - MACD (with source code) by Drun30//@version=4// Getting inputsfast_length = input(title="Fast Length", type=input.integer, defval=23,group="MACD")slow_length = input(title="Slow Length", type=input.integer, defval=16,group="MACD")src = input(title="Source", type=input.source, defval=open,group="MACD")signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9,group="MACD")sma_source1 = input(title="Simple MA FAST (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")sma_source2 = input(title="Simple MA SLOW (Oscillator)", defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")sma_signal = input(title="Simple MA(Signal Line)",defval="EMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="MACD")// Calculatingma(source,length,type)=>    type=="FEMA"?4*ema(source,length)-ema(ema(ema(ema(source,length),length),length),length):type=="FSMA"?4*sma(source,length)-sma(sma(sma(sma(source,length),length),length),length):type=="FWMA"?4*wma(source,length)-wma(wma(wma(wma(source,length),length),length),length):type=="FRMA"?4*rma(source,length)-rma(rma(rma(rma(source,length),length),length),length):type=="TEMA"?3*ema(source,length)-ema(ema(ema(source,length),length),length):type=="TSMA"?3*sma(source,length)-sma(sma(sma(source,length),length),length):type=="TWMA"?3*wma(source,length)-wma(wma(wma(source,length),length),length):type=="TRMA"?3*rma(source,length)-rma(rma(rma(source,length),length),length):type=="EMA"?ema(source,length):type=="SMA"?sma(source,length):type=="WMA"?wma(source,length):type=="RMA"?rma(source,length):type=="DEMA"?2*ema(source,length)-ema(ema(source,length),length):type=="DSMA"?2*sma(source,length)-sma(sma(source,length),length):type=="DWMA"?2*wma(source,length)-wma(wma(source,length),length):type=="DRMA"?2*rma(source,length)-rma(rma(source,length),length):type=="HMA"?hma(source,length):type=="DHMA"?2*hma(source,length)-hma(hma(source,length),length):type=="THMA"?3*hma(source,length)-hma(hma(hma(source,length),length),length):type=="FHMA"?4*hma(source,length)-hma(hma(hma(hma(source,length),length),length),length):ema(source,length)fast_ma = ma(src,fast_length,sma_source1)  slow_ma = ma(src,slow_length,sma_source2)macd = fast_ma - slow_ma //Differenza tra la media mobile veloce e quella lenta signal = ma(macd,signal_length,sma_signal) //usa o la SMA oppure la EMA sulla differenza tra la media mobile veloce e lentahist = macd - signal //Differenza tra la differenza precedente e la media mobile della differenzause_stress=input(true,title="Use stress on recent bars",group="Stress")recent_stress=input(0.41,title="Stress on recent bars",group="Stress",step=0.01,minval=0.01,maxval=0.99)level=input(6,title="Level of stress",group="Stress")if use_stress     macd:=macd*(1/(1-recent_stress))    if not na(macd[1])        macd:=pow((macd*(recent_stress)),level)+(1-recent_stress*macd[1])use_ma= input(true,title="Use moving average (MACD)?",group="Moving Average")if use_ma    macd:=ma(macd,input(36,title="Length",group="Moving Average"),input(title="Type MA",defval="THMA", options=["HMA","DHMA","THMA","FHMA","WMA","DWMA","TWMA","FWMA","SMA","DSMA","TSMA","FSMA","EMA","DEMA","TEMA","FEMA","RMA","DRMA","TRMA","FRMA"],group="Moving Average"))use_linreg= input(true,title="Use linear regression (MACD)?",group="Linear Regression")if use_linreg    macd:=linreg(macd,input(10,title="Length",group="Linear Regression"),input(1,title="Offset",group="Linear Regression"))//macd == linea blu (differenza tra media mobile veloce e media mobile lenta)//signal == linea arancione (media mobile dell'macd)//hist == istogramma (differenza tra macd e media mobile)on_cross = input(false,title="Use cross macd and signal",group="Condition entry/exit")on_minmax = input(true,title="Use min/max macd",group="Condition entry/exit")aperturaLong = change(macd)>0//crossover(macd,signal)aperturashort=not (change(macd)>0)//crossunder(macd,signal)if on_cross    on_minmax:=false    aperturaLong := crossover(macd,signal)    aperturashort := crossunder(macd,signal)if on_minmax    on_cross:=false    aperturaLong := change(macd)>0//crossover(macd,signal)    aperturashort:=change(macd)<0//crossunder(macd,signal)rsiFilter = input(false,title="Use RSI filter?",group="RSI")rsiTP = input(true,title="Use RSI Take Profit?",group="RSI")len=input(22,title="RSI period",group="RSI")srcr=input(close,title="RSI source",group="RSI")rsi=rsi(srcr,len)ovb=input(90,title="Overbought height",group="RSI") ovs=input(45,title="Oversold height",group="RSI")okLong=rsi<ovb and change(macd)>0 and change(macd)[1]<=0okShort=rsi>ovs and change(macd)<0 and change(macd)[1]>=0if not rsiFilter    okLong:=true    okShort:=true    usiLong=input(true,title="Use long?")usiShort=input(true,title="Use short?")chiusuraShort=rsi<ovs or (aperturaLong)chiusuraLong=rsi>ovb or (aperturashort)if rsiTP    aperturaLong := change(macd)>0 and change(macd)[1]<=0 and rsi<ovb//crossover(macd,signal)    aperturashort:=change(macd)<0 and change(macd)[1]>=0 and rsi>ovs//crossunder(macd,signal)if not rsiTP    chiusuraShort:=okLong and aperturaLong    chiusuraLong:=okShort and aperturashort    //if chiusuraShort //    strategy.close("SHORTISSIMO")//if usiLong and strategy.position_size<=0 and okLong and aperturaLong//    strategy.entry("LONGHISSIMO",true)//if chiusuraLong //    strategy.close("LONGHISSIMO")//if usiShort and strategy.position_size>=0 and okShort and aperturashort//    strategy.entry("SHORTISSIMO",false)// Strategy Actions//Buyif inDateRange and goodBuy    strategy.entry("Good Buy", strategy.long, base_order_size, when = strategy.opentrades <= 0, alert_message=enter_msg)if inDateRange and safety    strategy.order("Good Buy", strategy.long, actual_safety_size, when = strategy.opentrades > 0, comment = "safety order", alert_message=enter_msg)// Sellif inDateRange and goodSell    strategy.close_all(comment="Good sell point", alert_message=exit_msg)if inDateRange and stoploss    strategy.close_all(comment="Stoploss", alert_message=exit_msg)//if inDateRange and takeprofit//    strategy.close_all(comment="TP Target", alert_message=exit_msg)if usiShort and strategy.position_size>=0 and okShort and aperturashort    strategy.close_all(comment="SHORTISSIMO", alert_message=exit_msg)//if chiusuraShort//    strategy.close_all(comment="SHORTISSIMO1")