#/ This source code is subject to the terms of the Mozilla Public License 2.0
#// © tradeforopp
#indicator("Volume Spikes [TFO]", "Volume Spikes [TFO]", overlay=true)
# - Converted by Sam4Cok@Samer800 - 11/2023 - Request from UseThinkScript.com memeber
#// Variables and constants
input VolumeMultiplier = 1.5; # "Volume Multiplier"
input VolumeSmaLength = 100; # "Volume SMA Length"
input only_valid_hl = yes; # "Only Use Valid Highs & Lows"
input only_hammers_shooters = yes; # "Only Use Hammers & Shooters")
input UseSameCloseVolumeSpikes = no; # "Only Use Same-Close Volume Spikes"
input startTime = 0000; # "Session Time"
input EndTime = 2359; # "0000-0000", "Session Time"
def na = Double.NaN;
def t = SecondsFromTime(startTime) >=0 and SecondsTillTime(EndTime) >=0;
#// Candle calculations
def valid_high1 = if only_valid_hl then high[1] > high[2] and high[1] > high[0] else yes;
def valid_low1 = if only_valid_hl then low[1] < low[2] and low[1] < low[0] else yes;
def distance_hl = high - low;
def valid_hammer = open > low + distance_hl / 2 and close > low + distance_hl / 2;
def valid_shooter = open < low + distance_hl / 2 and close < low + distance_hl / 2;
def valid_high; def valid_low;
if only_hammers_shooters {
valid_high = valid_high1 and valid_shooter[1];
valid_low = valid_low1 and valid_hammer[1];
} else
if UseSameCloseVolumeSpikes {
valid_high = valid_high1 and close[1] < open[1];
valid_low = valid_low1 and close[1] > open[1];
} else {
valid_high = valid_high1;
valid_low = valid_low1;
}
#// Volume check
#// Is volume sufficiently greater than its MA?
def vol_check = volume > Average(volume, VolumeSmaLength) * VolumeMultiplier and t;
def result_bearish = valid_high and vol_check[1];
def result_bullish = valid_low and vol_check[1];
plot SpikeDn = if result_bearish[-1] then high else na;
plot SpikeUp = if result_bullish[-1] then low else na;
SpikeDn.SetLineWeight(2);
SpikeUp.SetLineWeight(2);
SpikeDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SpikeUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SpikeDn.SetDefaultColor(Color.MAGENTA);
SpikeUp.SetDefaultColor(Color.CYAN);
#-- END of CODE