この戦略は,イチモク・キンコ・ヒョー指標と他の複数の技術指標を統合し,さまざまな取引信号を組み合わせ,高い勝利率を追求しながら,誤った信号を効果的にフィルターし,リスクを制御するために複数の信号でエントリを確認しながら,イチモクシステムの利点を利用するために使用されています.
この戦略の主な要素は次のとおりです.
テンカンセン,キジョンセン,センコスパンA,センコスパンB,クモを含むイチモク・キンコ・ヒョー指標の計算.
クモ,キジュン,MACD,RSI,フラクタル,スーパートレンド,パラボリックSAR,ADXを含む複数のフィルタで,トレンドの方向性を確認し,ウィップソーを回避します.
価格ブレイク,チコウ関係,テンカン&キジュン関係を含む複数の取引信号で,合計23のイチモク信号,さらにMACD,RSI,フラクタルなどの信号により,潜在的な取引機会を特定します.
入り口信号を2段階フィルターで 入り口に閉じ込められないように
入力フィルターと同じような出力信号のための2段階フィルター
選択された取引信号とフィルター確認の組み合わせで最終的な取引決定を行う.
設定できる 利益とストップ損失の設定
バックテスト期間設定
この戦略の利点は以下の通りです.
イチモク
2段階のフィルターを通って入る際に罠を避け 効果的なリスク管理
異なる市場条件に適応できる複数の取引可能な信号を提供すること
複数の選択可能なフィルターを提供し 個々のストックに最適化できます
利益とストップロスを取り, 利益とリスクを制御します.
戦略の最適化を促進するバックテスト期間
この戦略のリスクは以下のとおりです.
イチモク信号は遅いので 短期的な機会を見逃すこともあります
過度のフィルタリングは不確実なエントリを引き起こす可能性があります.フィルタパラメータを調整する必要があります.
静的ストップ損失は,複雑な価格アクションにうまく適応しない可能性があります. ダイナミックストップ損失は役立ちます.
リアルマーケットを正確にシミュレートする際の バックテストの限界
戦略を最適化する方法:
短期間取引のためにテンカン期のような イチモクパラメータを調整します
個々の株に最適な配合を見つけるために信号の組み合わせをテストします
フィルタのパラメータを最適化してフィルタ効果と入り口の確実性をバランスさせる.
市場変化に適応するために ダイナミックストップロスを試してください
より正確なシミュレーションのために,より長いバックテスト期間またはチェックデータを使用します.
ポジションのサイズを追加して 資本の活用を図る
自動パラメータ最適化で よりスマートなチューニングを
この戦略は,イチモク
/*backtest start: 2023-10-13 00:00:00 end: 2023-11-12 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ramsay09 //@version=4 strategy(title="The Strategy - Ichimoku Kinko Hyo and more",shorttitle="Strategy ", overlay=true) backtest = input(title= "Backtest (no comment-string)", type= input.bool, defval= false) entry_type = input("Both", title= "Long/Short Entry", options= ["Both", "Long", "Short"]) shared_param = input(false, title= " Shared Filter and Entry Parameters :", type= input.bool) fr_period = input(2, title= "Fractals Period (Filter/Entry)", minval= 1) rsi_period = input(14, title= "RSI Period (Filter/Entry)", minval= 1) mult = input(2, type= input.float, title= "SuperTrend multiplier (Filter/Entry)", minval= 1) len = input(5, type= input.integer, title= "SuperTrend length (Filter/Entry)", minval= 1) start = 0.02//input(0.02, title= "PSAR Start (Filter/Entry)", minval= 0) inc = 0.02//input(0.02, title= "PSAR Increment (Filter/Entry)", minval= 0) max = 0.2//input(.2, title= "PSAR Maximum (Filter/Entry)", minval= 0) adx_period = input(10, title= "ADX Period (Filter/Entry)", minval= 1) adx_tres = input(25, title= "ADX threshold (Filter/Entry)", minval= 1) X_opt = input("Price X Kumo sig", title="Signal", options= ["---", "Inside Bar sig", "Outside Bar sig", "Sandwich Bar sig", "Bar sig", "SMA50 sig", "RSI50 sig", "Fractals sig", "Parabolic SAR sig", "SuperTrend sig", "Price X Kijun sig", "Price X Kumo sig", "Kumo flip sig", "Price filtered Kumo flip sig", "Chikou X Price sig", "Chikou X Kumo sig", "Price X Tenkan sig", "Tenkan X Kumo sig", "Tenkan X Kijun sig", "Kumo filtered Tenkan X Kijun sig", "CB/CS sig", "IB/IS sig", "B1/S1 sig", "B2/S2 sig"]) entry_f_1 = input("---", title="Entry filter 1", options= ["---", "SMA50 filter", "MACD filter", "RSI50 filter", "Fractals filter", "SuperTrend filter", "Parabolic SAR filter", "Cloud filter", "Kijun filter", "ADX filter"]) entry_f_2 = input("---", title="Entry filter 2", options= ["---", "SMA50 filter", "MACD filter", "RSI50 filter", "Fractals filter", "SuperTrend filter", "Parabolic SAR filter", "Cloud filter", "Kijun filter", "ADX filter"]) exit_f_1 = input("---", title="Exit filter 1", options= ["---", "SMA50 filter", "MACD filter", "RSI50 filter", "Fractals filter", "SuperTrend filter", "Parabolic SAR filter", "Cloud filter", "Kijun filter", "ADX filter"]) exit_f_2 = input("---", title="Exit filter 2", options= ["---", "SMA50 filter", "MACD filter", "RSI50 filter", "Fractals filter", "SuperTrend filter", "Parabolic SAR filter", "Cloud filter", "Kijun filter", "ADX filter"]) //-------------------- Ichimoku -------------------- TKlength = 9 //input(9, "Tenkan-sen length", minval= 1) KJlength = 26 //input(26, "Kijun-sen length", minval= 1) CSHSlength = 26 //input(26, "Chikouspan length/horizontal shift", minval= 1) SBlength = 52 //input(52, "SenkouspanB length", minval= 1) SAlength = 26 //input(26, "SenkouspanA length", minval= 1) // calculation TK = avg(lowest(TKlength), highest(TKlength)) KJ = avg(lowest(KJlength), highest(KJlength)) CS = close SB = avg(lowest(SBlength), highest(SBlength)) SA = avg(TK,KJ) kumo_high = max(SA[CSHSlength-1], SB[CSHSlength-1]) kumo_low = min(SA[CSHSlength-1], SB[CSHSlength-1]) //------------------------------------- Filters and entry signals -------------------------------------- //---------------------- Kumo filter ------------------------ kumo_buy = close > kumo_high kumo_sell = close < kumo_low //--------------------- Kijun filter ---------------------- kijun_buy = close > KJ kijun_sell = close < KJ //----------------------- macd filter ----------------------- [macdLine_f, signalLine_f, histLine_f] = macd(close, 12, 26, 9) macd_buy = macdLine_f > signalLine_f macd_sell = macdLine_f < signalLine_f //---------------------- rsi filter and entry signal------------------------ rsi_f_buy = rsi(close, rsi_period) > 50 rsi_f_sell = rsi(close, rsi_period) < 50 //---------------- Bill Williams Fractals (filter and entry signal) ----------------- up_fr = pivothigh(fr_period, fr_period) dn_fr = pivotlow(fr_period, fr_period) fractal_up_v = valuewhen(up_fr, high[fr_period],0) fractal_dn_v = valuewhen(dn_fr, low[fr_period],0) fr_upx = high > fractal_up_v fr_dnx = low < fractal_dn_v //-------------------- SuperTrend filter and entry signal --------------------- [SuperTrend, Dir] = supertrend(mult, len) sup_buy = close > SuperTrend sup_sell = close < SuperTrend //--------------------- Heikin Ashi ----------------------- //heikin_close = security(heikinashi(syminfo.tickerid), timeframe.period, close) //heikin_open = security(heikinashi(syminfo.tickerid), timeframe.period, open) //h_buy = heikin_close[1] > heikin_open[1] //h_sell = heikin_close[1] < heikin_open[1] //----------------- Parabolic SAR Signal (pb/ps) and filter ------------------- psar_buy = high > sar(start, inc, max)[0] psar_sell = low < sar(start, inc, max)[0] //-------------------------- ADX filter --------------------------- [diplus_f, diminus_f, adx_f] = dmi(adx_period, adx_period) //-------------------------- SMA50 filter and entry--------------------------- sma50_buy = close[2] > sma(close, 50) sma50_sell = close[2] < sma(close, 50) //-------------------------- entry filter ------------------------------- //entry buy filter 1 options entry_filter_buy_1 = entry_f_1 == "---" ? true : entry_f_1 == "MACD filter" ? macd_buy : entry_f_1 == "RSI50 filter" ? rsi_f_buy : entry_f_1 == "Fractals filter" ? fr_upx : entry_f_1 == "SuperTrend filter" ? sup_buy : entry_f_1 == "Parabolic SAR filter" ? psar_buy : entry_f_1 == "Cloud filter" ? kumo_buy : entry_f_1 == "Kijun filter" ? kijun_buy : entry_f_1 == "SMA50 filter" ? sma50_buy : entry_f_1 == "ADX filter" ? adx_f > 25 : true //entry sell filter 1 options entry_filter_sell_1 = entry_f_1 == "---" ? true : entry_f_1 == "MACD filter" ? macd_sell : entry_f_1 == "RSI50 filter" ? rsi_f_sell : entry_f_1 == "Fractals filter" ? fr_dnx : entry_f_1 == "SuperTrend filter" ? sup_sell : entry_f_1 == "Parabolic SAR filter" ? psar_sell : entry_f_1 == "Cloud filter" ? kumo_sell : entry_f_1 == "Kijun filter" ? kijun_sell : entry_f_1 == "SMA50 filter" ? sma50_sell : entry_f_1 == "ADX filter" ? adx_f > 25 : true //entry buy filter 2 options entry_filter_buy_2 = entry_f_2 == "---" ? true : entry_f_2 == "MACD filter" ? macd_buy : entry_f_2 == "RSI50 filter" ? rsi_f_buy : entry_f_2 == "Fractals filter" ? fr_upx : entry_f_2 == "SuperTrend filter" ? sup_buy : entry_f_2 == "Parabolic SAR filter" ? psar_buy : entry_f_2 == "Cloud filter" ? kumo_buy : entry_f_2 == "Kijun filter" ? kijun_buy : entry_f_2 == "SMA50 filter" ? sma50_buy : entry_f_2 == "ADX filter" ? adx_f > 25 : true //entry sell filter 2 options entry_filter_sell_2 = entry_f_2 == "---" ? true : entry_f_2 == "MACD filter" ? macd_sell : entry_f_2 == "RSI50 filter" ? rsi_f_sell : entry_f_2 == "Fractals filter" ? fr_dnx : entry_f_2 == "SuperTrend filter" ? sup_sell : entry_f_2 == "Parabolic SAR filter" ? psar_sell : entry_f_2 == "Cloud filter" ? kumo_sell : entry_f_2 == "Kijun filter" ? kijun_sell : entry_f_2 == "SMA50 filter" ? sma50_sell : entry_f_2 == "ADX filter" ? adx_f > 25 : true //------------------------- exit filter ----------------------- //exit buy filter 1 options exit_filter_buy_1 = exit_f_1 == "---" ? false : exit_f_1 == "MACD filter" ? macd_buy : exit_f_1 == "RSI50 filter" ? rsi_f_buy : exit_f_1 == "Fractals filter" ? fr_upx : exit_f_1 == "SuperTrend filter" ? sup_buy : exit_f_1 == "Parabolic SAR filter" ? psar_buy : exit_f_1 == "Cloud filter" ? kumo_buy : exit_f_1 == "Kijun filter" ? kijun_buy : exit_f_1 == "SMA50 filter" ? sma50_buy : exit_f_1 == "ADX filter" ? adx_f > 25 : false //exit sell filter 1 options exit_filter_sell_1 = exit_f_1 == "---" ? false : exit_f_1 == "MACD filter" ? macd_sell : exit_f_1 == "RSI50 filter" ? rsi_f_sell : exit_f_1 == "Fractals filter" ? fr_dnx : exit_f_1 == "SuperTrend filter" ? sup_sell : exit_f_1 == "Parabolic SAR filter" ? psar_sell : exit_f_1 == "Cloud filter" ? kumo_sell : exit_f_1 == "Kijun filter" ? kijun_sell : exit_f_1 == "SMA50 filter" ? sma50_sell : exit_f_1 == "ADX filter" ? adx_f > 25 : false //exit buy filter 2 options exit_filter_buy_2 = exit_f_2 == "---" ? false : exit_f_2 == "MACD filter" ? macd_buy : exit_f_2 == "RSI50 filter" ? rsi_f_buy : exit_f_2 == "Fractals filter" ? fr_upx : exit_f_2 == "SuperTrend filter" ? sup_buy : exit_f_2 == "Parabolic SAR filter" ? psar_buy : exit_f_2 == "Cloud filter" ? kumo_buy : exit_f_2 == "Kijun filter" ? kijun_buy : exit_f_2 == "SMA50 filter" ? sma50_buy : exit_f_2 == "ADX filter" ? adx_f > 25 : false //exit sell filter 2 options exit_filter_sell_2 = exit_f_2 == "---" ? false : exit_f_2 == "MACD filter" ? macd_sell : exit_f_2 == "RSI50 filter" ? rsi_f_sell : exit_f_2 == "Fractals filter" ? fr_dnx : exit_f_2 == "SuperTrend filter" ? sup_sell : exit_f_2 == "Parabolic SAR filter" ? psar_sell : exit_f_2 == "Cloud filter" ? kumo_sell : exit_f_2 == "Kijun filter" ? kijun_sell : exit_f_2 == "SMA50 filter" ? sma50_sell : exit_f_2 == "ADX filter" ? adx_f > 25 : false //----------------------- i-o-s signals ------------------------ i_bar_buy = high[1] < high[2] and low[1] > low[2] and close > high[1] i_bar_sell = high[1] < high[2] and low[1] > low[2] and close < low[1] o_bar_buy = high[1] > high[2] and low[1] < low[2] and high > high[1] o_bar_sell = high[1] > high[2] and low[1] < low[2] and low < low[1] s_bar_buy = high[2] < high[3] and low[2] > low[3] and high[1] > high[2] and low[1] < low[2] and high > high[1] s_bar_sell = high[2] < high[3] and low[2] > low[3] and high[1] > high[2] and low[1] < low[2] and low < low[1] //----------------- Ichimoku Signal B1/S1 ----------------- buy_strong_B1 = (TK >= KJ) and close > kumo_high and CS > high[(26-1)] and CS > kumo_high[26-1] and SA > SB sell_strong_S1 = (TK <= KJ) and close < kumo_low and CS < low[(26-1)] and CS < kumo_low[26-1] and SA < SB var buy_sig = true var sell_sig = true B1_a = buy_strong_B1 and buy_sig S1_a = sell_strong_S1 and sell_sig if sell_strong_S1 buy_sig := true, sell_sig := false if buy_strong_B1 sell_sig := true, buy_sig := false //----------------- Ichimoku Signal B2/S2 ----------------- buy_strong_B2 = (TK >= KJ) and close > kumo_high and CS > high[26-1] sell_strong_S2 = (TK <= KJ) and close < kumo_low and CS < low[26-1] var buy_sig_B2 = true var sell_sig_S2 = true B2_a = buy_strong_B2 and buy_sig_B2 S2_a = sell_strong_S2 and sell_sig_S2 if sell_strong_S2 buy_sig_B2 := true, sell_sig_S2 := false if buy_strong_B2 sell_sig_S2 := true, buy_sig_B2 := false //---------------------------- Confluence Signal ---------------------------- long_short_trig = 7 //input(7, type= input.float, title= "Confluence signal trigger Level", step= 0.1) trig_gap_cbcs = input(2, type= input.float, title= "CB/CS signal sesitivity", minval= 0, maxval= 6, step= 1) //Indicators // ma sma1 = sma(close, 50) sma2 = sma(close, 200) ema1 = ema(close, 50) ema2 = ema(close, 200) [macdLine, signalLine, histLine] = macd(close, 12, 26, 9) rsi = rsi(close, 14) [diplus, diminus, adx] = dmi(7, 7) [superTrend, dir] = supertrend(2, 5) //Klinger Oszillator sv = change(hlc3) >= 0 ? volume : -volume kvo = ema(sv, 34) - ema(sv, 55) sig = ema(kvo, 13) //Vortex Indicator VMP = sum( abs( high - low[1]), 14 ) VMM = sum( abs( low - high[1]), 14 ) STR = sum( atr(1), 14 ) VIP = VMP / STR VIM = VMM / STR //Signals var float sma_sig_w = na var float ema_sig_w = na var float p_kj_sig_w = na var float tk_kj_sig_w = na var float B1_S1_sig_w = na var float B2_S2_sig_w = na var float psar_sig_w = na var float frac_sig_w = na var float macd_sig_w = na var float rsi_sig_w = na var float p_tk_sig_w = na var float dmi_sig_w = na var float klin_sig_w = na var float vort_sig_w = na var float sup_sig_w = na if sma1 > sma2 sma_sig_w := 1 else if sma1 < sma2 sma_sig_w := 0 if ema1 > ema2 ema_sig_w := 1 else if ema1 < ema2 ema_sig_w := 0 if close > KJ p_kj_sig_w := 1 else if close < KJ p_kj_sig_w := 0 if TK > KJ tk_kj_sig_w := 1 else if TK < KJ tk_kj_sig_w := 0 if buy_strong_B1 B1_S1_sig_w := 1 else if sell_strong_S1 B1_S1_sig_w := 0 if buy_strong_B2 B2_S2_sig_w := 1 else if sell_strong_S2 B2_S2_sig_w := 0 if high >= sar(start, inc, max)[0] psar_sig_w := 1 else if low <= sar(start, inc, max)[0] psar_sig_w := 0 if high > fractal_up_v frac_sig_w := 1 else if low < fractal_dn_v frac_sig_w := 0 if macdLine > signalLine macd_sig_w := 1 else if macdLine < signalLine macd_sig_w := 0 if rsi > 50 rsi_sig_w := 1 else if rsi < 50 rsi_sig_w := 0 if close[2] > TK p_tk_sig_w := 1 else if close[2] < TK p_tk_sig_w := 0 if diplus > diminus dmi_sig_w := 1 else if diplus < diminus dmi_sig_w := 0 if sig > 0 klin_sig_w := 1 else if sig < 0 klin_sig_w := 0 if VIP > VIM vort_sig_w := 1 else if VIP < VIM vort_sig_w := 0 if close > superTrend sup_sig_w := 1 else if close < superTrend sup_sig_w := 0 bs_conf_sig = sma_sig_w + ema_sig_w + p_kj_sig_w + tk_kj_sig_w + B1_S1_sig_w + B2_S2_sig_w + psar_sig_w + frac_sig_w + macd_sig_w + rsi_sig_w + dmi_sig_w + klin_sig_w + vort_sig_w + sup_sig_w + p_tk_sig_w long_c = bs_conf_sig > long_short_trig + trig_gap_cbcs //with +- signal is less fluctuating short_c = bs_conf_sig < long_short_trig - trig_gap_cbcs //---------------------------- Pure Ichimoku Confluence Signal ---------------------------- pic_l_s_trig = 4 //input(4, type= input.float, title= "Ichimoku confluence signal trigger Level", step= 0.1) trig_gap_ibis = input(0, type= input.float, title= "IB/IS signal sesitivity", minval= 0, maxval= 3, step= 1) //Signals var float tkkh_sig_w = na var float csh_sig_w = na var float cskh_sig_w = na var float pkj_sig_w = na var float ptk_sig_w = na var float tkkj_sig_w = na var float sasb_sig_w = na var float ckh_sig_w = na if TK > kumo_high tkkh_sig_w := 1 else if TK < kumo_low tkkh_sig_w := 0 if CS > high[(26-1)] csh_sig_w := 1 else if CS < low[(26-1)] csh_sig_w := 0 if CS > kumo_high[26-1] cskh_sig_w := 1 else if CS < kumo_low[26-1] cskh_sig_w := 0 if close > TK ptk_sig_w := 1 else if close < TK ptk_sig_w := 0 if close > KJ pkj_sig_w := 1 else if close < KJ pkj_sig_w := 0 if TK > KJ tkkj_sig_w := 1 else if TK < KJ tkkj_sig_w := 0 if SA > SB sasb_sig_w := 1 else if SA < SB sasb_sig_w := 0 if close > kumo_high ckh_sig_w := 1 else if close < kumo_low ckh_sig_w := 0 bs_pic_sig = tkkh_sig_w + csh_sig_w + cskh_sig_w + ptk_sig_w + pkj_sig_w + tkkj_sig_w + sasb_sig_w + ckh_sig_w long_pic = bs_pic_sig > pic_l_s_trig + trig_gap_ibis short_pic = bs_pic_sig < pic_l_s_trig - trig_gap_ibis //--------------------------- Entry Signal Options --------------------------- var buy_sig_opt = true var sell_sig_opt = true // cross conditions for "Strong" bg's var bool sasb_x = true if crossover(SA, SB) and low > kumo_high sasb_x := true if crossunder(SA, SB) and high < kumo_low sasb_x := false var bool tkkj_x = true if crossover(TK, KJ) and TK > kumo_high and KJ > kumo_high tkkj_x := true if crossunder(TK, KJ) and TK < kumo_low and KJ < kumo_low tkkj_x := false // buy signal options opt_sig_buy = X_opt == "---" ? na : X_opt == "Inside Bar sig" ? i_bar_buy : X_opt == "Outside Bar sig" ? o_bar_buy : X_opt == "Sandwich Bar sig" ? s_bar_buy : X_opt == "Bar sig" ? close > high[1] : X_opt == "SMA50 sig" ? close[2] > sma(close, 50) : X_opt == "Fractals sig" ? fr_upx : X_opt == "RSI50 sig" ? rsi_f_buy : X_opt == "Parabolic SAR sig" ? psar_buy : X_opt == "SuperTrend sig" ? sup_buy : X_opt == "Price X Kijun sig" ? close > KJ : X_opt == "Price X Kumo sig" ? close > kumo_high : X_opt == "Kumo flip sig" ? SA > SB : X_opt == "Price filtered Kumo flip sig" ? sasb_x and low > kumo_high : X_opt == "Chikou X price sig" ? CS > high[(26-1)] : X_opt == "Chikou X Kumo sig" ? CS > kumo_high[26-1] : X_opt == "Price X Tenkan sig" ? close > TK : X_opt == "Tenkan X Kumo sig" ? TK > kumo_high : X_opt == "Tenkan X Kijun sig" ? TK > KJ : X_opt == "Kumo filtered Tenkan X Kijun sig" ? tkkj_x and TK > kumo_high and KJ > kumo_high and TK > KJ : X_opt == "CB/CS sig" ? long_c : X_opt == "IB/IS sig" ? long_pic : X_opt == "B1/S1 sig" ? buy_strong_B1 : X_opt == "B2/S2 sig" ? buy_strong_B2 : na // sell signal options opt_sig_sell = X_opt == "---" ? na : X_opt == "Inside Bar sig" ? i_bar_sell : X_opt == "Outside Bar sig" ? o_bar_sell : X_opt == "Sandwich Bar sig" ? s_bar_sell : X_opt == "Bar sig" ? close < low[1] : X_opt == "SMA50 sig" ? close[2] < sma(close, 50) : X_opt == "Fractals sig" ? fr_dnx : X_opt == "RSI50 sig" ? rsi_f_sell : X_opt == "Parabolic SAR sig" ? psar_sell : X_opt == "SuperTrend sig" ? sup_sell : X_opt == "Price X Kijun sig" ? close < KJ : X_opt == "Price X Kumo sig" ? close < kumo_low : X_opt == "Kumo flip sig" ? SA < SB : X_opt == "Price filtered Kumo flip sig" ? not sasb_x and high < kumo_low : X_opt == "Chikou X price sig" ? CS < low[(26-1)] : X_opt == "Chikou X Kumo sig" ? CS < kumo_high[26-1] : X_opt == "Price X Tenkan sig" ? close < TK : X_opt == "Tenkan X Kumo sig" ? TK < kumo_low : X_opt == "Tenkan X Kijun sig" ? TK < KJ : X_opt == "Kumo filtered Tenkan X Kijun sig" ? not tkkj_x and TK < kumo_low and KJ < kumo_low and TK < KJ : X_opt == "CB/CS sig" ? short_c : X_opt == "IB/IS sig" ? short_pic : X_opt == "B1/S1 sig" ? sell_strong_S1 : X_opt == "B2/S2 sig" ? sell_strong_S2 : na if opt_sig_sell buy_sig := true, sell_sig_opt := false if opt_sig_buy sell_sig := true, buy_sig_opt := false //---------------------------- Take profit and stop loss ------------------------------ tp_en = input(title= "Enable take profit", type= input.bool, defval= false) qty_tp = input(50, title= "Take profit - quantity of position (percent)", type= input.float, minval= 1, maxval= 100, step= 5) tp_ticks = input(1000, title= "Take profit - ticks", type= input.integer, minval= 0, step= 10) sl_en = input(title= "Enable stop loss", type= input.bool, defval= false) sl_ticks = input(1000, title= "Stop loss - ticks", type= input.integer, minval= 0, step= 10) //----------------------- Backtest periode -------------------------------- start_year = input(2018, "Start year") start_month = input(1, "Start month", minval= 1, maxval= 12) start_day = input(1, "Start day", minval= 1, maxval= 31) period_start = timestamp(start_year, start_month, start_day, 0, 0) stop_year = input(2021, "Stop year") stop_month = input(12, "Stop month", minval= 1, maxval= 12) stop_day = input(31, "Stop day", minval= 1, maxval= 31) period_stop = timestamp(stop_year, stop_month, stop_day, 0, 0) backtest_period() => time >= period_start and time <= period_stop ? true : false //--------------------- strategy entry --------------------- long = entry_type != "Short" short = entry_type != "Long" not_both = entry_type != "Both" if not backtest if long strategy.entry("os_buy", strategy.long, when = opt_sig_buy and entry_filter_buy_1 and entry_filter_buy_2, comment= "") strategy.close("os_buy", when = exit_filter_sell_1 or exit_filter_sell_2 or not_both ? opt_sig_sell : na , comment= "") strategy.exit("tpl", "os_buy", qty_percent= tp_en ? qty_tp : na, profit= tp_en ? tp_ticks : na, loss= sl_en ? sl_ticks : na) if short strategy.entry("os_sell",strategy.short, when = opt_sig_sell and entry_filter_sell_1 and entry_filter_sell_2, comment= "") strategy.close("os_sell", when = exit_filter_buy_1 or exit_filter_buy_2 or not_both ? opt_sig_buy : na , comment= "") strategy.exit("tps", "os_sell", qty_percent= tp_en ? qty_tp : na, profit= tp_en ? tp_ticks : na, loss= sl_en ? sl_ticks : na) if backtest_period() and backtest if long strategy.entry("os_buy", strategy.long, when = opt_sig_buy and entry_filter_buy_1 and entry_filter_buy_2) strategy.close("os_buy", when = exit_filter_sell_1 or exit_filter_sell_2 or not_both ? opt_sig_sell : na) strategy.exit("tpl", "os_buy", qty_percent= tp_en ? qty_tp : na, profit= tp_en ? tp_ticks : na, loss= sl_en ? sl_ticks : na) if short strategy.entry("os_sell",strategy.short, when = opt_sig_sell and entry_filter_sell_1 and entry_filter_sell_2) strategy.close("os_sell", when = exit_filter_buy_1 or exit_filter_buy_2 or not_both ? opt_sig_buy : na) strategy.exit("tps", "os_sell", qty_percent= tp_en ? qty_tp : na, profit= tp_en ? tp_ticks : na, loss= sl_en ? sl_ticks : na)