Multicharts code Timing process?

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Multicharts code Timing process?

Postby arjfca » 07 Jul 2011

Hello
I got interrogation on MC code timing process. A simple delay code will produce on a regular basis of 1 second an updated print, but will monopolize all MC resource to it

Code: Select all

inputs : Seconds.Delay (1);
vars :  Targettime(0);
Vars:  CMP (0);

Targettime =  ComputerDateTime + (Seconds.Delay*0.0000115740) ;
While cmp <20 begin   
    IF ComputerDateTime >= Targettime then Begin
       CMP = CMP +1;
       print (CMP:0:0, " ", time:5:8);
       Targettime= ComputerDateTime + (Seconds.Delay*0.0000115740) ;
   end; //IF ComputerDateTime >= Targettime then Begin
end; // While cmp <20 begin

This code works perfectly. But the "While cmp < 20" use all the resource of MC . All process clock is devoted to the routine. It won't allow to stop the indicator using Format Studies Indicators, Stop.

So I modified the code to remove the While condition

Code: Select all

inputs : Seconds.Delay (1);
vars :  Targettime(0);
Vars:  CMP (0);

Targettime =  ComputerDateTime + (Seconds.Delay*0.0000115740) ;

Print (Cmp:0:0, " start");
   IF ComputerDateTime >= Targettime then Begin
          CMP = CMP +1;
             print (CMP:0:0, " ", time:5:8);
             Targettime= ComputerDateTime + (Seconds.Delay*0.0000115740) ;
   end;
Only, this time the delay code is not executed. No new value of CMP is

I did try to replace the "While CMP < 20" for
- If LastbarOnTheChart then Begin.
- If BarStatus = 1 Then Begin
- If BarStatus = 2 then Begin

What could be the condition to trigger this time delay routine test?

Any help appreciated
Martin

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: Multicharts code Timing process?... Resolve

Postby arjfca » 07 Jul 2011

The solution was to use IntrabarPersist at the Variables definition

Code: Select all

inputs : Seconds.Delay (1);
vars :  IntraBarPersist Targettime(0);
Vars:  IntraBarPersist CMP (0);

Targettime =  ComputerDateTime + (Seconds.Delay*0.0000115740) ;

Print (Cmp:0:0, " start");
   IF ComputerDateTime >= Targettime then Begin
          CMP = CMP +1;
             print (CMP:0:0, " ", time:5:8);
             Targettime= ComputerDateTime + (Seconds.Delay*0.0000115740) ;
   end;


Return to “User Contributed Studies and Indicator Library”