Fibo Levels with Volume Profile [ChartPrime]

ChartPrime · study · 212 行 · 点赞 9,039 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime
 
//@version=5
indicator("Fibo Levels with Volume Profile and Targets [ChartPrime]",overlay = true,max_bars_back = 450,max_boxes_count = 500)
 
 
color Offwhite                                  = color.rgb(255, 255, 255, 71)
color _offwhite                                 = color.rgb(255, 255, 255, 50)
color  Red1                                     = color.rgb(255, 82, 82, 85)
color  Red2                                     = color.rgb(243, 6, 6, 60)
color green                                     = color.rgb(73, 241, 241, 85)
color green2                                    = color.rgb(73, 241, 241, 60)
color Black                                     = color.rgb(7, 7, 7)
color Yellow                                    = color.rgb(254, 229, 4)
 
 
string TIME                                     = input.timeframe("480",title = "Fibo Timeframe",
     group = "Fibo Levels",
     options=["120","240","480","720",'D', 'W', 'M'],
     tooltip = "Choose a Higher Timeframe than Chart Timeframe")
 
int sync                                        = bar_index
float scr                                       = close
string TF                                       = timeframe.isdwm ? "M" : "W"
int atrLen                                      = 30
float mult                                      = 0.3
float per                                       = 10.0
float perc                                      = close * (per/100)
float srdatr                                    = ta.atr (atrLen) * mult
float band                                      = math.min (srdatr, perc) [20] /2
float [] Fibo                                   = array.new_float(6)
var line [] Lines                               = array.new_line()   
var label [] Labels                              = array.new_label()  
var box [] FiboBOX                              = array.new_box()
float FH                                        = request.security(syminfo.tickerid, TIME, high[1]) + band
float FL                                        = request.security(syminfo.tickerid, TIME, low[1]) - band
float FC                                        = request.security(syminfo.tickerid, TIME, close[1]) + band
float [] TotalVolume                            = array.new_float()
float [] Greenvolume                            = array.new_float()
float [] redvolume                              = array.new_float()
 
is_NEWTF(res) =>
    t = time(res)
    not na(t) and (na(t[1]) or t > t[1])
 
isNewTF = is_NEWTF(TF)
 
Volume(GV,RV,TV,BC)=>
    GR = GV / TV 
    RR = RV / TV
    [GR , RR]
 
PP = (FH + FL + FC) / 3
array.set(Fibo,0,PP + 0.382 * (FH - FL))
array.set(Fibo,1,PP - 0.382 * (FH - FL))
array.set(Fibo,2,PP + 0.618 * (FH - FL))
array.set(Fibo,3,PP - 0.618 * (FH - FL))
array.set(Fibo,4,PP + (FH - FL))
array.set(Fibo,5,PP - (FH - FL))
 
int BAR1                    = ta.valuewhen(isNewTF, sync,0)
int levs                    = array.size(Fibo) * 2
float FT                    = array.get(Fibo,4)
float FB                    = array.get(Fibo,5)
float [] VPlevels           = array.new_float(levs+1)
var box [] VPboxes          = array.new_box(levs+3)
 
if array.size(Fibo) > 6
    for i = 0 to 5
        array.shift(Fibo) 
 
 
step = ( FT-FB ) / levs
for i=0 to levs by 1
    array.set(VPlevels,i, FB + step * i)
 
if barstate.islast
    int [] Points       = array.new_int(levs,0)
    float [] Volumes    = array.new_float(levs,0.0)
    float [] SCR        = array.new_float()
     
    for i = 0 to int(sync - BAR1)
        array.push(SCR,close[i])
 
    for i = 0 to array.size(Fibo) - 1
        C = i == 0 or i == 2 or i == 4  
        array.push(FiboBOX,box.new(BAR1,
         array.get(Fibo,i) + (band/2),
         sync + 80,
         array.get(Fibo,i) - (band/2),
         bgcolor = C ? Red1 : green,
         border_color =C ? Red2 : green2,
         border_width = 1))
 
    for i=0 to array.size(SCR) -1
        for x=0 to array.size(VPlevels) - 2  by 1
            if array.get(SCR,i)>array.get(VPlevels,x) 
                 and
                 array.get(SCR,i)<array.get(VPlevels,x+1)
                array.set(Points,x,array.get(Points,x)+1)
                array.set(Volumes,x,array.get(Volumes,x)+volume[x])
                break
        if array.get(SCR,i) > open[i]
            array.push(Greenvolume,volume[i])
        if array.get(SCR,i) < open[i]
            array.push(redvolume,volume[i])
        array.push(TotalVolume,volume[i])
    [GR,RR] = Volume(array.sum(Greenvolume),
         array.sum(redvolume),
         array.sum(TotalVolume),
         array.size(SCR) -1)    
    for i = 0 to array.size(Points) -1
        box.delete(array.get(VPboxes,i))
        array.set(VPboxes,i,
             box.new(sync + 80-array.get(Points,i),
             array.get(VPlevels,i+1) + band,
             sync + 80,
             array.get(VPlevels,i) + band,
         border_color = color.from_gradient(array.get(Points,i),0,
         array.max(Points),
         color.new(#f37451, 70),
         color.new(#42f07f, 35)),
         bgcolor=color.from_gradient(array.get(Points,i),0,
         array.max(Points),
         color.new(#f37451, 70),
         color.new(#42f07f, 35)),
         text=str.tostring(array.get(Volumes,i),format.volume),
         text_color=color.white))
 
    MID = (FB +FT ) / 2 
    if (scr < FT) and (scr > FB)
        if GR > RR
            if (scr > MID)
                array.push(Lines,
                     line.new(sync + 3,
                      hl2[1],sync + 10,
                      array.get(Fibo,2),
                      color= color.lime,
                      style = line.style_arrow_right,
                      width = 1))
                array.push(Labels,
                     label.new(sync + 10,
                     array.get(Fibo,2),
                     "Possible Target ",
                     style=label.style_label_lower_left,
                     color=color.new(color.green, 70),
                     textcolor = color.white,
                     size=size.small))
 
            else if (scr < MID)
                array.push(Lines,
                     line.new(sync + 3,
                     hl2[1],sync + 10,
                     array.get(Fibo,0),
                     color= color.lime,
                     style = line.style_arrow_right,
                     width = 1))
                array.push(Labels,
                     label.new(sync + 10,
                     array.get(Fibo,0),
                     "Possible Target ",
                     style=label.style_label_lower_left,
                     color=color.new(color.green, 70),
                     textcolor = color.white,
                     size=size.small))    
        else 
            if scr > MID 
                array.push(Lines,
                     line.new(sync + 3,
                     hl2[1],sync + 10,
                     array.get(Fibo,1),
                     color= color.rgb(255, 0, 0),
                     style = line.style_arrow_right,
                     width = 1))
                array.push(Labels,
                     label.new(sync + 10,
                     array.get(Fibo,1),
                     "Possible Target ",
                     style=label.style_label_lower_left,
                     color=color.new(#f37451, 70),
                     textcolor = color.white,
                     size=size.small))
 
            else if scr < MID
                array.push(Lines,
                     line.new(sync + 3,
                     hl2[1],sync + 10,
                     array.get(Fibo,3),
                     color= color.rgb(247, 0, 0),
                     style = line.style_arrow_right,
                     width = 1))
                array.push(Labels,
                     label.new(sync + 10,
                     array.get(Fibo,3),
                     "Possible Target ",
                     style=label.style_label_lower_left,
                     color=color.new(#f37451, 70),
                     textcolor = color.white,
                     size=size.small))
 
 
 
    if array.size(Lines) > 1
        line.delete(array.shift(Lines))
 
    if array.size(Labels) > 1
        label.delete(array.shift(Labels))
 
    if array.size(FiboBOX) > 6
        for i = 0 to 5
            box.delete(array.shift(FiboBOX))

← 返回列表