[pshaiCmd] Input Converted Trade Amount
stableDescription
A simple but yet handy custom command to input and convert trade amounts based on settings.
Update: Added optional market input
HaasScript
-- Author: pshai
DefineCommand('InputConvertedTradeAmount', 'Conversion command for trade amounts. Uses current close price.')
local name = DefineParameter(StringType, 'name', 'Optional name when used multiple times.', false, '', 'Text')
local market = DefineParameter(StringType, 'market', 'Optional market when used multiple times.', false, PriceMarket(), 'PriceMarket, InputMarket, InputAccountMarket')
local conversionTypes = {
'None (bypass)',
'Base to Quote',
'Quote to Base'
}
local coin = BaseCurrency(market)
InputGroupHeader('InputTradeAmount' .. (name != '' and (' - ' .. name) or ''))
local amt = Input('1. Amount', 1, 'Amount to be converted')
local ctype = InputOptions('2. Conversion Type', conversionTypes[3], conversionTypes)
local result = amt
local cc = CurrentPrice(market).close
if ctype == conversionTypes[2] then
-- base to quote
result = amt * cc
elseif ctype == conversionTypes[3] then
-- quote to base
result = amt / cc
end
DefineOutput(NumberType, result, 'The converted trade amount', 'PlaceBuyOrder, PlaceSellOrder, PlaceGoLongOrder, PlaceGoShortOrder')
2 Comments
Sign in to leave a comment.
Note that this is a simple, spot market type of conversion. It does not account for leverage, or contract value, on a leveraged market. You still need to do your own math on that after.
True dat. What i have done with this, is simply multiply the returned value with the used leverage, to get it represent the margin i want to invest on leverage markets.