Reduce Processor Waste running indicator

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #200087 quote
    robocop
    Participant
    Average

    Hello,
    I am looking for a way to reduce the CPU usage of the pc by writing an optimized code of an indicator.

    I know that PRT runs an indicator for every tick arriving on the instrument and, within this, it executes the indicator for every bar on the worktable.

    That is, if I have 1000 bars in the work plan, for every incoming tick PRT executes the indicator 1000 times.

    My indicatorit already uses calculateonlastbars = 20 so for every tick it run 20 times, one for last 20 bars, and draws objects with DRAW commands only if islastbarupdate.
    But the use of CPU is very high due to complex calculation.

    because object drawing are very static (starting from a certain date in the past), it would be sufficient to activate drawing not for each tick,
    but:
    – at each new opening bar or  every 10 seconds
    – in any case when the market is closed (because no new tick arriving to force draw).

    in other words, there is a way to recognize if we are at a closed market period, and therefore if ticks do not arrive?
    I can always draw, or I am at an open market and therefore I can count on the fact that the ticks arrive and then use
    currentsecond to make the indicator work every 10 seconds?

    Or its’ possible to know the my pc Time and date at indicator execution? I found only reference to closing bar time/date/timestamp.

    thank you.

    #200092 quote
    JS
    Participant
    Senior
    Hi @robocop

    If I understand your problem correctly and you only want to have your indicator updated 1 time every 10 seconds, you can use:

    TimeFrame(10 seconds, UpdateOnClose)

    #200093 quote
    robocop
    Participant
    Average
    Hi @robocop If I understand your problem correctly and you only want to have your indicator updated 1 time every 10 seconds, you can use: TimeFrame(10 seconds, UpdateOnClose)
    Your suggestion is not applicable because MultiTimeFrame require that the timeframe of the chart is below Timeframe coded (eg. chart TF 5 second). MyIndicators runs in Timeframe 1h and above (2h, 4h, Day, Week, etc) and i want to update not at every tick on market open (e.g. 10 second, at close/open bar, etrc) and always at market close.
    #200096 quote
    JS
    Participant
    Senior

    Okay, maybe you can make the complex calculations less complex in a smart way…

    For example, I use the standard deviation in my calculations and have found a way to calculate this standard deviation much faster…

    #200097 quote
    robocop
    Participant
    Average
    Okay, maybe you can make the complex calculations less complex in a smart way…
    In my opinion the right way is dont make any calculation if  we know is redundant, not make a light, but redundant, calculation. Anyway, i will think about it. Meanwhile if you know the answer to my original question, i appreciate it.
    #200098 quote
    JS
    Participant
    Senior
    I’m not talking about redundant calculations, but sometimes you can manipulate the equations/calculations in such a way that they work much faster. Calculating the standard deviation in this way is much faster than with the standard method…
    Mu = Average[n](Close)
    MuSquared = Square(Mu)
    
    XiSquared = Square(Close)
    
    StdRS = SQRT(1/n * Summation[n](XiSquared) - MuSquared)
    
    
    Return StdRS[n]
    
    #200100 quote
    JS
    Participant
    Senior
    I would not know any other solution for this. (Normally, using “CalculateOnLastBars” should significantly reduce your CPU usage)
    GraHal thanked this post
    #200190 quote
    Nicolas
    Keymaster
    Master
    You can use a simple conditions based on time in conjunction with islastbarupdate: In this example, I’m making a new calculation every X seconds:
    X = 6
    
    if islastbarupdate and timestamp-lastcalc>=X then 
    
     //do some calculations
     indi = close
     lastcalc=timestamp
    
    endif 
    
    return indi
    #200577 quote
    robocop
    Participant
    Average
    You can use a simple conditions based on time in conjunction with islastbarupdate: In this example, I’m making a new calculation every X seconds:
    Thanks a lot.
    #200579 quote
    GraHal
    Participant
    Master
    Link to Nicolas code added as Log 334 here … Snippet Link Library
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Reduce Processor Waste running indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
robocop @robocop Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by GraHal
3 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/03/2022
Status: Active
Attachments: No files
Logo Logo
Loading...