Get Throttled Templated

alpha
By Kobalt in Miscellaneous Published August 2022 👁 1,133 views 💬 0 comments

Description

Pshai's Get Throttled in Firetron's command template. Added index keys for things to make your charting life easier. very much still in development feel free to modify or share. Test script: EnableHighSpeedUpdates(true) InputGroupHeader('pnl: plots & logs') local isLogging = Input("isLogging", false, "logs?", "") local isVerbose = Input("isVerbose Logging", false, "verbose logs?", "") local isPlotting = Input("plot", true, "disable or enable plots", "") InputGroupHeader('Order Throttler') local min_timeout = Input('Min. Timeout', 10, 'Minimum timeout between orders placed (per slot, individually).') local max_timeout = Input('Max. Timeout', 100, 'Maximum timeout between orders placed (per slot, individually).') local min_change = Input('Min. Change', 0.2, 'Minimum change in price, represents the point where minimum timeout is used.') local max_change = Input('Max. Change', 2, 'Maximum change in price, represents the point where maximum timeout is used.') local lookback = Input('Lookback', 26, 'Depth / The amount of lookback for the timeout values. If depth is 10, the highest timeout value will last for 10 candles.') local plotIndex = 69 --test different index local plotIndexHight = 0.369 -- check if hight gets through v ----Uncomment this 'blank string' to see index, Title, index height... local plotIndexTitle = 'This index has been intentionally left blank..' Plot (-6, 'yourSpace', 0, Gold)-- ChartSetOptions(-6, 'YOUR AD HERE? donate 0800-Kobalt TODAY! BTC: bc1qz6gw8hje2scfq4wfmgtlfe9h4tgm7u8qzwev29', 0.1) local hsp = CC_HighSpeedPrices(1) local res = CC_GetTemplatedThrottledTimeout(min_timeout, max_timeout, min_change, max_change, lookback, hsp.high - hsp.low, plotIndex, plotIndexHight, plotIndexTitle) --CC_GetThrottledTimeout
HaasScript
-- Author: Kobalt_#7977_BTC_bc1qz6gw8hje2scfq4wfmgtlfe9h4tgm7u8qzwev29
--  ============================================================================
--    Name
--
--    Description.
--
--    Custom Command Dependencies:
--    Dependency 1
--    Dependency 2
--    Dependency 3
--    Kobalt    published 2022 for HaasScripts.com
--    Discord:  @Kobalt#7977
--    Consider leaving me a TIP if my work has helped you in any way:
--    BTC:      bc1qz6gw8hje2scfq4wfmgtlfe9h4tgm7u8qzwev29
--  ============================================================================
 
--  ========================================================
--    Variables
--  ========================================================
 
--  ------------------------------------
--    Definition
--  ------------------------------------
 
local description
local inputSuggestions
local output
local outputSuggestions
 
--  ------------------------------------
--    Parameter
--  ------------------------------------
 
--    Basic
 
local pOne
 
--    Logging
 
local pIsLogging
local pLogColor
local pIsPlotting
local pPlotIndex
local pPlotIndexTitle
local pPlotIndexHight
local pChartOptions 
local pIsReporting
local pIsVerbose
local pLoggingName

--  ------------------------------------
--    Reference
--  ------------------------------------
 
local value
 
--  ========================================================
--    Command Definition
--  ========================================================
 
description = 'Calculates and returns a price change based result that can be used as direct input for unmanaged order timeouts. The result table is a linear curve controlled by min and max timeout and price change values.'
DefineCommand('GetTemplatedThrottledTimeout', description)
 
--  ========================================================
--    Parameter Definition
--  ========================================================
 
--  ------------------------------------
--    Main
--  ------------------------------------
 -- dump this in here for now
local min_timeout = DefineParameter(NumberType, 'min_timeout', 'The minimum desired timeout in seconds. The result wont go below this value.', true, 60, 'Number, Input')
local max_timeout = DefineParameter(NumberType, 'max_timeout', 'The maximum desired timeout in seconds. The result wont go above this value.', true, 600, 'Number, Input')
local min_pc = DefineParameter(NumberType, 'min_pc', 'The minimum price change required to start calculating. Price change below and at this value produces a result of min_timeout.  This is where the linear line starts.', true, 0.2, 'Number, Input')
local max_pc = DefineParameter(NumberType, 'max_pc', 'The maximum price change, the other end of the curve. Price change at and above this value produces a result of max_timeout. This is where the linear line ends.', true, 0.3, 'Number, Input')
local depth = DefineParameter(NumberType, 'depth', 'The amount of lookback for the timeout values. If depth is 10, the highest timeout value will last for 10 candles.', false, 5, 'Number, Input')
local source = DefineParameter(ListNumberType, 'source', 'The source values to base the price changes on.', false, ClosePrices(), '')
--v local isPlotting = DefineParameter(BooleanType, "plotting", "Turn plotting on or off.", false, false, "" )
--v local pIndex = DefineParameter(BooleanType, "plotting", "Turn plotting on or off.", false, false, "" )

description      = 'chart id: The index to use for plotting.'
inputSuggestions = 'Number'
pPlotIndex      = DefineParameter(NumberType, 'plotIndex', description, false, 99, inputSuggestions)

description      = 'Chart index height. Use something like 0.2 on Oscillators, Exposure, the more plots next to 0 the lower you allocate to keep your PriceChart from getting sandwithed. Below 1 will be treated as percentage (0.5-50%)..'
inputSuggestions = 'Number, between 0.15-0.2 for indexes below or above the main index 0'
pPlotIndexHight  = DefineParameter(NumberType, 'plotIndexHight', description, false, 0.2, inputSuggestions)

description      = 'Plot Index Title: Naeme to set (instead of script name) To get a nice clean view of all your plots.'
inputSuggestions = 'Text'
pPlotIndexTitle  = DefineParameter(StringType, 'plotIndexTitle', description, false, 'index:' ..Parse(pPlotIndex, StringType).. '  gThrottled (h=' ..Parse(pPlotIndexHight*100, StringType)..' %)', inputSuggestions)

--  ------------------------------------
--    Logging
--  ------------------------------------
 
description      = 'Turns console logging on or off.'
inputSuggestions = 'Input'
pIsLogging       = DefineParameter(BooleanType, 'isLogging', description, false, true, inputSuggestions)

description      = 'logColor.'
inputSuggestions = 'ColorEnums'
pLogColor       = DefineParameter(EnumType, 'logColor', description, false, Teal, inputSuggestions)
 
description      = 'Turns chart plotting on or off.'
inputSuggestions = 'Input'
pIsPlotting      = DefineParameter(BooleanType, 'isPlotting', description, false, true, inputSuggestions)

description      = 'Turns custom report of current state on or off.'
inputSuggestions = 'Input'
pIsReporting     = DefineParameter(BooleanType, 'isReporting', description, false, true, inputSuggestions)
 
description      = 'Turns verbose console logging on or off. Ignored if logging is turned off.'
inputSuggestions = 'Input'
pIsVerbose       = DefineParameter(BooleanType, 'isVerbose', description, false, false, inputSuggestions)
 
description      = 'Name to use in logging to distinguish it from the other instances of this command.'
inputSuggestions = 'Text'
pLoggingName     = DefineParameter(StringType, 'loggingName', description, false, 'WickReversal', inputSuggestions)
 
--  ========================================================
--    Functions
--  ========================================================
 
--  ------------------------------------
--    Function Category
--  ------------------------------------
 
local FunctionA = function ()
 
  return 0
 
end
 
--  ----------------
 
local FunctionB = function ()
 
  return 1
 
end
 
--  ------------------------------------
--    Logging
--  ------------------------------------
 
local SafeLog = function (text)
 
  if text == Load('lastLog', '') then return end
 
  Log(text, logColor)
  Save('lastLog', text)
 
end
 
--  ----------------
 
local LogWithName = function (message)
 
  SafeLog(pLoggingName..': '..message)
 
end
 
--  ----------------
 
local LogSomething = function ()
 
  if not pIsLogging then return end
 
  LogWithName(pOne)
 
end
 
--  ----------------
 
local LogSomethingVerbose = function ()
 
  if not pIsLogging then return end
 
  if not pIsVerbose then return end
 
  LogWithName(pOne)
 
end
 
--  ------------------------------------
--    Plotting
--  ------------------------------------
if pPlotIndex == 0 then
pPlotIndexHight = 0
end
local PlotSomething = function ()
 
  if not pIsPlotting then return end
 
end
ChartSetOptions(pPlotIndex, pPlotIndexTitle, pPlotIndexHight)

 ----
 
local timeout_l_h = min_timeout
local timeout_s_l = max_timeout
 
if #source > 0 then
    local prev_time = Load('prev_time', Time())
    local price_ch = (source[1] - source[2]) / source[2] * 100
    
    local pc_size = price_ch
    local pc_size_l = Abs(ArrayFilter(pc_size, 0, ArrayFilterLessThanType))
    local pc_size_s = ArrayFilter(pc_size, 0, ArrayFilterGreaterThanType)
 
    local newArr =
        function(count, num)
            local ret = {}
            for i = 1, count do 
                ret[i] = num
            end
            return ret
        end
 
    local zeros = newArr(50, 0)
    local ones = newArr(50, 1)
 
    local timeout_l = min_timeout + Min(ones, Max(zeros, (pc_size_l - min_pc) / (max_pc - min_pc))) * (max_timeout - min_timeout)
    local timeout_s = min_timeout + Min(ones, Max(zeros, (pc_size_s - min_pc) / (max_pc - min_pc))) * (max_timeout - min_timeout)
    local timeout_l_ma = 0
    local timeout_s_ma = 0
 
    if #timeout_l > 0 then
        timeout_l_ma = DEMA(timeout_l, 13)
    end
 
    if #timeout_s > 0 then
        timeout_s_ma = DEMA(timeout_s, 13)
    end
    
 
    local raw_high = GetHigh(timeout_l, depth)
    local smooth_high = GetHigh(timeout_l_ma, depth)
    local raw_low = GetHigh(timeout_s, depth)
    local smooth_low = GetHigh(timeout_s_ma, depth)
 
    if smooth_high > raw_high then
        timeout_l_h = smooth_high
    else
        timeout_l_h = raw_high
    end
 
    if smooth_low > raw_low then
        timeout_s_l = smooth_low
    else
        timeout_s_l = raw_low
    end
    if pIsPlotting then
    Plot(pPlotIndex, 'timeout_l_h', timeout_l_h, Green)
    Plot(pPlotIndex, 'trix_l', timeout_l_ma, Green(60))
    Plot(pPlotIndex, 'timeout_l', timeout_l, Green(30))
    PlotHorizontalLine(pPlotIndex, 'min_l', Gray, min_timeout, Dashed)
    PlotHorizontalLine(pPlotIndex, 'max_l', Gray, max_timeout, Dashed)
    Plot(pPlotIndex, 'timeout_s_l', -timeout_s_l, Red)
    Plot(pPlotIndex, 'trix_s', -timeout_s_ma, Red(60))
    Plot(pPlotIndex, 'timeout_s', -timeout_s, Red(30))
    PlotHorizontalLine(pPlotIndex, 'min_s', Gray, -min_timeout, Dashed)
    PlotHorizontalLine(pPlotIndex, 'max_s', Gray, -max_timeout, Dashed)
  --v  ChartSetOptions(pPlotIndex, 'Throttled Timeout', 0.12) --This fixes screen real estate
    end
end
 

--  ------------------------------------
--    Reporting
--  ------------------------------------
 
local ReportSomething = function ()
 
  if not pIsReporting then return end
 
  local group = pLoggingName
  local name
  local value
 
  name  = ''
  value = pOne
  CustomReport(name, value, group)
 
  name  = ''
  value = pOne
  CustomReport(name, value, group)
 
end
 
--  ========================================================
--    Execution
--  ========================================================
 
output = pOne
 
--  ========================================================
--    Output Definitions
--  ========================================================
 
description       = ''
outputSuggestions = ''
DefineOutput(ListDynamicType, {timeout_buy = timeout_l_h, timeout_sell = timeout_s_l}, 'An array containing timeouts for buy and sell side.', 'ArrayGet')
DefineOutputIndex(1, NumberType, 'timeout_buy', 'Timeout seconds as a number, used to throttle buy side orders.')  
DefineOutputIndex(2, NumberType, 'timeout_sell', 'Timeout seconds as a number, used to throttle sell side orders.')

--DefineOutput(NumberType, output, description, outputSuggestions)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!