-
https://tr.tradingview.com/v/QgVDxphm/
5 dakkalık grafiklerde kullanmak için range...strateji kodu... v3 versiyon...
PHP Code:
//@version=5
strategy(title='Range Filter Buy and Sell 5min [Strategy]', overlay=true, commission_type=strategy.commission.percent, commission_value=0.025, default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000, slippage=0)
// === INPUT BACKTEST RANGE ===
useDate = input(true, title='---------------- Use Date ----------------')
FromMonth = input.int(defval=7, title='From Month', minval=1, maxval=12)
FromDay = input.int(defval=25, title='From Day', minval=1, maxval=31)
FromYear = input.int(defval=2019, title='From Year', minval=2017)
ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)
ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)
ToYear = input.int(defval=9999, title='To Year', minval=2017)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => // create function "within window of time"
time >= start and time <= finish ? true : false
// === INPUT BACKTEST RANGE ===
sources = input(defval=close, title='Source')
isHA = input(false, 'Use HA Candles')
heikenashi_1 = ticker.heikinashi(syminfo.tickerid)
security_1 = request.security(heikenashi_1, timeframe.period, sources)
src = isHA ? security_1 : sources
// Sampling Period
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
per = input.int(defval=50, minval=1, title='Sampling Period')
// Range Multiplier
mult = input.float(defval=3.0, minval=0.1, title='Range Multiplier')
// Smooth Average Range
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(src, per, mult)
// Range Filter
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(src, smrng)
// Filter Direction
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
// Target Bands
hband = filt + smrng
lband = filt - smrng
// Colors
filtcolor = upward > 0 ? color.lime : downward > 0 ? color.red : color.orange
barcolor = src > filt and src > src[1] and upward > 0 ? color.lime : src > filt and src < src[1] and upward > 0 ? color.green : src < filt and src < src[1] and downward > 0 ? color.red : src < filt and src > src[1] and downward > 0 ? color.maroon : color.orange
filtplot = plot(filt, color=filtcolor, linewidth=3, title='Range Filter')
// Target
hbandplot = plot(hband, color=color.new(color.aqua, 100), title='High Target')
lbandplot = plot(lband, color=color.new(color.fuchsia, 100), title='Low Target')
// Fills
fill(hbandplot, filtplot, color=color.new(color.aqua, 90), title='High Target Range')
fill(lbandplot, filtplot, color=color.new(color.fuchsia, 90), title='Low Target Range')
// Bar Color
//barcolor(barcolor)
// Break Outs
longCond = bool(na)
shortCond = bool(na)
longCond := src > filt and src > src[1] and upward > 0 or src > filt and src < src[1] and upward > 0
shortCond := src < filt and src < src[1] and downward > 0 or src < filt and src > src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//Alerts
plotshape(longCondition, title='Buy Signal', text='BUY', textcolor=color.new(color.white, 0), style=shape.labelup, size=size.normal, location=location.belowbar, color=color.new(color.green, 0))
plotshape(shortCondition, title='Sell Signal', text='SELL', textcolor=color.new(color.white, 0), style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.new(color.red, 0))
//strategy.entry("Long", strategy.long, stop = hband, when = window() , comment="Long")
//strategy.entry("Short", strategy.short, stop = lband, when = window() , comment="Short")
strategy.entry('Long', strategy.long, when=longCondition and window(), comment='Long')
strategy.entry('Short', strategy.short, when=shortCondition and window(), comment='Short')
// === Stop LOSS ===
useStopLoss = input(false, title='----- Use Stop Loss / Take profit -----')
sl_inp = input.float(100, title='Stop Loss %', step=0.25) / 100
tp_inp = input.float(1.5, title='Take Profit %', step=0.25) / 100
stop_level = strategy.position_avg_price * (1 - sl_inp)
take_level = strategy.position_avg_price * (1 + tp_inp)
stop_level_short = strategy.position_avg_price * (1 + sl_inp)
take_level_short = strategy.position_avg_price * (1 - tp_inp)
// === Stop LOSS ===
if useStopLoss
strategy.exit('Stop Loss/Profit Long', 'Long', stop=stop_level, limit=take_level)
strategy.exit('Stop Loss/Profit Short', 'Short', stop=stop_level_short, limit=take_level_short)
v5 hali...
-
-
-
-
https://tr.tradingview.com/v/r2aZvj57/
2 farklı uuznluğa.. belirleyeceğiniz 2 farklı oranla...
range hesaplatıp....sinyal oluşturuyor... v4
v5 hali...
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © colinmck
//@version=5
indicator(title='Twin Range Filter', overlay=true)
source = input(defval=close, title='Source')
// Smooth Average Range
per1 = input.int(defval=27, minval=1, title='Fast period')
mult1 = input.float(defval=1.6, minval=0.1, title='Fast range')
per2 = input.int(defval=55, minval=1, title='Slow period')
mult2 = input.float(defval=2, minval=0.1, title='Slow range')
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
// Range Filter
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(source, smrng)
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
hband = filt + smrng
lband = filt - smrng
longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source < filt and source > source[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
long = longCond and CondIni[1] == -1
short = shortCond and CondIni[1] == 1
// Plotting
plotshape(long, title='Long', text='Long', style=shape.labelup, textcolor=color.new(color.black, 0), size=size.tiny, location=location.belowbar, color=color.new(color.lime, 0))
plotshape(short, title='Short', text='Short', style=shape.labeldown, textcolor=color.new(color.white, 0), size=size.tiny, location=location.abovebar, color=color.new(color.red, 0))
// Alerts
alertcondition(long, title='Long', message='Long')
alertcondition(short, title='Short', message='Short')
bunu algo olarak kullanmak isteyenler için...
algo...v5 hali....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © colinmck, greenmask9
//@version=5
strategy(title='Twin Range Filter Algo v.3', shorttitle='Twin Range Strategy', overlay=true)
source = input(defval=close, title='Source')
// Smooth Average Range
per1 = input.int(defval=27, minval=1, title='Fast period', group='Twin Range Filter @colinmck')
mult1 = input.float(defval=1.6, minval=0.1, title='Fast range', group='Twin Range Filter @colinmck')
per2 = input.int(defval=55, minval=1, title='Slow period', group='Twin Range Filter @colinmck')
mult2 = input.float(defval=2, minval=0.1, title='Slow range', group='Twin Range Filter @colinmck')
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
// Range Filter
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(source, smrng)
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
hband = filt + smrng
lband = filt - smrng
longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source < filt and source > source[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
long = longCond and CondIni[1] == -1
short = shortCond and CondIni[1] == 1
// Plotting
// Strategy
// From this part on, programmer is greenmaks9
//
Separator = input.bool(title='Following conditions and backtest algorithm are added by @greenmask9 🎯, original script is written by @colinmck 👍. Read both of their\'s release notes for more info on how this script works.', defval=false, group='Greenmask\'s testing resources & ATR condition')
disabler = input.bool(title='Disable @greenmask9\'s ATR conditions', defval=false, group='Greenmask\'s testing resources & ATR condition')
//second
l2 = input.int(title='ATR1', defval=32, minval=1, group='ATR condition', tooltip='C: Short-range volatility must be low than long-term volatility measurement for the entry.')
s2 = input.string(title='Smoothing', defval='SMA', options=['RMA', 'SMA', 'EMA', 'WMA'], tooltip='C: Short-range volatility must be low than long-term volatility measurement for the entry.', group='ATR condition')
atr2(source, l2) =>
if s2 == 'SMA'
ta.sma(source, l2)
else
if s2 == 'RMA'
ta.rma(source, l2)
else
if s2 == 'EMA'
ta.ema(source, l2)
else
ta.wma(source, l2)
//third
l3 = input.int(title='ATR2', defval=64, minval=1, group='ATR condition', tooltip='C: Short-range volatility must be low than long-term volatility measurement for the entry.')
s3 = input.string(title='Smoothing', defval='RMA', options=['RMA', 'SMA', 'EMA', 'WMA'], tooltip='C: Short-range volatility must be low than long-term volatility measurement for the entry.', group='ATR condition')
atr3(source, l3) =>
if s3 == 'RMA'
ta.rma(source, l3)
else
if s3 == 'SMA'
ta.sma(source, l3)
else
if s3 == 'EMA'
ta.ema(source, l3)
else
ta.wma(source, l3)
atr20 = atr2(ta.tr(true), l2)
atr30 = atr3(ta.tr(true), l3)
ordersize = math.floor(strategy.initial_capital / close)
maxcandles_till_close = input.int(title='Time-based Close', defval=17, group='Alternative Exit')
i_time = input.bool(true, 'Enable Time Base Close', group='Alternative Exit')
//stop
varip stop_long = 0.0
varip entry = 0.0
varip stop_short = 0.0
i_sl_type = input.string('Low - (close - lowest low[len]) * %', options=['Low - (ATR[len] * %)', 'Low - (close - lowest low[len]) * %', 'Low - (close - average low[len]) * %', 'Close - (ATR[len] * %)', 'Low - TicksNumber'], title='Calculation (Long)', group='Stop-loss', tooltip='This is a stop-loss calculation for long positions. Reversed logic is used for short stop-loss. *Calculation Low - TicksNumber doesn\'t use Percentage-based multiplier. **Number of ticks is always substracted (added) after the initial calculation. ')
i_sl_atr = input.int(10, 'Calculation Length', group='Stop-loss')
i_sl_perc = input.float(80, 'Percentage', group='Stop-loss') / 100
i_sl_ticks = input.int(defval=10, minval=1, title='Number of ticks', group='Stop-loss') * syminfo.mintick
i_stoploss = input.bool(true, 'Enable Stop-loss', group='Stop-loss')
f_stop_long(calculation, length, mult, ticks) =>
stop_0 = calculation == 'Low - (ATR[len] * %)' ? low - ta.atr(length) * mult - ticks : calculation == 'Low - (close - lowest low[len]) * %' ? low - (close - ta.lowest(low, length)) * mult - ticks : calculation == 'Low - (close - average low[len]) * %' ? low - (close - ta.sma(low, length)) * mult - ticks : calculation == 'Close - (ATR[len] * %)' ? close - ta.atr(length) * mult - ticks : low - ticks
stop_0
f_stop_short(calculation, length, mult, ticks) =>
stop_0 = calculation == 'Low - (ATR[len] * %)' ? high + ta.atr(length) * mult + ticks : calculation == 'Low - (close - lowest low[len]) * %' ? high + math.abs(close - ta.lowest(high, length)) * mult + ticks : calculation == 'Low - (close - average low[len]) * %' ? high + math.abs(close - ta.sma(high, length)) * mult + ticks : calculation == 'Close - (ATR[len] * %)' ? close + ta.atr(length) * mult + ticks : high + ticks
stop_0
//target
varip target_long = 0.0
varip target_short = 0.0
i_tr_type = input.string('Close + (ATR[len] * %)', options=['High + (ATR[len] * %)', 'Close + (ATR[len] * %)', 'Close + abs(close - highest high[len]) * %', 'Close + abs(close - average high[len]) * %', 'High + TicksNumber', 'Close + TicksNumber'], title='Calculation (Long)', group='Target', tooltip='Raw number of ticks is always added to the target.')
i_tr_atr = input.int(10, 'Calculation Length', group='Target')
i_tr_perc = input.float(500, 'Percentage', group='Target') / 100
i_tr_ticks = input.int(defval=10, minval=1, title='Number of ticks', group='Target') * syminfo.mintick
i_target = input.bool(true, 'Enable Target', group='Target')
f_target_long(calculation, length, mult, ticks) =>
stop_0 = calculation == 'High + (ATR[len] * %)' ? high + ta.atr(length) * mult + ticks : calculation == 'Close + (ATR[len] * %)' ? close + ta.atr(length) * mult + ticks : calculation == 'Close + abs(close - highest high[len]) * %' ? close + math.abs(close - ta.highest(high, length)) * mult + ticks : calculation == 'Close + abs(close - average high[len]) * %' ? close + math.abs(close - ta.sma(high, length)) * mult + ticks : calculation == 'High + TicksNumber' ? high + ticks : close + ticks
stop_0
f_target_short(calculation, length, mult, ticks) =>
stop_0 = calculation == 'High + (ATR[len] * %)' ? low - ta.atr(length) * mult - ticks : calculation == 'Close + (ATR[len] * %)' ? close - ta.atr(length) * mult - ticks : calculation == 'Close + abs(close - highest high[len]) * %' ? close - math.abs(close - ta.lowest(low, length)) * mult - ticks : calculation == 'Close + abs(close - average high[len]) * %' ? close - math.abs(close - ta.sma(low, length)) * mult - ticks : calculation == 'High + TicksNumber' ? low - ticks : close - ticks
stop_0
if strategy.position_size >= 0 or strategy.position_size[1] != strategy.position_size
stop_short := i_stoploss ? f_stop_short(i_sl_type, i_sl_atr, i_sl_perc, i_sl_ticks) : na
target_short := i_target ? f_target_short(i_tr_type, i_tr_atr, i_tr_perc, i_tr_ticks) : na
target_short
if strategy.position_size <= 0 or strategy.position_size[1] != strategy.position_size
stop_long := i_stoploss ? f_stop_long(i_sl_type, i_sl_atr, i_sl_perc, i_sl_ticks) : na
target_long := i_target ? f_target_long(i_tr_type, i_tr_atr, i_tr_perc, i_tr_ticks) : na
target_long
if strategy.position_size == 0 or strategy.position_size[1] != strategy.position_size
entry := open
entry
bull = long and (atr20 < atr30 or disabler)
bear = short and (atr20 < atr30 or disabler)
bullclock = ta.barssince(bull)
bearclock = ta.barssince(bear)
if bull
strategy.entry('Twin Long', strategy.long, ordersize)
strategy.exit('Exit', from_entry='Twin Long', limit=target_long, stop=stop_long)
if bear
strategy.entry('Twin Short', strategy.short, ordersize)
strategy.exit('Exit', from_entry='Twin Short', limit=target_short, stop=stop_short)
i_message_long = input.string('Long entry default message: x', 'Long Entry Alert Message', group='Alert')
i_long_alert = input.bool(true, 'Enable Long Alert', group='Alert')
i_message_short = input.string('Long entry default message: x', 'Short Entry Alert Message', group='Alert')
i_short_alert = input.bool(true, 'Enable Short Alert', group='Alert')
if bull and strategy.position_size[1] == 0 and i_long_alert
alert(i_message_long, alert.freq_once_per_bar_close)
if bear and strategy.position_size[1] == 0 and i_short_alert
alert(i_message_short, alert.freq_once_per_bar_close)
//time stoploss
if i_time
strategy.close('Twin Long', when=bullclock == maxcandles_till_close, comment='Time')
strategy.close('Twin Short', when=bearclock == maxcandles_till_close, comment='Time')
c_fill_stop = color.new(color.red, 90)
c_fill_target = color.new(color.green, 90)
p_longstop = plot(strategy.position_size > 0 and i_stoploss ? stop_long : na, linewidth=2, color=color.new(color.red, 0), style=plot.style_linebr)
p_shortstop = plot(strategy.position_size < 0 and i_stoploss ? stop_short : na, linewidth=2, color=color.new(color.red, 0), style=plot.style_linebr)
p_entry = plot(strategy.position_size != 0 ? entry : na, linewidth=2, color=color.new(color.blue, 0), style=plot.style_linebr)
p_longtarget = plot(strategy.position_size > 0 and i_target ? target_long : na, linewidth=2, color=color.new(color.green, 0), style=plot.style_linebr)
p_shorttarget = plot(strategy.position_size < 0 and i_target ? target_short : na, linewidth=2, color=color.new(color.green, 0), style=plot.style_linebr)
fill(p_entry, p_longstop, c_fill_stop)
fill(p_entry, p_shortstop, c_fill_stop)
fill(p_entry, p_longtarget, c_fill_target)
fill(p_entry, p_shorttarget, c_fill_target)
-
-
https://i.hizliresim.com/5opi1hv.png
range hesaplamalrı ile tasarlanmmış sade ve agresif bir sistem oldu...
z score ile hedefleme yapıldı...
-