Download MetaTrader 5
To add comments, please log in or register
Publish your articles and improve your rating!
janakpatel3210
37
janakpatel3210 2014.03.08 09:18  
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
37
janakpatel3210 2014.03.08 09:38  
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
37
janakpatel3210 2014.03.08 09:39  
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

janakpatel3210
37
janakpatel3210 2014.03.08 09:40  
your trick worked
Simon Gniadkowski
Moderator
17972
Simon Gniadkowski 2014.03.08 11:39  
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.
Alain Verleyen
Moderator
29468
Alain Verleyen 2014.03.08 12:02  
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.
Ian Venner
2583
Ian Venner 2014.03.09 00:53  

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

/ /12
To add comments, please log in or register