Discussion about this post

User's avatar
Cagan Tunc's avatar

Kodun "Projected Volume" için revize edilmiş hali aşağıdadır. Son dönemde ben bu versiyonu kullanmaya başladım.

//@version=5

indicator("Volume Comparison - Projected Volume-REV01", overlay=false)

// User-configurable inputs

length = input.int(50, "Moving Average Period", minval=1, tooltip="Period for calculating the average volume")

multiplier = input.float(2.0, "Volume Multiplier", minval=0.1, step=0.1, tooltip="Multiplier for comparing volume to average volume")

// Calculate projected volume for the current bar

time_period = ((time_close - time) / 1000)

time_passed = ((timenow - time) / 1000)

time_left = ((time_close - timenow) / 1000)

volume_per_second = 0.0

raw_volume_projected = float(volume) // Keep original projected volume

display_volume_projected = float(volume) // For display with unit conversion

uP = ''

if time_left > 0

volume_per_second := time_passed > 0 ? (volume / time_passed) : 0 // Prevent division by zero

raw_volume_projected := (volume + (volume_per_second * time_left))

display_volume_projected := raw_volume_projected

if display_volume_projected >= 1000 and display_volume_projected < 1000000

display_volume_projected := display_volume_projected / 1000

uP := 'K'

else if display_volume_projected >= 1000000 and display_volume_projected < 1000000000

display_volume_projected := display_volume_projected / 1000000

uP := 'M'

else if display_volume_projected >= 1000000000

display_volume_projected := display_volume_projected / 1000000000

uP := 'B'

// Calculate average volume based on actual volume

avg_volume = ta.sma(volume, length)

// Calculate threshold with unit conversion for display

threshold = avg_volume * multiplier

display_threshold = threshold

uT = ''

if threshold >= 1000 and threshold < 1000000

display_threshold := threshold / 1000

uT := 'K'

else if threshold >= 1000000 and threshold < 1000000000

display_threshold := threshold / 1000000

uT := 'M'

else if threshold >= 1000000000

display_threshold := threshold / 1000000000

uT := 'B'

// Comparison: Use raw (unscaled) projected volume

is_high_volume = raw_volume_projected >= avg_volume * multiplier

// Label results

label.new(bar_index, display_volume_projected, is_high_volume ? "True" : "False",

color=is_high_volume ? color.green : color.red,

style=label.style_label_down,

textcolor=color.white)

// Display results in a table

var table t = table.new(position.top_right, 2, 3, border_width=1)

if barstate.islast

table.cell(t, 0, 0, "Projected Volume", bgcolor=color.gray, text_color=color.white)

table.cell(t, 1, 0, str.tostring(display_volume_projected) + uP, bgcolor=color.gray, text_color=color.white)

table.cell(t, 0, 1, "Threshold (Avg Vol * Mult)", bgcolor=color.orange, text_color=color.white)

table.cell(t, 1, 1, str.tostring(display_threshold) + uT, bgcolor=color.orange, text_color=color.white)

table.cell(t, 0, 2, "Condition", bgcolor=is_high_volume ? color.green : color.red, text_color=color.white)

table.cell(t, 1, 2, is_high_volume ? "True" : "False", bgcolor=is_high_volume ? color.green : color.red, text_color=color.white)

// Alarm conditions

alertcondition(is_high_volume, title="Projected Volume High", message="Projected volume is at least {{multiplier}}x the average volume")

alertcondition(not is_high_volume, title="Projected Volume Low", message="Projected volume is below {{multiplier}}x the average volume")

Expand full comment
burak's avatar

Mismatched input 'volume_per_second' expecting 'end of line without line continuation' hatasını ben de alıyorum.

Expand full comment
8 more comments...

No posts