Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I use a "variable" as a list name?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can I use a "variable" as a list name?

    I have an indicator that uses lists to store historical data so I can use OnRender to draw (I have a lot of rectangles and lines on the chart)

    But the lists have identical fields and content except for their status, Bull, Bear, Open, Closed

    I have the following named lists:
    BullOpenGaps
    BearOpenGaps
    BullClosedGaps
    BearClosedGaps

    the reason I separate them into Bull and Bear is because the formula is different for the values I store in the list.

    The reason I separate into Open and Closed is that I need to search the Open lists frequently to determine trade status and update fields. If I only have 1 list for Open & Closed, I would have to search a very large list just to find the few Open gaps to evaluate.

    But the separate lists work great. It's only a problem with the extra code I need to Render the gaps

    When I go to render them, I have to make the same method call 4 times, passing the same information to the render method. This is what the code looks like.

    HTML Code:
                for (int x = BullGapsOpen.Count - 1; x >= 0 ; x--)
                    RenderFVG(BULL,
                        chartControl.GetXByTime(BullGapsOpen[x].startTime),
                        chartScale.GetYByValue(BullGapsOpen[x].top),
                        chartControl.GetXByTime(BullGapsOpen[x].endTime) - chartControl.GetXByTime(BullGapsOpen[x].startTime) + 2 * pad,
                        (int)chartScale.GetPixelsForDistance(BullGapsOpen[x].height),
                        BullGapsOpen[x].border, BullGapsOpen[x].period);​
    I loop through the list to render each Gap. But I have the same code for BearGapsOpen, BullGapsClosed and BearGapsClosed.

    Is there any way to loop through the list, but substitute the List Name in each of the places where I use it....

    like it I could had a variable "listName", I could

    HTML Code:
    listName = BullGapsOpen.
                for (int x = listName.Count - 1; x >= 0 ; x--)
                    RenderFVG(BULL,
                        chartControl.GetXByTime(listName[x].startTime),
                        chartScale.GetYByValue(listName[x].top),
                        chartControl.GetXByTime(listName[x].endTime) - chartControl.GetXByTime(listName[x].startTime) + 2 * pad,
                        (int)chartScale.GetPixelsForDistance(listName[x].height),
                        listName[x].border, listName[x].period);​
    then I could change the "listName" and use the same method for each of my lists

    is there any way to do this?​

    #2
    Originally posted by cre8able View Post
    then I could change the "listName" and use the same method for each of my lists

    is there any way to do this?​
    Of course!

    Why not just create an extra method that takes an
    argument and does the work? The OnRender code
    can call any personalized custom methods, there is
    no prohibition against this whatsoever.

    So, create a new personalized custom method.

    Then just call your custom method 4 times, once for
    each list, passing the desired list as the argument.​

    Standard C# programming stuff, right?

    Should be piece of cake.

    Enjoy!

    Comment


      #3
      thanks bltdavid

      I created custom methods to render my different objects. But I was passing individual elements of the list to the method. So one time I would have to send BullGapsOpem[x].startTime, and another time send BearGapsOpen[x].startTime. Very cumbersome when passing 5-8 parameters to multiple methods.

      I didn't realize I could pass a list as a parameter.... I will have to research how to do that but it would greatly simplify my problem.... as long as passing a list doesn't required a lot of overhead

      Comment


        #4
        it worked great.... and about 30% faster to load than the way I was doing it.

        thank you bltdavid

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X