Strooths Find Candle Indicator (by input list)
stableDescription
For the main description see the original indicator
Strooths Candle Indicator
This one is modified so you can feed it a list as required in your strategy rather then the standard lists I defined.
to use
local bearish = {BreakawayType, BeltHoldType, ThreeBlackCrowsType}
local bullish = {MorningStarType, ThreeWhiteSoldiersType, MarubozuType}
local signal = CC_StroothsFindCDL(bearish, bullish)
to fine tune a little more
local bearish = {BreakawayType, BeltHoldType, ThreeBlackCrowsType}
local bullish = {MorningStarType, ThreeWhiteSoldiersType, MarubozuType}
local cp = CurrentPrice()
local signal = CC_StroothsFindCDL(bearish, bullish, 1 CurrentInterval(), {cp.open, cp.high, cp.low, cp.close}, 3, 3, 4, true, false, false)
HaasScript
-- author - Find me on discord - strooth#4739
-- Define command
DefineCommand("StroothsFindCDL", "Custom Find CDL Pattern and signal ")
-- Define command parameters.
local bearishlist = DefineParameter(ListDynamicType, 'Bearish List', 'The Array/List of candles to pattern check for bearish signal', true, {BreakawayType, EngulfingType, ThreeOutsideType}, 'Array/ListDynamicType - {BreakawayType, EngulfingType, ThreeOutsideType}')
local bullishlist = DefineParameter(ListDynamicType, 'Bullish List', 'The Array/List of candles to pattern check for bullish signal', true, {AbandonedBabyType, BeltHoldType, ThreeOutsideType}, 'Array/ListDynamicType - {AbandonedBabyType, BeltHoldType, ThreeOutsideType}')
local penetration = DefineParameter(NumberType, 'penetration', 'the penetration level before pattern is vaalid', false, 1, 'Number,InputInterval')
local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', false, 0, 'Number,InputInterval')
local source = DefineParameter(ListDynamicType, 'source', 'Price Source {OpenPrices(),HighPrices(),LowPrices(),ClosePrices()}.', false, {OpenPrices(interval),HighPrices(interval),LowPrices(interval),ClosePrices(interval)}, '{OpenPrices(),HighPrices(),LowPrices(),ClosePrices()}')
local shortweight = DefineParameter(NumberType, 'shortweight', 'the consensus weight threshold of each signal.', false, 3, 'Number,InputInterval')
local longweight = DefineParameter(NumberType, 'longweight', 'the consensus weight threshold of each signal.', false, 3, 'Number,InputInterval')
local noneweight = DefineParameter(NumberType, 'noneweight', 'the consensus weight threshold of each signal.', false, 4, 'Number,InputInterval')
local plotall = DefineParameter(BooleanType, 'plotall', 'plot and mark each signal', false, false, 'true,false')
local plotfinal = DefineParameter(BooleanType, 'plotfinal', 'plot and mark only the final signal', false, false, 'true,false')
local log = DefineParameter(BooleanType, 'log', 'log each signal', false, false, 'true,false')
DefineIntervalOptimization(interval)
-- Variables
local stally,ltally,text = {},{}
local op,hp,lp,clp=source[1],source[2],source[3],source[4],source[5]
local signal,bearishsignal,bullishsignal = SignalNone,SignalNone,SignalNone
-- Calculate direction
local sum = function(i, o, l)
local output = ArraySum(Grab(i, o, l))
if IsSmallerThan(output, 0) then
output = output * -1
end
output = output / 100
if output == l then return true else return false end
end
-- Check for patterns function
local check = function(patterns, interval, bearish, bullish)
local output
local lindex = 0
local sindex = 0
local sp
local both = false
if bullish and bearish then
both = true
end
for i=1, #patterns do
local result = CDL(op, hp, lp, clp, patterns[i], penetration)
result = Grab(result, 1, 1)
result = Parse(result, NumberType)
if IsNotNull(result) and IsSmallerThan(result, 0) then
if both or bearish then
sindex = sindex + 1
stally[sindex] = result
if plotall then
local text = Parse(patterns[i], StringType)
PlotShape(0, ShapeTriangleDown, Red, 10, true, text, White)
MarkCandle(0, 1)
end
end
end
if IsNotNull(result) and IsBiggerThan(result, 0) then
if both or bullish then
lindex = lindex + 1
ltally[lindex] = result
if plotall then
local text = Parse(patterns[i], StringType)
PlotShape(0, ShapeTriangleUp, Green, 10, false, text, White)
MarkCandle(0, 1)
end
end
end
end
if both or bearish then
if IsNotNull(ArraySum(stally)) then
sp = ArraySum(stally) * -1
end
end
if both then
if IsNotNull(sp) and IsNotNull(ArraySum(ltally)) then
if IsBiggerThan(sp, ArraySum(ltally)) then
local weight = sp
output = SignalWeight(SignalShort, weight)
end
if IsBiggerThan(ArraySum(ltally), sp) then
local weight = ArraySum(ltally) / 100
output = SignalWeight(SignalLong, weight)
end
end
elseif bullish then
if IsNotNull(ArraySum(ltally)) then
if IsBiggerThan(ArraySum(ltally), 1) then
local weight = ArraySum(ltally)
output = SignalWeight(SignalLong, weight)
end
end
elseif bearish then
if IsNotNull(ArraySum(stally)) then
if IsSmallerThan(ArraySum(stally), 0) then
local weight = sp
output = SignalWeight(SignalShort, weight)
end
end
else
output = SignalWeight(SignalNone, 1)
end
if IsNull(output) then output = SignalWeight(SignalNone, 1) end
return output
end
-- Run pattern checks and generate signals
bearishsignal = SignalWeight(GetWeightedConsensusSignal(8,8,8, check(bearishlist, interval, true, false)), 3)
bullishsignal = SignalWeight(GetWeightedConsensusSignal(8,8,8, check(bullishlist, interval, false, true)), 3)
-- log signals
if log then
local allsignals = {Bearish = bearishsignal, Bullish = bullishsignal}
for type,sig in pairs(allsignals) do
if sig != SignalNone then
LogWarning(type..' = '..Parse(sig, StringType))
end
end
end
-- get final signal
signal = GetWeightedConsensusSignal(longweight,shortweight,noneweight, bearishsignal,bullishsignal)
-- plot final signal
if plotfinal then
if signal != SignalNone then
local p = IfElse(signal==SignalLong,{shape=ShapeTriangleUp,color=Green,ab=false,text='GoLong'},{shape=ShapeTriangleDown,color=Red,ab= true,text='GoShort'})
PlotShape(0, p.shape, p.color, 5, p.ab, p.text, White)
MarkCandle(0, 1)
end
end
-- log final signal
if log then
if signal != SignalNone then
local weights = {LongWeight = longweight, ShortWeight = shortweight, NoneWeight = noneweight}
for type,weight in pairs(weights) do
LogWarning(type..' = '..weight)
end
LogWarning('Final Weighted Signal = '..Parse(signal, StringType))
end
end
-- Create output
local output = {}
output.Signal = signal
output.Bearish = bearishsignal
output.Bullish = bullishsignal
--Return the custom signal.
DefineOutput(ListDynamicType, output , 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')
DefineOutputIndex(1, EnumType, 'Signal', 'main signal', 'signallong,signalshort')
DefineOutputIndex(2, EnumType, 'Bearish', 'Bearish', 'signallong,signalshort')
DefineOutputIndex(3, EnumType, 'Bullish', 'Bullish', 'signallong,signalshort')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!