Firetron's InputPriceSpread

stable
By Firetron in Miscellaneous Published December 2020 👁 1,147 views 💬 0 comments

Description

Creates a group of inputs for Firetron's GetPriceSpread. Custom Command Dependencies: None Test Script:
if not Load('done', false) then

  local p = {listDynamic = CC_InputPriceSpread('Price Spread')}

  local spreadPrices = CC_GetPriceSpread(p)

  for i = 1, #spreadPrices do

    Log('Spread Price: '..spreadPrices[i])

  end

  Save('done', true)

end
HaasScript
--  ============================================================================
--    Firetron's InputPriceSpread
--
--    Creates a group of inputs for Firetron's GetPriceSpread.
--
--    Custom Command Dependencies:
--    None
--
--    Discord: @FiretronP75
--  ============================================================================

--  ========================================================
--    Variables
--  ========================================================

--  ------------------------------------
--    Definition
--  ------------------------------------

local defaultValue
local description
local index
local inputSuggestions
local isRequired
local label
local name
local options
local output
local outputSuggestions
local tooltip
local type

--  ------------------------------------
--    Enumeration
--  ------------------------------------

local Direction = {
  above = 'above',
  below = 'below',
}

local SpreadType = {
  exp        = 'exp',
  fib        = 'fib',
  fibPercent = 'fibPercent',
  fixed      = 'fixed',
  percent    = 'percent',
}

--  ------------------------------------
--    Parameter
--  ------------------------------------

local pBasePrice
local pCount
local pDirection
local pGroup
local pOffset
local pSpreadFactor
local pSpreadType

--  ========================================================
--    Command Definition
--  ========================================================

name        = 'InputPriceSpread'
description = 'Creates a group of inputs for Firetron\'s GetPriceSpread.'
DefineCommand(name, description)

--  ========================================================
--    Parameter Definition
--  ========================================================

type             = StringType
name             = 'group'
description      = 'The group of the input fields.'
isRequired       = false
defaultValue     = 'Price Spread'
inputSuggestions = 'Text'
pGroup           = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)

--  ========================================================
--    Input Definitions
--  ========================================================

label        = 'Base Price'
defaultValue = 1
tooltip      = 'Price to spread out from. This price will not be included. The first price will be placed at the spread factor away from this price.'
pBasePrice   = Input(label, defaultValue, tooltip, pGroup)

label        = 'Count'
defaultValue = 1
tooltip      = 'How many prices are in the spread.'
pCount       = Input(label, defaultValue, tooltip, pGroup)

label        = 'Direction'
defaultValue = Direction.below
options      = Direction
tooltip      = '"above" will spread prices above the base price, "below" will spread prices below the base price.'
pDirection   = InputOptions(label, defaultValue, options, tooltip, pGroup)

label         = 'Offset'
defaultValue  = 0
tooltip       = 'How many prices to skip over at the start of the spread.'
pOffset       = Input(label, defaultValue, tooltip, pGroup)

label         = 'Spread Factor'
defaultValue  = 1
tooltip       = 'How far to space prices apart. May be an exponential, fibonacci, fibonacci percent, fixed, or percent value.'
pSpreadFactor = Input(label, defaultValue, tooltip, pGroup)

label        = 'Spread Type'
defaultValue = SpreadType.fixed
options      = SpreadType
tooltip      = '"exp" if you specified an exponential spread, "fib" if you specified a fibonacci spread, "fibPercent" if you specified a fibonacci percent spread, "fixed" if you specified a fixed spread, "percent" if you specified a percent spread.'
pSpreadType  = InputOptions(label, defaultValue, options, tooltip, pGroup)

--  ========================================================
--    Output Definitions
--  ========================================================

output = {
  basePrice    = pBasePrice,
  count        = pCount,
  direction    = pDirection,
  offset       = pOffset,
  spreadFactor = pSpreadFactor,
  spreadType   = pSpreadType,
}

type              = ListDynamicType
description       = 'ListDynamic with named elements.'
outputSuggestions = 'CC_GetPriceSpread'
DefineOutput(type, output, description, outputSuggestions)

index       = 1
type        = NumberType
name        = 'basePrice'
description = 'Price to spread out from. This price will not be included. The first price will be placed at the spread factor away from this price.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

index       = 2
type        = NumberType
name        = 'count'
description = 'How many prices are in the spread.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

index       = 3
type        = StringType
name        = 'direction'
description = '"above" will spread prices above the base price, "below" will spread prices below the base price.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

index       = 4
type        = NumberType
name        = 'offset'
description = 'How many prices to skip over at the start of the spread.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

index       = 5
type        = NumberType
name        = 'spreadFactor'
description = 'How far to space prices apart. May be an exponential, fibonacci, fibonacci percent, fixed, or percent value.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

index       = 6
type        = StringType
name        = 'spreadType'
description = '"exp" if you specified an exponential spread, "fib" if you specified a fibonacci spread, "fibPercent" if you specified a fibonacci percent spread, "fixed" if you specified a fixed spread, "percent" if you specified a percent spread.'
DefineOutputIndex(index, type, name, description, outputSuggestions)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!