Strooths Trailing Enter (Roof-in/Floor-in)
stableDescription
This is for momentum or swing each way, kind of like a trailing stoploss or profit trailer, but does not require a position id so its great for opening new positions or when short term scalping/market making.
On longer timeframes like week/month it can VERY profitable if you know what you are doing and have enough capital to play.
Examples
CC_StroothsTrailingEnter(5, PositionLong)
local trailingenter = CC_StroothsTrailingEnter(2, PositionLong, BidPrices(), 50, CurrentInterval(), 10, positionId, true, false, 1, 0)
HaasScript
-- Author: find me on discord - strooth#4739
DefineCommand('StroothsTrailingEnter', '')
local pTrailPerc = DefineParameter(NumberType, 'TrailPerc', 'The percent to trail', true, 5, 'number')
local pDirection = DefineParameter(EnumType, 'Direction', 'The direction to trail', true, NoPosition, 'positionlong')
local pStartPrice = DefineParameter(NumberType, 'StartPrice', 'The price to start trailing from', false, CurrentPrice(), 'Currentprice()')
local pPeriod = DefineParameter(NumberType, 'Period', 'The Period', false, 5, '5')
local pInterval = DefineParameter(NumberType, 'Interval', 'The Interval', false, CurrentInterval(), 'CurrentInterval()')
local poffset = DefineParameter(NumberType, 'offset', 'The Offset', false, 1, '1')
local ptrailingId = DefineParameter(StringType, "trailingId", "Unique ID.", false, '1', "String" )
local pploten = DefineParameter(BooleanType, 'EnablePlot', 'Show Plot', false, true, 'false')
local ppen = DefineParameter(NumberType, 'Penetration', 'How far it must crossover', false, 1, '1')
local pchart = DefineParameter(NumberType, 'ChartIndex', 'Chart Index', false, 0, '1')
local name = Parse(pDirection, StringType)..ptrailingId
DefineIntervalOptimization(pInterval)
local output = false
local ptId = Load(name, NewGuid())
Save(name, ptId)
local tenter = function(TrailPerc,Direction,StartPrice,Period,Interval,offset,trailingId,ploten,penetration)
local hp = HighPrices(pInterval, false, PriceMarket(), true)
local lp = LowPrices(pInterval, false, PriceMarket(), true)
local perccmd, grow, shrink, cp
if Direction == PositionShort then
perccmd = AddPerc
grow = IsSmallerThan
shrink = IsBiggerThan
hp = SMA(HT_TRENDLINE(hp), Period)
cp = perccmd(lp,penetration)
elseif Direction == PositionLong then
perccmd = SubPerc
grow = IsBiggerThan
shrink = IsSmallerThan
lp = SMA(HT_TRENDLINE(lp), Period)
cp = perccmd(hp,penetration)
end
local plot = Load('plot'..trailingId, true )
local TrailPrice = Load('trailperc'..trailingId, perccmd(StartPrice, TrailPerc))
if TrailPrice == 'done' then
output = false
Save(name, NewGuid())
LogWarning('This Guid is complete, please generate a new one')
else
if shrink(cp, TrailPrice) then output = true
if shrink(perccmd(cp, TrailPerc), TrailPrice) then
TrailPrice = perccmd(cp, TrailPerc)
end
elseif grow(cp, TrailPrice) then
if grow(perccmd(cp, TrailPerc), TrailPrice) then
TrailPrice = perccmd(cp, TrailPerc)
end
output = false
end
TrailPrice = SourceManager(TrailPrice, Interval, Period)
TrailPrice = Offset(TrailPrice, offset)
if CrossOver(TrailPrice, cp) or CrossUnder(TrailPrice, cp) then
local text = 'Hit - '..TrailPerc..'% - '..Direction
if ploten then PlotShape(pchart, ShapeCross, White, 10, Direction == PositionShort and true or false, text, White); MarkCandle(0, 1) end
end
if plot == true then
if ploten then
local lops = LineOptions({color = Direction == PositionShort and ChangeColorOpacity(Purple,30) or ChangeColorOpacity(Olive,30), style=Step})
Plot(pchart, 'TrailingEnter'..Parse(Direction, StringType), TrailPrice, lops )
end
end
Save('trailperc'..trailingId, TrailPrice)
Save('plot'..trailingId, plot )
end
if output == true then
Save(name, NewGuid())
Save('trailperc'..trailingId, 'done')
Save('plot'..trailingId, false)
end
return output
end
if pDirection != NoPosition then
output = tenter(pTrailPerc,pDirection,pStartPrice,pPeriod,pInterval,poffset,ptId,pploten,ppen)
elseif pDirection == NoPosition then
local long, short
long = tenter(pTrailPerc,PositionLong,pStartPrice,pPeriod,pInterval,poffset,ptId..'long',pploten,ppen)
short = tenter(pTrailPerc,PositionShort,pStartPrice,pPeriod,pInterval,poffset,ptId..'short',pploten,ppen)
output = IfElseIf(IsTrue(long), IsTrue(short), long, short, false )
end
DefineOutput(BooleanType, output, "True if safety has triggered, otherwise false", "SafetyContainer, And, Or, IfElse, IfElseIf")
1 Comment
Sign in to leave a comment.
Kind of resonates with Impulse MACD by Lazy Bear. Excellent!