RicardoSantos

[STRATEGY][RS][JR] Triple Timeframe Bollinger excess V0

Request for:JR
preliminary version
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
//strategy("My Script", overlay=true)
strategy(title='[STRATEGY][RS][JR] Triple Timeframe Bollinger excess V0', overlay=true, pyramiding=0, default_qty_type=strategy.cash, default_qty_value=1000, initial_capital=100000, currency=currency.USD)
//  ||------------------------------||
//  ||  Timeframe 0 code block      ||
use_tf00 = input(true)
tf00_src = input(close)
tf00_length = input(5)
tf00_deviations = input(0.6)
tf00_basis = sma(tf00_src, tf00_length)
tf00_dev = tf00_deviations * stdev(tf00_src, tf00_length)
tf00_upper = tf00_basis + tf00_dev
tf00_lower = tf00_basis - tf00_dev
tf00_buy_signal = use_tf00 ? change(close > tf00_upper) > 0 : true
tf00_sel_signal = use_tf00 ? change(close < tf00_lower) > 0 : true
plot(series=tf00_basis, title='00 Basis', color=color(blue, 0), style=linebr)
plot(series=tf00_upper, title='00 Upper', color=color(red, 0), style=linebr)
plot(series=tf00_lower, title='00 Lower', color=color(red, 0), style=linebr)
//  ||------------------------------||
//  ||  Timeframe 1 code block      ||
use_tf01 = input(true)
tf01_timeframe = input('30')
tf01_src = input(defval=open, title='TF01 Source(WARNING:change at your own risk!!)')
tf01_length = input(5)
tf01_deviations = input(0.6)
tf01_basis = security(tickerid, tf01_timeframe, sma(tf01_src, tf01_length))
tf01_dev = security(tickerid, tf01_timeframe, tf01_deviations * stdev(tf01_src, tf01_length))
tf01_upper = security(tickerid, tf01_timeframe, tf01_basis + tf01_dev)
tf01_lower = security(tickerid, tf01_timeframe, tf01_basis - tf01_dev)
tf01_buy_signal = use_tf01 ? change(close > tf01_upper) > 0 : true
tf01_sel_signal = use_tf01 ? change(close < tf01_lower) > 0 : true
plot(series=tf01_basis, title='01 Basis', color=color(blue, 0), style=linebr)
plot(series=tf01_upper, title='01 Upper', color=color(red, 0), style=linebr)
plot(series=tf01_lower, title='01 Lower', color=color(red, 0), style=linebr)
//  ||------------------------------||
//  ||  Timeframe 2 code block      ||
use_tf02 = input(true)
tf02_timeframe = input('90')
tf02_src = input(defval=open, title='TF01 Source(WARNING:change at your own risk!!)')
tf02_length = input(5)
tf02_deviations = input(0.6)
tf02_basis = security(tickerid, tf02_timeframe, sma(tf02_src, tf02_length))
tf02_dev = security(tickerid, tf02_timeframe, tf02_deviations * stdev(tf02_src, tf02_length))
tf02_upper = security(tickerid, tf02_timeframe, tf02_basis + tf02_dev)
tf02_lower = security(tickerid, tf02_timeframe, tf02_basis - tf02_dev)
tf02_buy_signal = use_tf02 ? change(close > tf02_upper) > 0 : true
tf02_sel_signal = use_tf02 ? change(close < tf02_lower) > 0 : true
plot(series=tf02_basis, title='02 Basis', color=color(blue, 0), style=linebr)
plot(series=tf02_upper, title='02 Upper', color=color(red, 0), style=linebr)
plot(series=tf02_lower, title='02 Lower', color=color(red, 0), style=linebr)

buy_trigger = tf00_buy_signal and tf01_buy_signal and tf02_buy_signal
sel_trigger = tf00_sel_signal and tf01_sel_signal and tf02_sel_signal

//  ||  -->
//  ||  Effective Trading Session:
use_trade_session = input(false)
trade_session = input(title='Trade Session(xxxx-xxxx or xxxx-xxxx,xxxx-xxxx to define a interval):', type=string, defval='0400-0700,0900-1300', confirm=false)
isinsession = use_trade_session ? not na(time('1', trade_session)) : true
bgcolor(color=use_trade_session and isinsession ? purple : na, transp=95, title='In Session BG')
//  ||  -->

//  ||  -->
//  ||  Account Margin Management:
f_account_margin_call(_ammount)=>_return = na(_return[1]) ? false : strategy.equity <= _ammount ? true : _return[1]
//  ||  -->
//  ||  -->
f_account_fixed_trail_call(_ammount)=>
    _maximum_equity = na(_maximum_equity[1]) ? strategy.equity : max(_maximum_equity[1], strategy.equity)
    _return = na(_return[1]) ? false : strategy.equity <= _maximum_equity - _ammount ? true : _return[1]
//  ||  -->
//  ||  -->
f_account_percent_trail_call(_percent)=>
    _maximum_equity = na(_maximum_equity[1]) ? strategy.equity : max(_maximum_equity[1], strategy.equity)
    _return = na(_return[1]) ? false : strategy.equity <= _maximum_equity * (_percent/100) ? true : _return[1]
//  ||  -->
//  ||  -->
use_margin_call = input(false)
margin_call_mode = input(defval=1, title='1:fixed value, 2:fixed value trail, 3:percent equity trail', type=integer, minval=1, maxval=3)
margin_value = input(95000)

trade_if_not_margin_call = use_margin_call ? (margin_call_mode == 1 ? not f_account_margin_call(margin_value) : margin_call_mode == 2 ? not f_account_fixed_trail_call(margin_value) : margin_call_mode == 3 ? not f_account_percent_trail_call(margin_value) : false) : true
    

wins_multiplier = input(defval=1.00, title='Scaling Multiplier for Consecutive Wins:')
losses_multiplier = input(defval=1.00, title='Scaling Multiplier for Consecutive Losses:')


buy_cond = isinsession and trade_if_not_margin_call and buy_trigger and strategy.opentrades < 1
sel_cond = isinsession and trade_if_not_margin_call and sel_trigger and strategy.opentrades < 1

f_martingale_wins_multiplier(_multiplier) => _return = na(_return[1]) ? 1 : change(strategy.losstrades) > 0 ? 1 : change(strategy.wintrades) > 0 or change(strategy.eventrades) > 0 ? _return[1] * _multiplier : _return[1]
f_martingale_loss_multiplier(_multiplier) => _return = na(_return[1]) ? 1 : change(strategy.wintrades) > 0 ? 1 : change(strategy.losstrades) > 0 or change(strategy.eventrades) > 0 ? _return[1] * _multiplier : _return[1]

mode = change(strategy.wintrades) > 0 ? 1 : change(strategy.losstrades) > 0 ? -1 : nz(mode[1], 1)
trade_multiplier = mode > 0 ? f_martingale_wins_multiplier(wins_multiplier) : f_martingale_loss_multiplier(losses_multiplier)

trade_size = input(defval=1000, title='Base trade value:')
trade_leverage = input(defval=1, title='Base Leverage value:')
trade_size_multiplied = (trade_size * trade_leverage) * trade_multiplier

//plot(strategy.closedtrades)
strategy.entry('B', long=true, qty=trade_size_multiplied, when=buy_cond)
strategy.entry('S', long=false, qty=trade_size_multiplied, when=sel_cond)

take_profit = input(defval=250, title='TP in ticks(1/10 of a pip):')
stop_loss = input(defval=100, title='SL in ticks(1/10 of a pip):')
strategy.exit('B', from_entry='B', profit=take_profit, loss=stop_loss)
strategy.exit('S', from_entry='S', profit=take_profit, loss=stop_loss)

//p_eq = plot(series=strategy.equity, title='Equity', color=black, linewidth=2)

//drawdown = change(strategy.closedtrades) > 0 ? strategy.equity : drawdown[1]
//p_dd = plot(series=drawdown, title='Drawdown', style=linebr, color=red, linewidth=1)

//fill(plot1=p_eq, plot2=p_dd, color=red, transp=70, title='DD')

trade_open_price = strategy.opentrades == 0 ? na : change(strategy.opentrades) > 0 ? open : trade_open_price[1]
trade_loss_price = strategy.opentrades == 0 ? na : change(strategy.opentrades) > 0 ? (buy_trigger[1] ? trade_open_price - (stop_loss * (round(open)*0.00001)) : trade_open_price + (stop_loss * (round(open)*0.00001))) : trade_loss_price[1]
trade_profit_price = strategy.opentrades == 0 ? na : change(strategy.opentrades) > 0 ? (buy_trigger[1] ? trade_open_price + (take_profit * (round(open)*0.00001)) : trade_open_price - (take_profit * (round(open)*0.00001))) : trade_profit_price[1]
t_o = plot(series=trade_open_price, title='Trade Open Price Line', color=color(black, 0), style=linebr)
t_l = plot(series=trade_loss_price, title='Trade Loss Price Line', color=color(black, 0), style=linebr)
t_p = plot(series=trade_profit_price, title='Trade Profit Price Line', color=color(black, 0), style=linebr)
fill(plot1=t_o, plot2=t_l, color=red, transp=80, title='Trade Loss Fill')
fill(plot1=t_o, plot2=t_p, color=lime, transp=80, title='Trade Profit Fill')
English
English (UK)
English (IN)
Deutsch
Français
Español
Italiano
Polski
Türkçe
Русский
Português
Bahasa Indonesia
Bahasa Melayu
ภาษาไทย
Tiếng Việt
日本語
한국어
简体
台灣
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out