Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © alphatrader09
- //@version=4
- study("TPO Project", overlay = true, max_lines_count = 500)
- tpoSize = input(20)
- timeFrame = input("D")
- // pltLine = input(title = "TPO Length", type = input.integer, defval = 2)
- int i_sessions = input( title='Sessions to display:', defval=50, minval=1, maxval=50, tooltip='Session number to display.')
- _uppercol = input(title = "Colors for Value Area High" , type = input.color, defval = #f50000)
- _downcol = input(title = "Colors for Value Area Low" , type = input.color, defval = #00c700)
- _poccol = input(title = "Color of PoC" , type = input.color, defval = #00bfff)
- _pdhl = input(title = "Color of PDH & PDL" , type = input.color, defval = color.gray)
- inrange(_tpo,_high,_low)=>
- cond = _high >= _tpo and _low <= _tpo
- get_index(_array, up, dn)=>
- upval = array.get(_array,up)
- dnval = array.get(_array,dn)
- index = upval > dnval ? up : dn
- val = max(upval, dnval)
- [index, val]
- MarketProfile(res) =>
- bool newbar = change(time(res)) != 0
- float tfHigh = na
- float tfLow = na
- int barNum = na
- var tpoIndex = array.new_int(tpoSize + 2 , 0)
- var tpoValue = array.new_float(tpoSize + 2 , 0)
- tfHigh := newbar ? high : max(tfHigh[1], high)
- tfLow := newbar ? low : min(tfLow[1], low)
- barNum := newbar ? 0 : barNum[1] + 1
- ranGe = tfHigh - tfLow
- tpoDiff = ranGe / tpoSize
- int tpoSum = 0
- for x = 0 to tpoSize
- _tpovalue = tfLow + (x)* tpoDiff
- array.set(tpoValue, x, _tpovalue)
- int tpoind = 0
- for i = 0 to barNum
- if inrange(_tpovalue, high[i], low[i])
- tpoind:= tpoind + 1
- _tpoIndex = tpoind
- array.set(tpoIndex, x, _tpoIndex)
- tpoSum := tpoSum + _tpoIndex
- pocLen = array.max(tpoIndex)
- pocIndex = array.indexof(tpoIndex,pocLen)
- pocValue = tfLow + pocIndex* tpoDiff
- int vaHighIndex = pocIndex
- int vaLowIndex = pocIndex
- float valueArea = pocLen
- float targetArea = tpoSum * 0.70
- // for i = 1 to tpoSize
- // if valueArea < targetArea
- // vaHighIndex := min(tpoSize - 1, vaHighIndex + 1)
- // valueArea := valueArea + array.get(tpoIndex,vaHighIndex)
- // if valueArea < targetArea
- // vaLowIndex := max(0, vaLowIndex - 1)
- // valueArea := valueArea + array.get(tpoIndex,vaLowIndex)
- for x = 0 to tpoSize
- if valueArea <= tpoSum * 0.70
- tup = min(tpoSize,vaHighIndex + 1)
- tdn = max(0,vaLowIndex - 1)
- [index,val] = get_index(tpoIndex,tup,tdn)
- if index == tdn
- vaLowIndex := tdn
- valueArea := valueArea + val
- else
- vaHighIndex := tup
- valueArea := valueArea + val
- vaHigh = (tfLow + (vaHighIndex ) * tpoDiff)
- vaLow = (tfLow + (vaLowIndex) * tpoDiff)
- pocV = valuewhen(newbar, pocValue[1],0)
- vaH = valuewhen(newbar, vaHigh[1],0)
- vaL = valuewhen(newbar, vaLow[1],0)
- maxH = tfHigh - pocV
- [pocValue,pocV, vaH, vaL, vaHigh, vaLow]
- [pocValue,pocV, vaH, vaL, vaHigh, vaLow] = MarketProfile(timeFrame)
- newSession = change(time(timeFrame)) != 0
- insession = change(time(timeFrame)) == 0
- plot(insession ? pocValue: na, color = _poccol, linewidth = 1, style = plot.style_linebr)
- // plot(insession ? vaHigh: na, color = _uppercol, linewidth = 1, style = plot.style_linebr)
- // plot(insession ? vaLow: na, color = _downcol, linewidth = 1, style = plot.style_linebr)
- tfHigh = 0.0
- tfHigh := newSession ? high : max(tfHigh[1], high)
- var int previous_session_start = na
- var int previous_session_end = na
- if newSession
- previous_session_start := previous_session_end
- previous_session_end := time
- f_Lines_show(_array,max_lines, new_line)=>
- int _size = array.size(_array)
- if _size >= max_lines
- line.delete(array.pop(_array))
- array.unshift(_array, new_line)
- f_Lines_draw(_x1,_y1,_x2,_y2,_col) => line.new(_x1,_y1,_x2, _y2, extend =extend.none, xloc = xloc.bar_time, color =_col, style = line.style_solid, width =2)
- var line[] valueH_Lines = array.new_line(0)
- var line[] valueL_Lines = array.new_line(0)
- var line[] poC_Lines = array.new_line(0)
- if newSession
- // _valHline = line.new(previous_session_end, vah_value[1], time_close(i_session_timeframe), vah_value[1], extend = extend.none, xloc = xloc.bar_time, color = color.new(_uppercol,0), width = 2)
- // _valLline = line.new(previous_session_end, val_value[1], time_close(i_session_timeframe), val_value[1], extend = extend.none, xloc = xloc.bar_time, color = color.new(_downcol,0), width = 2)
- // _pocLine = line.new(previous_session_end, poc[1], time_close(i_session_timeframe), poc[1], extend = extend.none, xloc = xloc.bar_time, color = color.new(_poccol,0), width = 2)
- f_Lines_show(valueH_Lines, i_sessions,f_Lines_draw(previous_session_end, vaH, time_close(timeFrame), vaH, _uppercol))
- f_Lines_show(valueL_Lines, i_sessions,f_Lines_draw(previous_session_end, vaL, time_close(timeFrame), vaL, _downcol))
- f_Lines_show(poC_Lines, i_sessions,f_Lines_draw(previous_session_end, pocV, time_close(timeFrame), pocV, _poccol))
Advertisement
Add Comment
Please, Sign In to add comment