Announcement

Collapse
No announcement yet.

Repainting after every tick CPU intensive?

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

  • Repainting after every tick CPU intensive?

    I have an efs used in many intraday charts that evaluates four stochastic conditions using a string of 'if/else if' statements. Based on whichever stochastic condition is true, setChartBG() will paint a particular background color.

    The conditions are such that one of them will always be true, and as I understand it, these conditions are evaluated for every single tick throughout the trading day (which could be thousands of ticks). So the chart background could be repainted thousands of times a day. However, any one condition could remain true for hundreds of consecutive ticks, so a repaint (of the same color) is not really necessary.

    My question is: Is all that repainting CPU or graphics intensive given the efs is used in many charts? Would it be worth enclosing the setChartBG() color command in an if statement with a flag, so if the same condition is true this tick as last tick, a repaint would not occur? Or in the efs world, is repainting a relatively simple task that is not worth optimizing?

    Thank you
    shaeffer

  • #2
    shaeffer

    so if the same condition is true this tick as last tick, a repaint would not occur?
    You can do that in the following way. First declare two global variables called (for example) color0 and color1 and set them both to a color of your choice for example var color0 = color.white
    Then as the first line of the main() function add the following
    PHP Code:
    color1 color0
    This will run on every tick and will assign to the variable color1 the color last determined by your conditions.
    Then in your conditions you will have the following
    PHP Code:
    if(myCondition1){
        
    color0 Color.lime;//assigns the color to the variable color0
    }
    else if(
    myCondition2){
        
    color0 Color.yellow;//as above
    }
    //else etc 
    At this point you check if the value of color0 is different from that of color1 which was the color at the prior tick and if it is different you repaint the chart
    PHP Code:
    if(color0 != color1){//if color on current tick is not the same as at prior tick
        
    setChartBG(color0);//chart gets repainted in current color

    I leave it to you to determine the difference (if any) this change will have on the performance of your setup
    Alex

    Comment


    • #3
      Thanks Alex,

      I'll try it this weekend. Now, the background is 'commanded' to paint on every tick and I was wondering what it would do with no paint command - stay the same or would it paint a default color? But from the looks of your suggestion, with no specific command to paint differently, it will simply stay the color it was. Great!

      I'll let you know if it makes a noticeable CPU loading difference.

      Regards
      shaeffer

      Comment


      • #4
        shaeffer
        The example I provided will execute the command to paint the chart background only when there is a change in color.
        Alex

        Comment

        Working...
        X