Firetron’s ReportOpenPositions

1 59 Views No Comments 4 weeks ago
  • Adds a custom report on your open positions.
    Includes a sum of all open position profits.

    Custom Command Dependencies:
    Firetron’s FormatRoundedQuoteCurrency

    • This topic was modified 3 weeks, 5 days ago by Team HaasScripts.
    • This topic was modified 3 days, 7 hours ago by Firetron. Reason: Added hyperlink to command
    HaasScript Code
    --  ==========================================================================================================
    --    Firetron's ReportOpenPositions
    --
    --    Adds a custom report on your open positions.
    --
    --    Custom Command Dependencies:
    --    Firetron’s FormatRoundedQuoteCurrency
    --
    --    Discord:  @FiretronP75
    --    BTC Tips: 14WLDZsrhshcP6qvBarKW8ABACv3iUXEro
    --    ETH Tips: 0xfaaac99fbf11f8f4abc4b3bf079cb2c7a43b5f87
    --  ==========================================================================================================
    
    --  ==============
    --    Definition
    --  ==============
    
    DefineCommand('ReportOpenPositions', 'Adds a custom report on your open positions.')
    
    --  ============
    --    Finalize
    --  ============
    
    Finalize(function()
    
      local group = 'Open Positions Report'
      local name  = 'Open Positions'
      local value = 'None'
      local sum   = 0
    
      local positionList = GetAllOpenPositions()
    
      --  --------
      --    None
      --  --------
    
      if Count(positionList) == 0 then
        CustomReport(name, value, group)
      end
    
      --  -------
      --    Sum
      --  -------
    
      for i = 1, #positionList do
    
        local positionContainer = positionList[i]
    
        sum = sum + positionContainer.profit
    
      end
    
      name  = 'Open Positions Sum'
      value = CC_FormatRoundedQuoteCurrency(sum)
      CustomReport(name, value, group)
    
      --  ----------
      --    Shorts
      --  ----------
    
      for i = 1, #positionList do
    
        local positionContainer = positionList[i]
    
        if positionContainer.isShort then
          name  = 'Open Short Position'
          value = CC_FormatRoundedQuoteCurrency(positionContainer.profit)
          CustomReport(name, value, group)
        end
    
      end
    
      --  ---------
      --    Longs
      --  ---------
    
      for i = 1, #positionList do
    
        local positionContainer = positionList[i]
    
        if positionContainer.isLong then
          name  = 'Open Long Position'
          value = CC_FormatRoundedQuoteCurrency(positionContainer.profit)
          CustomReport(name, value, group)
        end
    
      end
    
    end)
    
    --  ==========
    --    Output
    --  ==========
    
    DefineOutput(VoidType)
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free