Download MetaTrader 5
To add comments, please log in or register
Do you need a trading robot? Orderit via Freelance service!
feeblefx
19
feeblefx 2012.10.18 17:16 

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?


int start()

{ 

 if(!WindowScreenShot(StringConcatenate(Symbol(),"_",Period(),"_",TimeToStr(TimeCurrent(),TIME_DATE),"_",Hour(),".",Minute(),".gif"),1280,1024)) Print(GetLastError()); 
 return(0);
}
Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2012.10.18 17:27  
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?

<SNIP>


Please edit your post . .  . .



Please use this to post code . . . it makes it easier to read.

 

Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2012.10.18 17:30  
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql? 

Make a note of the current time ( TimeCurrent() ) to a variable, take a screenshot . . .  on the next tick check if 5 mins or more have elapsed,  if they have take a screenshot and reset your time variable to the current time.
feeblefx
19
feeblefx 2012.10.18 18:06  

Thanks Raptor,

The issue here is that I need to run this as a script, which is not run tick-wise like an EA. So it seems that for scripts the script() function terminates is only loaded again on the next request not on the next tick.

Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2012.10.18 21:12  
feeblefx:

Thanks Raptor,

The issue here is that I need to run this as a script, which is not run tick-wise like an EA. So it seems that for scripts the script() function terminates is only loaded again on the next request not on the next tick.

You can have an infinite loop within start() and a 5 min ( 300000 ms ) Sleep() . . .   
feeblefx
19
feeblefx 2012.10.19 15:25  

Raptor, that is exactly that I came up with. Turns out my problems extend beyond this issue, but thank you.

You would not happen to know the state of the art concerning HTTP Posts from Mt4? ;-)

Most solutions out there seem to be broken in one way or another. Has MetaTrader come out with an official approach? 

Tonny Obare
1047
Tonny Obare 2012.10.19 16:26  
Raptor's code will hinder other operations like trading etc since the entire EA will sleep. Try this
int NextSave;

int init()
{
 NextSave=0;
}

int start()
{

...// other code

 while(TimeCurrent()>NextSave)
 {
  ...    // code to take screenshot goes where dots are
  NextSave=TimeCurrent()+300;
 }

//--------------------------------------
return();
}
Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2012.10.19 20:19  
tonny:
Raptor's code will hinder other operations like trading etc since the entire EA will sleep. Try this
Please read all the posts in the tread . . .  I suggested checking the time and doing a screen shot every 5 mins . . .  but the OP wanted a script.
James Clark
117
James Clark 2016.06.24 10:09  
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?



 Hi feeblefx

 You can use MathMod to do this. Try the following;

 

//Vars
extern string Info = "RunFunctionveryXMins 1 - 60";
extern int RunFunctionveryXMins = 5; 
bool functionCalled = false;

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      //Reset functionCalled boolean
      if(MathMod(Minute(),RunFunctionveryXMins)) {
         functionCalled = false;
      }
      
      //
      if(functionCalled == false) {
         if(MathMod(Minute(),RunFunctionveryXMins)) {
            Print("Don't Run Function");
         }
         else {
            Print("Call Function");
            //Call Your Function Here
            
            //Stop Function being called again
            functionCalled = true;
            
         }
      }
      
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register