EasyTSIv2K0b: True Strength Index enhanced.. 2 extra 'extreme' buy sell levels, plots etc.

stable
By Kobalt in Oscillators Published July 2021 👁 1,220 views 💬 0 comments

Description

--v2Kob/; Specified Input Group, added InputInterval -- ordered items. -- fixed / replaced PlotLineBuySellzone, -- Added 2 extra buy sell levels.... Ideal for triggering second buys or bigger spread, amounts in an SMM?
HaasScript
-- Source: https://www.tradingview.com/script/UQjj3yax-Indicator-True-Strength-Index/

-- Define command
DefineCommand('EasyTSIv2i', 'True Strength Index 2 buy sell levels, fixed plots et..')
--v2: Specified Input Group, added InputInterval and ordered items. -Other Settings- No more!
-- Define command parameters.
local chartIndex = DefineParameter(NumberType, 'chartIndex', 'The index on which to chart', true, 1, 'Number')
local name = DefineParameter(StringType, 'name', 'Unique name of the indicator.', false, '', 'Text')
local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', false, 0, 'Number,InputInterval')

DefineIntervalOptimization(interval)

-- Input fields TIP: 
-- You can use spacing as invisible prefix to order your Input fields without adding visible characters..
-- Spacing goes above  AAA, 000, but also won't move the first '        Word in a string to the right..! 
-- So a nice clean little trick to order your Input Group fields in a non alphabetical order you like.
-- You can start with the thing you want on top and add enough spacing to not have to work from the bottom up.....

--Here 'Interval' has 3 spaces, 'Smoothing fields 1 and 2' use 2 spaces and Sell Level has one space to get displayed above Buy Level. 
local interval = InputInterval("    Interval", 0, {group = "TSI Settings"}) 
local smoothing1 = Input('Smoothing 1', 6, {group = "TSI Settings"}) 
local smoothing2 = Input('Smoothing 2', 12, {group = "TSI Settings"})
local sellLevel2 = Input('  Sell Level 2', 50, {group = "TSI Settings"}) 
local sellLevel1 = Input(' Sell Level 1', 25, {group = "TSI Settings"}) 
local buyLevel1 = Input('Buy Level 1', -25, {group = "TSI Settings"}) 
local buyLevel2 = Input('Buy Level 2', -50, {group = "TSI Settings"}) 
-- Don't forget to specify a group name for your commands InputFields! Easiest way {group = "TSI Settings"}) 
-- Or it will go to 'Other Settings' in your Haasbot showing several of the same unspecified common input fields..



-- Calculate the indicator
local prices = ClosePrices(interval)

-- Calculation
local change = Change(prices)

local ema1 = EMA(EMA(change, smoothing1),smoothing2)
local ema2 = EMA(EMA(Abs(change), smoothing1), smoothing2)
local tsi = Mul(Div(ema1, ema2),100)

-- Determine the signal.
local signal = SignalNone

if (tsi < buyLevel1) then
    signal = SignalLong ---mm still bit getting used to but the outer level 2 could signal a double up buy if tsi<buylevel2 SignalA B??)
elseif (tsi > sellLevel1) then -- or use them as spread low, spread high trigger in an SMM
    signal = SignalShort
end
OvercomeDoubleFeeCosts()
-- Plot the indicator Use the chartIndex parameter.
Plot(chartIndex, 'TSI', tsi, Orange)
PlotHorizontalLine(chartIndex, 'centre line', DarkGray(88), 0, Dashed) 
PlotHorizontalLine(chartIndex, 'buyLevel 2', Green, buyLevel2) 
PlotHorizontalZone(chartIndex, '2', Olive(12), buyLevel2, buyLevel1)
PlotHorizontalLine(chartIndex, 'buyLevel 1', Green(40), buyLevel1) 
PlotHorizontalZone(chartIndex, '', DarkGray(11), buyLevel1, sellLevel1) 
PlotHorizontalLine(chartIndex, 'sellLevel 1', Red(66), sellLevel1)
PlotHorizontalZone(chartIndex, '2', Purple(33), sellLevel1, sellLevel2 ) 
PlotHorizontalLine(chartIndex, 'sellLevel 2', Red, sellLevel2)

--ChartSetAxisOptions(chartIndex, RightAxis,-100, 100)
ChartSetOptions(chartIndex, 'TSI')


DoSignal(signal)
--Return the custom signal.
DefineOutput(EnumType, signal, 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!