Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
Pavel Soukup
559
Pavel Soukup 2015.02.02 18:34 

Hi guys,

I have this problem: I have indicator which calculate some arithmetic operations.

If change period on chart --> all aritmetic operations have to be make again. This very very slowing down and placing a burden on my pc. And some data is loss.

My idea was - simply demonstrative mql code:

#property version   "1.00"
#property strict
#property indicator_chart_window
int count=0;

void OnDeinit(const int reason)
{
  if (_UninitReason==REASON_CHARTCHANGE) Alert("change chart OnDeinit REASON_CHARTCHANGE   count=",count); 
}

int OnInit()
{
  Alert(__FUNCTION__," change chart OnInit REASON_CHARTCHANGE   count=",count); 
  return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{}
//+------------------------------------------------------------------+
void start()
{ 
  count++;
  if (count==5) { Alert(StaticValue()); count=0; }
}

//+------------------------------------------------------------------+
int StaticValue()
{
   static int static_value=0;
   return(static_value++);
}

 

 But this is not solution for my problem. Variable static_value after change period on chart always begin from zero.

This is simply code. In real code I need remember value of 4 arrays.

Can you help me, please? Thank you.

Keith Watford
Moderator
8028
Keith Watford 2015.02.02 19:24  
You could write the data to a file in OnDeinit
Pavel Soukup
559
Pavel Soukup 2015.02.02 22:04  

It isn´t good solution. 

works with file (time write and reading)  because fast repeat change periods on chart would phase out activities code!

Carl Schreiber
5967
Carl Schreiber 2015.02.02 22:29  
Global Variables?
Pavel Soukup
559
Pavel Soukup 2015.02.03 13:21  

I know about it. Thank you, gooly. But - for arrays data? Global variable for variable type of array mql not supported.

I would have to more individual variable and then select, sorte global variables to properly match the value into the index array.  

I am afraid the situation when user quckly repeat change period. Does it other solution?... 

Carl Schreiber
5967
Carl Schreiber 2015.02.03 13:48  

use a loop?

for(int i=0;i<ArrSze;i++) GlobalVariableSet( "arrName "+(string)(i+10000), arr[i]);

=> i+10000 is an easy way (if ArrSze<=9999) to add leading zeros for a lexical==numerical sort order.

But don't forget to subtract it..

Pavel Soukup
559
Pavel Soukup 2015.02.04 08:53  

Thanks for the willingness to help. I'm thinking about the potential problems of running the indicator.. As an example of the situation when it will be completed candle and the same time user change period.

I have solution next problem - synchronize. My next idea for solution - divide the indicator into two parts. The first part (only calcul buffer indicator) is running one chart. This chart will be user prohibited swith period, the second part is running next chart, when will be user enabled switch period. I have to think comunications between parts of indicators.I think that this way will be the source of any smaller problems to futures my code and for debuggering code soo. 

/
To add comments, please log in or register