zeromq doesnt work when used as an indicator , but works when used as a script

 

Hi coders

I need to plot values from an EA onto a chart , It is a very complicated EA , and I want to do this for troubleshooting purposes , I have multiple signal setups and need to validate the signals/indicators 'look' correct visually [ie if signal1 is true plot arrow , if signal 2 is correct fill an area etc , up to 30 signals]. 

I want to use zeromq that pubs and subs , so that I don't have to use the indicator all the time , just when i am troubleshooting.


I downloaded 2 scripts that work as examples of how to use zeromq. They work as scripts , i put one one server script on one chart and used the client script on another.
Ther server publishes data to port 5556 , the receiver subscribes to port 5556 and reads the data. These scripts work fine.


I have a need however to use zeromq as a indicator , that needs to plot information on the graph on each bar. So I want to convert the receiver code to become an indicator. 
I have pasted and slightly modified the client code into an indicator called 'plottest'. I am using basic print to debug and without plotting as yet.

The indicator when added to a chart locks up MT4.

If i change this line of code from this

"subscriber.recv(update);"

to this

"subscriber.recv(update,1);"

 the code runs but no data is returned. [I am a newb at zeromq/mt4, but I read somewhere this is a noblock flag change]

If i change the line to

Print(subscriber.recv(update,1));

it returns false , so it is not reading any data.

Seems I am missing something obvious? like this is never going to work... or i got some brain malfunction.
Any ideas?


What do other people use to validate signals? I don't want to put on 30 indicators at once because it would be unreadable. My signals are linear , once a signal is activated it waits for another/new/different signal [its/I am complicated]. This zeromq would solve my issues for ever but I cant get it to work.

Regards
Cam

snippet below from plottest.mq4

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

Context context;
int InpZipCode=10001;
//  Socket to talk to server
Print("Collecting updates from dodgy weather server…");
Socket subscriber(context,ZMQ_SUB);


   
subscriber.connect("tcp://*:5556");
subscriber.subscribe(IntegerToString(InpZipCode));



//  Process 100 updates
int update_nbr;
long total_temp=0;
for(update_nbr=0; update_nbr<100; update_nbr++)
  {
      ZmqMsg update;
      Print(subscriber.recv(update,1));
      string msg=update.getData();
      if (msg!=""){
      Print(msg);
      }
  }
return(rates_total);
}
 

mmm update.


I have a workaround , but I don't prefer it , though it is simpler , yet not as 'adaptable to everything'.

see https://www.mql5.com/en/forum/244357/page2

 at post 16 by @nicholi shen

Simple code. my example is attached below as files , compile and both the EA [EATestPlotTest2] and the Indicator [plottestv2] to the same chart.

Be nice to know why I couldn't use ZeroMQ in an indicator though.

18hrs of my life gone.

Cheers
Cam

Best way to share data between indicators (.csv vs. array)
Best way to share data between indicators (.csv vs. array)
  • 2018.05.14
  • www.mql5.com
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...
Files:
Reason: