Do not want to run script on more than one chart - page 2

 
Ovo:


It looks like you let your script time out. Your endless loop should contain condition like below. Does it?


No it has a loop like below

while(true)

{

.... Open the File, Read the content and delete the file

}

 
janakpatel3210:


Thanks SDC. your approach works fine for my requirement. Only one issue left now..

My script is never ending script. there is a while loop there..so I will not be able to delete GV before script unloads..

In this case, I am unable to attach script after restarting MetaTrader. Please help.


Awesome guys. I was able to solve my requirement. You all are real life-saver. Here is my code.

int OnStart() {
    #defineGV_ONE"ChartID"
    if (GlobalVariableCheck(GV_ONE))// Does the variable exist? {
        if (GlobalVariableGet(GV_ONE) != ChartID()) {
            MessageBox("Only single execution of MT5EasyTrading allowed.", "Error", MB_OK + MB_ICONERROR);
            //Alert(GV_ONE + " one only"); 
            return (0);
            // Yes
        }
    }
    GlobalVariableSet(GV_ONE, ChartID());
    // Create a lock.
    while (!IsStopped()) {
        ...........FileReading & otheroperations;
    } 

Thanks a Ton.

Janak

 
janakpatel3210:


Thanks SDC. your approach works fine for my requirement. Only one issue left now..

My script is never ending script. there is a while loop there..so I will not be able to delete GV before script unloads..

In this case, I am unable to attach script after restarting MetaTrader. Please help.


janakpatel3210:


Thanks SDC. your approach works fine for my requirement. Only one issue left now..

My script is never ending script. there is a while loop there..so I will not be able to delete GV before script unloads..

In this case, I am unable to attach script after restarting MetaTrader. Please help.


Awesome guys. I was able to solve my requirement. You all are real life-saver. Here is my code.

<SRC by Moderator: Ubzen>

int OnStart() {
    #define GV_ONE "ChartID"
    if (GlobalVariableCheck(GV_ONE))// Does the variable exist?
    {
        if (GlobalVariableGet(GV_ONE) != ChartID()) {
            MessageBox("Only single execution of MT5EasyTrading allowed.", "Error", MB_OK + MB_ICONERROR);
            //Alert(GV_ONE + " one only"); 
            return (0);
            // Yes
        }
    }
    GlobalVariableSet(GV_ONE, ChartID());
    // Create a lock.
    while (!IsStopped()) {
        ...........FileReading & otheroperations;
    }
    GlobalVariableDel(GV_ONE);

Thanks a Ton.

Janak

 
your trick worked
 
janakpatel3210:


As I said, my script is never ending script. It has never ending while loop in it. It attaches to a chart like an EA or Indicator.

So with your solution I am unable to run it on a chart on which it is already running. (Though this will happen rarely...by mistake).

I wasn't giving a solution just stating what happens.
 
janakpatel3210:


As I said, my script is never ending script. It has never ending while loop in it. It attaches to a chart like an EA or Indicator.

So with your solution I am unable to run it on a chart on which it is already running. (Though this will happen rarely...by mistake).

Following code works fine to solve that issue.

My only issue left now is, I want to reset or delete my Global Variables when I close the MT4 / MT5 or when it crashes.

Any help w'd be great.

Thanks,

Janak

deinit() / OnDeinit() event works with script and is exactly what you need.
 

glad to hear you got it working janak, I was going to suggest you add a deinit() function to your script too.

Reason: