Best way to share data between indicators (.csv vs. array) - page 2

 
  1. ZetaTrader:

    I'm using this function courtesy of Hanover over at ForexFactory, I've adapted it slightly to work in my context.

    I'd rather you'd give me an opinion on my question, though.

    1. Those calls are the precursor to, and the equivalent of, the modern webrequest. They are blocking calls. You can not use them in an indicator.
    2. Your question is irrelevant. What part of you can not use blocking calls in an indicator is unclear?

  2. Emma Schwatson: I assume you're using an ea to process webrequests.
    No he is not.
    ZetaTrader: I wrote an indicator that, once a minute, reads a website and extracts a certain value.
 
whroeder1:
    1. Those calls are the precursor to, and the equivalent of, the modern webrequest. They are blocking calls. You can not use them in an indicator.
    2. Your question is irrelevant. What part of you can not use blocking calls in an indicator is unclear?

  1. No he is not.

Well, I am using it. Paste it in an indicator, call the function with a website of your choice and let me know. 

 
ZetaTrader:

Well, I am using it. Paste it in an indicator, call the function with a website of your choice and let me know. 

@whroeder1 While I hope you test it:

Forget the website part. It was not my question whether I can or can not get data from websites in an indicator. I just do it.

Please focus on the question part of my question:

Say indicator 1 does calculations resulting in a value and Indicator 2 needs those values.


In your opinion, is it better to have indicator 1 write these values into a .csv (I'd do that anyway to create charts in other software) and have indicator 2 read them (in the same time), if that is possible, 

- or, have indicator 1 save them in an array and offer access to this array by indicator 2, if that is possible,

- or, as suggested by Emma here, share each new value by using a custom chart event?


I you do have an opinion on that out of your experience, I'd be interested, I don't want help with the code, as shown in previous threads, I always try to get around that myself as far as possible.

 
ZetaTrader:

@whroeder1 While I hope you test it:

Forget the website part. It was not my question whether I can or can not get data from websites in an indicator. I just do it.

Please focus on the question part of my question:

Say indicator 1 does calculations resulting in a value and Indicator 2 needs those values.


In your opinion, is it better to have indicator 1 write these values into a .csv (I'd do that anyway to create charts in other software) and have indicator 2 read them (in the same time), if that is possible, 

- or, have indicator 1 save them in an array and offer access to this array by indicator 2, if that is possible,

- or, as suggested by Emma here, share each new value by using a custom chart event?


I you do have an opinion on that out of your experience, I'd be interested, I don't want help with the code, as shown in previous threads, I always try to get around that myself as far as possible.

Being able to use WINNET call in an indicator doesn't mean it's a good idea to do it.

About your question :

I'm attempting to solve an issue but I'd like to have an opinion which solution is more efficient/appropriate in the MQL4 way of thinking.

There is no generic answer, it depends of your specific case. File can be fine, ChartEvent too, or any other way. In summary, there is no best way.

 
ZetaTrader:

- or, as suggested by Emma here, share each new value by using a custom chart event?

Well, if you want efficient code with asynchronous operation and the fastest possible response time then you'd run a worker script (do not use an indicator to process web requests) and an EA on the same chart. The worker script would perform the web request (asynchronous work), parse and/or re-serialize the relevant data and send it to the EA via EventChartCustom's "sparam" for large data-set or use the lparam/dparam if all you need to send is a simple value. 

I think it would make a lot more since if you saw it as an example. 

Example script:

#property strict
#define WORKER_EVENT 9
//+------------------------------------------------------------------+
void OnStart()
{
   int sleep = 5*1000;
   while(!IsStopped())
   {
      /* do webrequest stuff with WebRequest() built-in functions*/
      string serialized_data = "long:60,short:175";
      bool event = EventChartCustom(ChartID(),WORKER_EVENT, 0,0.0,serialized_data);
      if(event)
      {
         Sleep(1);
         //The EA should print first since we slept 1ms, thus demonstrating asynchronous operation.
         printf("<FROM SCRIPT> Sent [%s] as sparam.", serialized_data);
      }
      Sleep(sleep);
   }   
}


Example EA (or indicator):

#property strict
#define WORKER_EVENT 9
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnTick(){}
void OnTimer()
{
   Print("EA working while script sleeps.");
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id == CHARTEVENT_CUSTOM+WORKER_EVENT)
      printf("<FROM EA> event string = %s", sparam);
}


Compile and run both on the same chart to get a better understanding of how it works. 

 
Emma Schwatson:

Well, if you want efficient code with asynchronous operation and the fastest possible response time then you'd run a worker script (do not use an indicator to process web requests) and an EA on the same chart. The worker script would perform the web request (asynchronous work), parse and/or re-serialize the relevant data and send it to the EA via EventChartCustom's "sparam" for large data-set or use the lparam/dparam if all you need to send is a simple value. 

I think it would make a lot more since if you saw it as an example. 

Example script:



Example EA (or indicator):


Compile and run both on the same chart to get a better understanding of how it works. 

Thanks so much, Emma!

I haven't had the chance to compile and understand the code but will ASAP and reply here. Thank you!

Reason: