Ошибка возникла из-за особенностей markdown-разметки в сообщениях Telegram. Заместо кавычек " следует использовать специальные символы, например, " - это именно то, что исправлено в вашем коде. Советую использовать IDE или текстовый редактор для написания кода, а затем копировать его в Telegram в кодовом форматировании (кнопка "code" или три символа ``` перед и после кода). При этом, подобных проблем при переносе кода быть не должно.
TradingView не может выполнить компиляцию, в чем проблема?
session=tradingsession.regular
nullsession = tradingsession.regular
tradingsession = input.session(title="Trading Session", defval="24x7")
sessioncolor = tradingsession=="24x7" ? na : (tradingsession=="0900-1630" ? #33FF33 : #FF3333)
bgcolor(sessioncolor, transp=50)
strategy("Combined signals with Take Profit and Stop Loss",overlay=true)
// Inputs for MA+EMA signals
fast_ma_length = input(title="Fast MA length", type=input.integer, defval=10)
slow_ma_length = input(title="Slow MA length", type=input.integer, defval=30)
ema_length = input(title="EMA length", type=input.integer, defval=20)
// Inputs for MACD+RSI signals
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
signal_length = input(title="Signal Length", type=input.integer, defval=9)
rsi_length = input(title="RSI Length", type=input.integer, defval=14)
upper_bound = input(title="Overbought level", type=input.float, defval=70.0)
lower_bound = input(title="Oversold level", type=input.float, defval=30.0)
// Take Profit and Stop Loss inputs
tp1_perc = input(title="TP 1 %", type=input.float, defval=1.0)
tp2_perc = input(title="TP 2 %", type=input.float, defval=2.0)
tp3_perc = input(title="TP 3 %", type=input.float, defval=3.0)
sl_perc = input(title="SL %", type=input.float, defval=1.0)
// Inputs for CCI+OBV+ROC+CMF signals
cci_length = input(title="CCI Length", type=input.integer, defval=14)
cci_upper_bound = input(title="Overbought CCI level", type=input.float, defval=100.0)
cci_lower_bound = input(title="Oversold CCI level", type=input.float, defval=-100.0)
obv_length = input(title="OBV Length", type=input.integer, defval=20)
roc_length = input(title="ROC Length", type=input.integer, defval=14)
min_chaikin_money_flow = input(title="Min CMF value", type=input.float, defval=-0.5)
// Inputs for RSI+StochRSI+CCI signals
src = input(title="Source", type=input.source, defval=close)
rsi_overbought = input(title="Overbought RSI level", type=input.float, defval=70.0)
rsi_oversold = input(title="Oversold RSI level", type=input.float, defval=30.0)
stochrsi_length = input(title="Stoch RSI Length", type=input.integer, defval=14)
stochrsi_overbought = input(title="Overbought Stoch RSI level", type=input.float, defval=80.0)
stochrsi_oversold = input(title="Oversold Stoch RSI level", type=input.float, defval=20.0)
// Calculating MA and EMA signals
fast_ma = sma(close, fast_ma_length)
slow_ma = sma(close, slow_ma_length)
ema = ema(close, ema_length)
// Calculating MACD and RSI signals
[macdLine, signalLine, _] = macd(close, fast_length, slow_length, signal_length)
rsi = rsi(close, rsi_length)
// Determining signals for MA+EMA
long_entry_ma = crossover(fast_ma, slow_ma) and crossover(close, ema)
short_entry_ma = crossunder(fast_ma, slow_ma) and crossunder(close, ema)
exit_long_ma = crossunder(close, ema)
exit_short_ma = crossover(close, ema)
// Determining signals for MACD+RSI
long_entry_macd = crossover(macdLine, signalLine) and rsi <= lower_bound
short_entry_macd = crossunder(macdLine, signalLine) and rsi >= upper_bound
exit_long_macd = crossunder(macdLine, signalLine)
exit_short_macd = crossover(macdLine, signalLine)
// Combining the signals
long_entry = long_entry_ma or long_entry_macd
short_entry = short_entry_ma or short_entry_macd
exit_long = exit_long_ma or exit_long_macd
exit_short = exit_short_ma or exit_short_macd
// Calculating CCI+OBV+ROC+CMF signals
cci = cci(high, low, close, cci_length)
obv = obv(close, volume)
roc = roc(close, roc_length)
chaikin_money_flow = cmf(high, low, close, volume)
// Determining signals
long_entry_cci = cci <= cci_lower_bound and obv > nz(obv[1]) and roc > 0 and chaikin_money_flow >= min_chaikin_money_flow
short_entry_cci = cci >= cci_upper_bound and obv < nz(obv[1]) and roc < 0 and chaikin_money_flow <= -min_chaikin_money_flow
exit_long_cci = cci >= cci_upper_bound or roc < 0 or chaikin_money_flow <= -min_chaikin_money_flow
exit_short_cci = cci <= cci_lower_bound or roc > 0 or chaikin_money_flow >= min_chaikin_money_flow
// Combining the signals
long_entry := long_entry or long_entry_cci
short_entry := short_entry or short_entry_cci
exit_long := exit_long or exit_long_cci
exit_short := exit_short or exit_short_cci
// Calculating RSI+StochRSI+CCI signals
rsi_ = rsi(src, rsi_length)
stoch_rsi = stoch(rsi_, rsi_length, stochrsi_length)
cci_ = cci(high, low, src, cci_length)
// Determining signals
long_entry_rsi = rsi_ <= rsi_oversold and stoch_rsi <= stochrsi_oversold and cci_ <= cci_lower_bound
short_entry_rsi = rsi_ >= rsi_overbought and stoch_rsi >= stochrsi_overbought and cci_ >= cci_upper_bound
// Plotting TP and SL levels
tp1 = close * (tp1_perc/100 + 1)
tp2 = close * (tp2_perc/100 + 1)
tp3 = close * (tp3_perc/100 + 1)
sl = close * (1 - sl_perc/100)
plot(tp1, title="TP 1 Level", color=color.green, style=plot.style_linebr)
plot(tp2, title="TP 2 Level", color=color.green, style=plot.style_linebr)
plot(tp3, title="TP 3 Level", color=color.green, style=plot.style_linebr)
plot(sl, title="SL Level", color=color.red, style=plot.style_linebr)
// Long entry
long_entry_condition = long_entry and close < tp1
if (long_entry_condition)
strategy.entry("Long Entry", strategy.long)
strategy.exit("TP 1 Long", "Long Entry", limit=tp1)
strategy.exit("SL Long", "Long Entry", stop=sl)
// Short entry
short_entry_condition = short_entry and close > tp1
if (short_entry_condition)
strategy.entry("Short Entry", strategy.short)
strategy.exit("TP 1 Short", "Short Entry", limit=tp1)
strategy.exit("SL Short", "Short Entry", stop=sl)
// Exit long
exit_long_condition = exit_long and strategy.position_size > 0;
if (exit_long_condition)
strategy.close("Long Entry", qty=strategy.position_size)