Firetron's ReportOpenPositions
stableDescription
Adds a custom report on your open positions.
Includes a sum of all open position profits.
Custom Command Dependencies:
Firetron’s FormatRoundedQuoteCurrency
HaasScript
-- ============================================================================
-- Firetron's ReportOpenPositions
--
-- Adds a custom report on your open positions.
--
-- Custom Command Dependencies:
-- CC_FormatRoundedQuoteCurrency
--
-- Discord: @FiretronP75
-- ============================================================================
-- ========================================================
-- Variables
-- ========================================================
local description
-- ========================================================
-- Command Definition
-- ========================================================
description = 'Adds a custom report on your open positions.'
DefineCommand('ReportOpenPositions', description)
-- ========================================================
-- Functions
-- ========================================================
local ReportList = function (list, group)
for i = 1, #list do
local element = list[i]
CustomReport(element.name, element.value, group)
end
end
-- ----------------
local Report = function ()
local group = 'Open Positions Report'
local name = ''
local value = ''
local positionList = GetAllOpenPositions()
if Count(positionList) == 0 then
-- Report None
name = 'Open Positions'
value = 'None'
CustomReport(name, value, group)
return
end
-- Parse Positions
local longIndex = 0
local longList = {}
local shortIndex = 0
local shortList = {}
local sum = 0
for i = 1, #positionList do
local positionContainer = positionList[i]
sum = sum + positionContainer.profit
if positionContainer.isLong then
longIndex = longIndex + 1
local element = {
name = 'Long Open Position '..longIndex,
value = CC_FormatRoundedQuoteCurrency(positionContainer.profit),
}
longList[longIndex] = element
else
shortIndex = shortIndex + 1
local element = {
name = 'Short Open Position '..shortIndex,
value = CC_FormatRoundedQuoteCurrency(positionContainer.profit),
}
shortList[shortIndex] = element
end
end
-- Report Sum
name = 'Open Positions Sum'
value = CC_FormatRoundedQuoteCurrency(sum)
CustomReport(name, value, group)
-- Report Positions
ReportList(shortList, group)
ReportList(longList, group)
end
-- ========================================================
-- Execution
-- ========================================================
Finalize(function ()
Report()
end)
-- ========================================================
-- Output Definitions
-- ========================================================
DefineOutput(VoidType)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!