PHP Code:
//@version=6
indicator("MTF 123", overlay=true)
INLINE_1 = "1"
UPDATE_LAST_INFO = "How many boxes will be updated for extend to current bar?"
TIMEFRAME_TEXT_INFO="Time periods should be written with commas and without spaces."
UPDATE_LAST = input.int(4, "Update last", tooltip=UPDATE_LAST_INFO)
TIMEFRAME_CHOICE = input.string("1,2,3", "Timeframes", ["1,2,3", "1,3,5"], inline=INLINE_1)
USE_CUSTOM_TIMEFRAME = input.bool(true, "Use Custom", inline=INLINE_1)
TIMEFRAME_TEXT = input.text_area("1,2,3,5", "Custom Timeframe", tooltip=TIMEFRAME_TEXT_INFO)
enum TYPE
BULLISH
BEARISH
type Area
float top
float bottom
int left_time
box display = na
method display(Area this, string tf = na, TYPE _type = na) =>
if na(this.display)
this.display := box.new(this.left_time, this.top, time, this.bottom, xloc=xloc.bar_time)
this.display.set_border_width(0)
this.display.set_bgcolor(color.new(_type == TYPE.BULLISH ? color.green : color.red , 80))
this.display.set_text(tf)
this.display.set_text_halign(text.align_right)
this.display.set_text_valign(_type == TYPE.BULLISH ? text.align_bottom : text.align_top)
this.display.set_text_size(size.small)
this.display.set_text_color(color.new(color.yellow, 00))
else
this.display.set_right(time)
true
type FTR
Area area
TYPE _type
string tf
f_get_ftr() =>
tf = timeframe.period
is_bullish = close > open
lbus = ta.barssince(is_bullish)
lbes = ta.barssince(not is_bullish)
lbes_ftr = lbes[1] + 1
pbes_ftr = lbes[lbes_ftr + 1] + lbes_ftr + 1
bullish_cond = not is_bullish and low - high[lbes_ftr] > 0 and low[lbes_ftr] > high[pbes_ftr]
lbus_ftr = lbus[1] + 1
pbus_ftr = lbus[lbus_ftr + 1] + lbus_ftr + 1
bearish_cond = is_bullish and low[lbus_ftr] - high > 0 and low[pbus_ftr] - high[lbus_ftr] > 0
FTR ftr = na
if bullish_cond
area = Area.new(high[lbes_ftr], low[lbes_ftr], time[lbes_ftr], na)
ftr := FTR.new(area, TYPE.BULLISH, tf)
if bearish_cond
area = Area.new(high[lbus_ftr], low[lbus_ftr], time[lbus_ftr], na)
ftr := FTR.new(area, TYPE.BEARISH, tf)
ftr
method check_ftr(array<FTR> this) =>
for [index, ftr] in this
if ftr._type == TYPE.BULLISH and low < ftr.area.bottom
this.remove(index)
break
if ftr._type == TYPE.BEARISH and high > ftr.area.top
this.remove(index)
break
method update_display(array<FTR> this) =>
for i=1 to math.min(this.size(), UPDATE_LAST)
ftr = this.get(-i)
ftr.area.display()
method price_in_area(array<FTR> this) =>
is_in_area = false
for ftr in this
if ftr._type == TYPE.BULLISH and close < ftr.area.top
is_in_area := true
break
if ftr._type == TYPE.BEARISH and close > ftr.area.bottom
is_in_area := true
break
is_in_area
var store = array.new<FTR>()
timeframes = USE_CUSTOM_TIMEFRAME ? TIMEFRAME_TEXT : TIMEFRAME_CHOICE
for tf in str.split(timeframes, ",")
ftr = request.security(syminfo.tickerid, tf, f_get_ftr())
if not na(ftr) and na(ftr[1])
store.push(ftr)
ftr.area.display(ftr.tf, ftr._type)
if store.size() > 1
store.check_ftr()
store.update_display()
///////
üzerinde oynanmış bir mtf çalışmasıdır.....
Yer İmleri