[Strvinmarvin] (Snippet) Report lowest open position ROI's

stable
By Strvinmarvin in Miscellaneous Published December 2021 👁 1,327 views 💬 0 comments

Description

This snippet checks for open positions and reports the lowest 'x' number of them in a Custom Report. Useful for Dashboard reporting and Backtesting, especially with multiple markets or positions running in a single bot.
HaasScript
Finalize(function()   

    open_positions = GetAllOpenPositions()

    --Get Unrealized gains total for report
    open_value = 0
    --Get lowest open ROI %
    lowest_roi_list = {}
    lowest_roi_string = ''

    if Count(open_positions) > 0 then
        for i = 1, Count(open_positions) do
            open_value = open_value + open_positions[i].profit
            lowest_roi_list = ArrayAdd(lowest_roi_list, open_positions[i].roi)
        end
    end

    --Sort and pull out the lowest 'x' positions
    max_num_pos_to_concatenate = 3
    actual_num_pos_to_concatenate = Parse(Min(Count(lowest_roi_list), max_num_pos_to_concatenate), NumberType)
    Log(actual_num_pos_to_concatenate, Yellow)
    if Count(lowest_roi_list) > 0 then
        lowest_roi_list = ArraySort(lowest_roi_list, false)
        for i = 1, actual_num_pos_to_concatenate do
            lowest_roi_string = lowest_roi_string .. Round(lowest_roi_list[i], 1) .. '%, '
        end
        lowest_roi_string = SubString(lowest_roi_string, 1, #lowest_roi_string - 2)
    else
        lowest_roi_string = 'n/a'
    end

    CustomReport('>> Open Positions', Count(open_positions)..' ($'..Round(open_value, 2)..')', 'Interesting Info')
    CustomReport('>> Lowest '..actual_num_pos_to_concatenate..' Open ROI\'s', lowest_roi_string, 'Interesting Info')

end)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!