How to store data (pivots) from previous trading day, and draw them as levels on current today trading session?

岁酱吖の 提交于 2021-01-07 06:32:09

问题


Trying to find some way to store pivots data of the previous day trading, and put them inside an array to carry those points to the current day trading for drawing them as line levels.


For example, $AAPL stock.

On Tuesday (yesterday), recorded pivots points at these levels [100.2, 100.3, 100.5] at 15-min timeframe.

On Wednesday (today), I'm looking to draw Support/Resistance lines based on selected pivots [100.2, 100.3, 100.5] from the previous day of trading.

I've already done it in python, but I couldn't find a successful method capable of pine script.

====================================================

To PinseScript Response #1

I already tried this method before, but unfortunately, it didn't work inside a 15-min security function. It seems the security didn't recognize the result of change(time('D')), but when I plot the change(time('D')), it gives the result. Check image description below

Again,

  1. The output of change(time('D')) is not recognized by PineScript, if I use it inside a security function.
  2. The PineScript Plotted the output change(time('D')) successfully. Check image bellow.

============================================

To PinseScript Response #2

here's my full code, the change(time('D')) insdie function FunYesterday() below

//------------------ Select Day of Trading
Start_Period= timestamp(syminfo.timezone, 2020, 12, 09, 00, 00, 00) //Start Day
End_Period  = timestamp(syminfo.timezone, 2020, 12, 09, 23, 59, 59) //End Day


//------------------ Filtring Session
t_reg   = time("1440", session.regular)  // Regular Session
t_ext   = time("1440", session.extended) // Extended Session
// Brackets the time [ Start Day --- To ----- End Day] 
T_ext   = time >= Start_Period and time <= End_Period and t_ext


// Build a function to detect the change of time between current day-trading and most recent day trading (t-t[1])

FunYesterday()=>
    Change_Time         = iff(T_ext == true, change(time("1D")), na) 
    Change_Time_Update  = fixnan(Change_Time <= 0? na: Change_Time)
    Change_Time_Update2 = iff(T_ext == true, Change_Time_Update, na)

    if time >= Start_Period-Change_Time_Update2 and time <= End_Period-Change_Time_Update2 and t_reg
        [pivothigh(close, 3, 2), pivotlow(close, 3, 2)]


//------------------ Pivot point at 15 min. 
[ph2, pl2] = security(syminfo.tickerid, "15", FunYesterday(), lookahead = barmerge.lookahead_off)
ph2_filter= ph2 == ph2[1]?na:ph2
pl2_filter= pl2 == pl2[1]?na:pl2

//------------------ Array Part
var a = array.new_float()
if (not na(ph2_filter))
    array.push(a,ph2_filter)
else if (not na(pl2_filter))
    array.push(a,pl2_filter)


if barstate.islast and array.size(a)>0
        
    y=label.new(bar_index, close, "Initial\na: " + tostring(a))
    label.delete(y[1])

回答1:


Part 1

Provided you are running the chart on a < 15min resolution, the best way would be to maintain queues of pivot values using arrays and clear the arrays on change(time("D")) so they reset every day.

See the usrman on arrays for an example of queue handling.

Part 2

change(time("D")) is meant to be detected at the chart's resolution:

//@version=4
study("", "", true)
newDay = change(time("D"))
plotchar(newDay, "newDay", "►", location.top, size = size.tiny)



来源:https://stackoverflow.com/questions/65306165/how-to-store-data-pivots-from-previous-trading-day-and-draw-them-as-levels-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!