Need help using HTTP request.

 

Hi.

I have implemented an AI algorithm and exposed it as a HTTP Service. Now I want to call it to draw the line in MetaTrader 5.

This is my code: https://gist.github.com/Industrial/73e1c7dbf3b009b04c7476a2bb251c47

When I test it from MetaEditor or add it to a chart then I get:

2018.12.24 15:27:58.976 Scripts script TensorFlow (EURUSD,M1) loaded successfully
2018.12.24 15:27:58.989 Scripts script TensorFlow (EURUSD,M1) removed

What did I do wrong?



Edit: HTTP Links in this editor don't work.

 

The function can be called only from Expert Advisors and scripts,

Read the doc.

 

Okay. So I can not have it as an indicator and then have other indicators / experts based on it. Why is there a restriction on this, if I may ask?

Say I would write an Expert instead. The documentation states `WebRequest() cannot be executed in the Strategy Tester.`. That would be another thing that would block what I want; To test and trade my AI.

How do I tackle this best? I have found SocketCreate. Could I use that instead?


gr,


Tom

Documentation on MQL5: Network Functions / SocketCreate
Documentation on MQL5: Network Functions / SocketCreate
  • www.mql5.com
//|                                                SocketExample.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | "Add Address to the list of allowed ones in the terminal settings to let the example work...
 

It's in the documentation just read what is written:

The WebRequest() function is synchronous, which means its breaks the program execution and waits for the response from the requested server. Since the delays in receiving a response can be large, the function is not available for calls from indicators, because indicators run in a common thread shared by all indicators and charts on one symbol. Indicator performance delay on one of the charts of a symbol may stop updating of all charts of the same symbol.

The function can be called only from Expert Advisors and scripts, as they run in their own execution threads. If you try to call the function from an indicator, GetLastError() will return error 4014 – "Function is not allowed for call".


If your call times out it will mean that this and all other indicators will hang also.

I am not sure what your target is but you can also bind to other languages by file or pipes and have your mql program read and write the I/O of that.
 
What Marco said is viable . 

I assume you are feeding price data via the webrequest for the learning processes and you aim to feed MetaTrader data to the Tensor Flow .
(if you use external data sources for price you would have to sync dates in the terminal and also make symbol and asset associations in your code)

But , if you use MetaTrader5 solely for price feeds , you can access real tick data with an expert advisor , feed that data into your learning processes 
and internally gauge the outcome . 
The issue with that approach is that you cannot do it in the tester , you would have to have a pseudo tester inside MT5  .