My 500 ms Delay code froze MC

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

My 500 ms Delay code froze MC

Postby arjfca » 05 Jul 2011

I posted a similar questions in another topic. But it is more appropriate to have is own one.
viewtopic.php?f=1&p=41821&sid=059cc9301 ... 62d#p41819

I'm using the GetmachineTime.dll to capture the actual time of my pc. I then add 500 millisecond to this time and loop until actual time = Targettime.

It work very well until i try to stop it by turning off my indicator on the chart. Then, my Multicharts session froze and I have to close it.

Any modification I should do?

Is there a better way to create a 500 ms delay

Code: Select all

//Function MachineTime
DefineDLLFunc: "GetMachineTime.dll", Long,"MachineTimeMill";
MachineTime = MachineTimeMill;

//Indicator DisplayTime

Var:
TargetTime (0),
Delay (500);

Targettime = MachineTime + delay;
While Value1 =0 begin
if machinetime >= Targettime then
begin
print (Targettime);
Targettime = MachineTime + delay;
end;
end;
Any help appreciated

Martin

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: My 500 ms Delay code froze MC

Postby arjfca » 06 Jul 2011

It seems that my problem is caused by my endless loop: While Value1 = 0

Code: Select all

Var:
TargetTime (0),
Delay (500);

Targettime = MachineTime + delay;
While Value1 =0 begin
if machinetime >= Targettime then
begin
print (Targettime);
Targettime = MachineTime + delay;
end;
end;
To my understanding, MC Format Object Studies Status does not take back the control of is process before the last line of the indicator code is completed. This indefinite loop will never allowed the last line to be executed, hence, control never return to MC. Since MC does not have the control of the process, he is waiting for the last line of code to be executed before turning off the studies. This line never came and a fatal error is created and MC is forced to close.

To my 2 cents opinion, MC Indicator Studies Status should always have total control over the execution of an indicator. Turning on or off should be to the prerogative of the user, not thigh to the given indicator code execution.

I will go to bed less dummy tonight :)
Martin

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: My 500 ms Delay code froze MC

Postby Stan Bokov » 06 Jul 2011

To my 2 cents opinion, MC Indicator Studies Status should always have total control over the execution of an indicator. Turning on or off should be to the prerogative of the user, not thigh to the given indicator code execution.
Hmmm, thanks for the idea. It sounds logical to me.


Return to “MultiCharts”