[Kobalt updated sorted] Mad Hatter Indicators: MHB BBands v2
stableDescription
Input Menu Group format and order of elements.
-- Sorted Input Group items to match MadHatter, clean group format.
-- Added Interval per indicator
-- Optional description name, included in chart plot instead of script name.
-- introduced HSP(HighSpeedPrices) to see how that works..
-- (optional) Dependency
-- CC_HSP (HaasScriptPrices) fork of CC_HighSpeedPrices from the pshai
-- (both are arguably but still equally fast or slow..'at times'.;p)
https://www.haasscripts.com/t/kobalts-plunder-hsp-all-highspeedprices/
HaasScript
-- Author: kob
-- Define command
DefineCommand("MadHatterBBandsv2", "HSP Multi Time Frame able MadHatter BBands for MadHaasBots")
-- Sorted Input Group items to match MadHatter, clean group format.
-- Added Interval per indicator
-- Optional description name, included in chart plot instead of script name.
--========================================================================================================-
-- (optional) Dependency
-- CC_HSP (HaasScriptPrices) fork of CC_HighSpeedPrices from the pshai
-- (both are arguably equally fast or slow. depends on the time..)
--========================================================================================================-
-- Define command parameters.
local chartIndex = DefineParameter(NumberType, 'chartIndex', 'The index on which to chart', true, 0, 'Number')
local name = DefineParameter(StringType, 'name', 'Optional name/description of the indicator.', false, '', 'Text')
local interval = DefineParameter(NumberType, 'interval', 'interval for HSP price data. Default is 0 and the main interval will be used.', false, 0, 'Number,InputInterval')
DefineIntervalOptimization(interval)
-- Input fields for the indicator. Add the name in front.
--InputGroupHeader('MHB BBands '..name)
local interval = InputInterval(name..' BBands Interval', 1, 'HSP Multi Time Frame (if it is different than main interval) MadHatter BBands. Using HighSpeedPrices will give better results but may slow down the script', {group = "MHB BBands"})
local period = Input(name..' BBands Length', 20, {group = "MHB BBands"})
local devUp = Input(name..' BBands DevUp', 2, {group = "MHB BBands"})
local devDn = Input(name..' BBands DevDown', 2, {group = "MHB BBands"})
local maType = InputMaTypes(name..' BBands MA Type', 'sma', {group = "MHB BBands"})
local deviation = Input(name..' BBands Deviation', 0, {group = "MHB BBands"})
local requireFCC = Input(name..' Require FCC', false, {group = "MHB BBands"})
local resetMiddle = Input(name..' Reset Middle', false, {group = "MHB BBands"})
local allowMidSells = Input(name.. 'Allow Mid Sells', false, {group = "MHB BBands"})
-- Calculate the indicator
--HighSpeedPrices will give better more accurate results on higher timeframes, (not visable on plot)
-- but might slow down the script..
local hsp = CC_HSP(interval)
local o = hsp.open
local h = hsp.high
local l = hsp.low
local c = hsp.close
local cp = ClosePrices(interval)
local op = OpenPrices(interval)
local getinterval = CurrentInterval()
local prices
local open
if getinterval == interval then prices = cp else prices = c end
if getinterval == interval then open = op else open = c end
local bbandsData = BBANDS(prices, period, devUp, devDn, maType)
local upper = bbandsData[1]
local middle = bbandsData[2]
local lower = bbandsData[3]
PlotBBandsChart(chartIndex, name.. 'MHB BBands', upper, middle, lower)
--ChartSetOptions(chartIndex, name.. 'MHB BBands')
local wentAbove = Load('wentAbove', false)
local wentBelow = Load('wentBelow', false)
local result = SignalNone
if prices < lower then
wentBelow = true
if resetMiddle == false then
wentAbove = false
end
end
if prices > lower and wentBelow then
if requireFCC then
if open > lower then
result = SignalBuy
end
else
result = SignalBuy
end
if resetMiddle == false then
wentBelow = false
end
end
if resetMiddle and prices > middle and wentBelow then
wentBelow = false
end
if prices > upper then
if resetMiddle == false then
wentBelow = false
end
wentAbove = true
end
if prices < upper and wentAbove then
if requireFCC then
if open < upper then
result = SignalSell
end
else
result = SignalSell
end
if resetMiddle == false then
wentAbove = false
end
end
if resetMiddle and prices < middle and wentAbove then
wentAbove = false
end
if allowMidSells and prices > middle then
result = SignalSell
end
local finalSignal = SignalNone
if open < prices and result == SignalBuy then
finalSignal = SignalBuy
elseif result == SignalSell then
finalSignal = SignalSell
end
Save('wentAbove', wentAbove)
Save('wentBelow', wentBelow)
--Return the custom signal.
DefineOutput(EnumType, finalSignal, 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')
2 Comments
Sign in to leave a comment.
Please fix:
local hsp = CC_HSP(interval) -- wrong
local hsp = CC_HighSpeedPrices(interval) -- write
Is this not working?
https://www.haasscripts.com/t/kobalts-plunder-hsp-all-highspeedprices/