PERO Real — Strategy by Happerson9

By version

Performance Metrics

Description

//version=6//// LE VAN DO - Modified 9.0-X// Добавлен RSI-фильтр, исправлены настройки//VERSION = '9.0-X'strategy( 'LE VAN DO - Modified ' + VERSION, shorttitle = 'LVD-Mod ' + VERSION, overlay = true, explicit_plot_zorder = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, calc_on_every_tick = false, process_orders_on_close = true, max_bars_back = 500, initial_capital = 5000, commission_type = strategy.commission.percent, commission_value = 0.02, max_lines_count = 500)// ================================================================// === ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ ===// ================================================================truncate(number, decimals) => factor = math.pow(10, decimals) int(number * factor) / factor// ================================================================// === ГЛАВНЫЕ НАСТРОЙКИ ===// ================================================================TPSType = input.string('Trailing', 'Система выхода', options=['ATR', 'Trailing'], group='=== ОСНОВНЫЕ НАСТРОЙКИ ===')scolor = input.bool(true, 'Цветные бары по тренду?', group='=== ОСНОВНЫЕ НАСТРОЙКИ ===')almaRibbon = input.bool(false, 'Показать ленту?', group='=== ОСНОВНЫЕ НАСТРОЙКИ ===')// ================================================================// === НАСТРОЙКИ RSI (ДОБАВЛЕНО) ===// ================================================================useRSI = input.bool(true, 'Использовать RSI фильтр', group='=== НАСТРОЙКИ RSI ===')rsiPeriod = input.int(7, 'Период RSI', minval=1, group='=== НАСТРОЙКИ RSI ===')rsiUpper = input.int(45, 'Верхний лимит RSI (для short)', minval=0, maxval=100, group='=== НАСТРОЙКИ RSI ===')rsiLower = input.int(10, 'Нижний лимит RSI (для long)', minval=0, maxval=100, group='=== НАСТРОЙКИ RSI ===')// ================================================================// === РИСК-МЕНЕДЖМЕНТ ===// ================================================================fixPercentTP1 = input.float(50, 'Фиксация % на ТП1', minval=0, maxval=100, step=5, group='=== РИСК-МЕНЕДЖМЕНТ ===')fixPercentTP2 = input.float(30, 'Фиксация % на ТП2', minval=0, maxval=100, step=5, group='=== РИСК-МЕНЕДЖМЕНТ ===')fixPercentTP3 = input.float(20, 'Фиксация % на ТП3', minval=0, maxval=100, step=5, group='=== РИСК-МЕНЕДЖМЕНТ ===')stopFactor = input.float(2.5, 'Множитель стоп-лосса (ATR)', minval=0.5, maxval=5.0, step=0.1, group='=== РИСК-МЕНЕДЖМЕНТ ===')// ================================================================// === ТАЙМФРЕЙМ ===// ================================================================f_tfInMinutes() => _tfInMinutes = timeframe.period == '1' ? '3' : timeframe.period == '3' ? '5' : timeframe.period == '5' ? '15' : timeframe.period == '15' ? '30' : timeframe.period == '30' ? '60' : timeframe.period == '60' ? '240' : 'D' _tfInMinutesmy_time1 = f_tfInMinutes()tfmult = 18f_resInMinutes() => _resInMinutes = timeframe.multiplier * ( timeframe.isseconds ? 1.0 / 60.0 : timeframe.isminutes ? 1.0 : timeframe.isdaily ? 1440.0 : timeframe.isweekly ? 10080.0 : timeframe.ismonthly ? 43800.0 : na) _resInMinutesres_mins = f_resInMinutes()my_time = na(res_mins) ? timeframe.period : str.tostring(int(res_mins * tfmult))// ================================================================// === ФИЛЬТР RSI ===// ================================================================tf = my_timer = ticker.heikinashi(syminfo.tickerid)openSeriesAlt = request.security(r, tf, open, lookahead=barmerge.lookahead_on)closeSeriesAlt = request.security(r, tf, close, lookahead=barmerge.lookahead_on)// RSI на тех же Heikin-Ashi свечахrsiValue = ta.rsi(closeSeriesAlt, rsiPeriod)rsiFilterLong = not useRSI or (useRSI and rsiValue rsiUpper)// ================================================================// === СИГНАЛЫ OPEN/CLOSE С УЧЁТОМ RSI ===// ================================================================BUYOC = ta.crossover(closeSeriesAlt, openSeriesAlt) and rsiFilterLongSELLOC = ta.crossunder(closeSeriesAlt, openSeriesAlt) and rsiFilterShort// ================================================================// === ВЫБОР СИГНАЛА ===// ================================================================sel_color = closeSeriesAlt openSeriesAltsel_entry = SELLOCbuy_entry = BUYOC// ================================================================// === ВИЗУАЛИЗАЦИЯ ===// ================================================================trendColour = buy_color ? color.green : color.redbcolour = buy_color ? #66bb6a : #f7525fbarcolor(scolor ? bcolour : na, title='Цвет баров')p11 = plot(almaRibbon ? closeSeriesAlt : na, style=plot.style_circles, linewidth=1, color=color.new(trendColour, 80), title="Серия_1")p22 = plot(almaRibbon ? openSeriesAlt : na, style=plot.style_circles, linewidth=1, color=color.new(trendColour, 80), title="Серия_2")fill(p11, p22, color=color.new(trendColour, 50), title="Заливка")// ================================================================// === ТРИГГЕРЫ ===// ================================================================lxTrigger = falsesxTrigger = falseleTrigger = buy_entryseTrigger = sel_entrybuy = leTriggersell = seTrigger// ================================================================// === СТРАТЕГИЯ - ORIGINAL (CROSS ENTRY) ===// ================================================================if buy and TPSType == "Trailing" strategy.close("Short", alert_message="Short Exit") strategy.entry("Long", strategy.long, alert_message="Long Entry")if sell and TPSType == "Trailing" strategy.close("Long", alert_message="Long Exit") strategy.entry("Short", strategy.short, alert_message="Short Entry")// ================================================================// === ATR TP/SL СИСТЕМА ===// ================================================================atrLength = 20profitFactor = 2.5tpatrValue = ta.atr(atrLength)takeProfit1_buy = 1 * profitFactor * tpatrValuetakeProfit2_buy = 2 * profitFactor * tpatrValuetakeProfit3_buy = 3 * profitFactor * tpatrValuestopLoss_buy = close - (stopFactor * tpatrValue)takeProfit1_sell = 1 * profitFactor * tpatrValuetakeProfit2_sell = 2 * profitFactor * tpatrValuetakeProfit3_sell = 3 * profitFactor * tpatrValuestopLoss_sell = close + (stopFactor * tpatrValue)// ================================================================// === ФУНКЦИИ TP/SL ===// ================================================================f_tp(_condition, _conditionValue, _leTrigger, _seTrigger, _src, _lxLvlTP, _sxLvlTP) => var float _tpLine = 0.0 _topLvl = _src + _lxLvlTP _botLvl = _src - _lxLvlTP _tpLine := _condition[1] != _conditionValue and _leTrigger ? _topLvl : _condition[1] != -_conditionValue and _seTrigger ? _botLvl : nz(_tpLine[1]) [_tpLine]f_cross(_scr1, _scr2, _over) => _over ? (_scr1 > _scr2 and _scr1[1] _scr2[1])// ================================================================// === СОСТОЯНИЕ ПОЗИЦИИ ДЛЯ TP/SL ===// ================================================================var float condition = 0.0var float slLine = 0.0var float entryLine = 0.0entryLine := leTrigger and condition[1] = 0.0 ? close : nz(entryLine[1])i_src = closei_lxLvlSL = leTrigger ? stopLoss_buy : seTrigger ? stopLoss_sell : naslTopLvl = i_src + i_lxLvlSLslBotLvl = i_src - i_lxLvlSLslLine := condition[1] = 0.0 and seTrigger ? slTopLvl : nz(slLine[1])// ================================================================// === УРОВНИ TP ===// ================================================================i_lxLvlTP1 = leTrigger ? takeProfit1_buy : seTrigger ? takeProfit1_sell : nai_lxLvlTP2 = leTrigger ? takeProfit2_buy : seTrigger ? takeProfit2_sell : nai_lxLvlTP3 = leTrigger ? takeProfit3_buy : seTrigger ? takeProfit3_sell : nai_lxQtyTP1 = fixPercentTP1i_lxQtyTP2 = fixPercentTP2i_lxQtyTP3 = fixPercentTP3i_sxLvlTP1 = i_lxLvlTP1i_sxQtyTP1 = i_lxQtyTP1i_sxLvlTP2 = i_lxLvlTP2i_sxQtyTP2 = i_lxQtyTP2i_sxLvlTP3 = i_lxLvlTP3i_sxQtyTP3 = i_lxQtyTP3i_sxLvlSL = i_lxLvlSL[tp3Line] = f_tp(condition, 1.2, leTrigger, seTrigger, i_src, i_lxLvlTP3, i_sxLvlTP3)[tp2Line] = f_tp(condition, 1.1, leTrigger, seTrigger, i_src, i_lxLvlTP2, i_sxLvlTP2)[tp1Line] = f_tp(condition, 1.0, leTrigger, seTrigger, i_src, i_lxLvlTP1, i_sxLvlTP1)tp3Long = f_cross(high, tp3Line, true)tp3Short = f_cross(low, tp3Line, false)tp2Long = f_cross(high, tp2Line, true)tp2Short = f_cross(low, tp2Line, false)tp1Long = f_cross(high, tp1Line, true)tp1Short = f_cross(low, tp1Line, false)slLong = f_cross(low, slLine, false)slShort = f_cross(high, slLine, true)// ================================================================// === МАШИНА СОСТОЯНИЙ ===// ================================================================switch leTrigger and condition[1] condition := 1.0 seTrigger and condition[1] >= 0.0 => condition := -1.0 tp3Long and condition[1] == 1.2 => condition := 1.3 tp3Short and condition[1] == -1.2 => condition := -1.3 tp2Long and condition[1] == 1.1 => condition := 1.2 tp2Short and condition[1] == -1.1 => condition := -1.2 tp1Long and condition[1] == 1.0 => condition := 1.1 tp1Short and condition[1] == -1.0 => condition := -1.1 slLong and condition[1] >= 1.0 => condition := 0.0 slShort and condition[1] condition := 0.0 lxTrigger and condition[1] >= 1.0 => condition := 0.0 sxTrigger and condition[1] condition := 0.0longE = leTrigger and condition[1] = 0.0 and condition == -1.0longX = lxTrigger and condition[1] >= 1.0 and condition == 0.0shortX = sxTrigger and condition[1] = 1.0 and condition == 0.0shortSL = slShort and condition[1] 0 and condition == 1.0 and TPSType == "ATR" strategy.exit( id = 'LXTP1', from_entry = 'Long', qty_percent = i_lxQtyTP1, limit = tp1Line, stop = slLine, comment_profit = 'LXTP1', comment_loss = 'SL', alert_profit = i_lxMsgTP1, alert_loss = i_lxMsgSL )if strategy.position_size > 0 and condition == 1.1 and TPSType == "ATR" strategy.exit( id = 'LXTP2', from_entry = 'Long', qty_percent = i_lxQtyTP2, limit = tp2Line, stop = slLine, comment_profit = 'LXTP2', comment_loss = 'SL', alert_profit = i_lxMsgTP2, alert_loss = i_lxMsgSL )if strategy.position_size > 0 and condition == 1.2 and TPSType == "ATR" strategy.exit( id = 'LXTP3', from_entry = 'Long', qty_percent = i_lxQtyTP3, limit = tp3Line, stop = slLine, comment_profit = 'LXTP3', comment_loss = 'SL', alert_profit = i_lxMsgTP3, alert_loss = i_lxMsgSL )if longX strategy.close('Long', alert_message=i_lxMsg, comment='LX')// Short orders with ATR TP/SLif strategy.position_size = 1.0 or condition _cellText = _title + "\\n" + _value table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor)var bgcolor = color.new(color.black, 0)if drawTester if barstate.islastconfirmedhistory dollarReturn = strategy.netprofit winRate = strategy.closedtrades > 0 ? (strategy.wintrades / strategy.closedtrades) * 100 : 0.0 avgWin = strategy.wintrades > 0 ? (strategy.grossprofit / strategy.wintrades) : 0.0 avgLoss = strategy.losstrades > 0 ? (strategy.grossloss / strategy.losstrades) : 0.0 profitFactor = strategy.grossloss > 0 ? (strategy.grossprofit / strategy.grossloss) : (strategy.grossprofit > 0 ? 999.0 : 0.0) maxDD = strategy.equity > 0 ? (strategy.max_drawdown / strategy.equity) * 100 : 0.0 f_fillCell(testTable, 0, 0, "Всего сделок:", str.tostring(strategy.closedtrades), bgcolor, color.white) f_fillCell(testTable, 0, 1, "Win Rate:", str.tostring(truncate(winRate, 2)) + "%", bgcolor, color.white) f_fillCell(testTable, 1, 0, "Начало:", "$" + str.tostring(strategy.initial_capital), bgcolor, color.white) f_fillCell(testTable, 1, 1, "Конец:", "$" + str.tostring(truncate(strategy.initial_capital + strategy.netprofit,2)), bgcolor, color.white) f_fillCell(testTable, 2, 0, "Средний выигрыш:", "$"+ str.tostring(truncate(avgWin, 2)), bgcolor, color.white) f_fillCell(testTable, 2, 1, "Средний проигрыш:", "$"+ str.tostring(truncate(avgLoss, 2)), bgcolor, color.white) f_fillCell(testTable, 3, 0, "Profit Factor:", str.tostring(truncate(profitFactor, 2)), strategy.grossprofit > strategy.grossloss ? color.green : color.red, color.white) f_fillCell(testTable, 3, 1, "Max Runup:", str.tostring(truncate(strategy.max_runup, 2)), bgcolor, color.white) f_fillCell(testTable, 4, 0, "Прибыль:", (dollarReturn > 0 ? "+" : "") + str.tostring(truncate((dollarReturn / strategy.initial_capital)*100,2)) + "%", dollarReturn > 0 ? color.green : color.red, color.white) f_fillCell(testTable, 4, 1, "Max DD:", str.tostring(truncate(maxDD, 2)) + "%", color.red, color.white)// ================================================================// === EMA И ЦВЕТ БАРОВ ===// ================================================================hide = timeframe.isintradayemaPeriod = 48emaPeriod2 = 2emaPeriod3 = 21showcloud = input.bool(false, "Показать EMA?", group='=== EMA И ATR ===')useHTF = input.bool(true, "Использовать старший ТФ?")matimeframe = useHTF ? my_time1 : timeframe.periodema = request.security(syminfo.tickerid, matimeframe, ta.ema(close, emaPeriod))ema2 = request.security(syminfo.tickerid, matimeframe, ta.ema(close, emaPeriod2))ema3 = request.security(syminfo.tickerid, matimeframe, ta.ema(close, emaPeriod3))c_barCol = close > open ? color.rgb(120, 9, 139) : color.rgb(69, 155, 225)barcolor(c_barCol)

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView