1

I have some COT data that I want to plot under the main price window as an indicator. The COT data are external data, i.e. independent of the prices. So one can not write it like a traditional indicator calculated from the prices. Since I have all the data needed, I don't need to do any calculation. I only need to convert the date and time so that it aligns with the price chart. I will figure out how to do it later. Now, if we ignore the alignment, what I want to ask is how could I plot the data under the price chart? Thanks!

fyang
  • 89
  • 9

2 Answers2

0

Alternative A:

Use the MT4-GUI tools and plot the data programmatically right into the MT4.Graph or using the screen-layout-plane of GUI-objects, independent of the underlying live-[TimeDOMAIN,PriceDOMAIN]-graphing, both using Expert Advisor-type of MQL4-code. We use this approach most often for all the tasks, that would normally land as a Custom Indicator-type of MQL4-code, as the New-MQL4.56789 code-execution engine has reduced the achievable performance for all ( yes, ALL ) Custom Indicator code-units' execution into a single, thus both RealTime-sensitive and potentially blocking, thread.

Using this alternative, you retain the full freedom of the code-design and may benefit a lot from pre-computing & pre-setting the GUI-objects inside OnInit(){...} section, before entering the trading-loop. This also minimises the latency costs associated with a need to update the GUI-scene from inside an OnTick(){...} event-loop.


Alternative B:

One may also opt to do a similar job using an independent Script-type of MQL4-code unit, as the COT data are weekly announced and thus static per-se.

Launching Script is a step, that can happen whenever feasible and this implementation model may also enjoy some ex-post modification tools, that could be run from another Expert Advisor or another Script MQL4-code, for the sake for some ex-post live-GUI-scene modification/maintenance.


Alternative C:

If one indeed insists to do so, the GUI-composition might be assembled inside a rather special-purpose live-calculated Custom Indicator-type of MQL4-code.

This approach but has to carefully deploy the GUI-composition into the Custom Indicator OnInit(){...} section and avoid any risk of blocking a flow of execution inside the above said critical section of OnCalculate(){...}.

Buffer-mapped, register-based Custom Indicator data & graphing tools are rather rigid for more advanced purposes, that do not strictly follow the hard-wired logic of a code, responding just to a stream of MarketEvent-s, which may, but need not, happen at once, but is being arranged by a sort of mini-batches, so as to process the whole depth of the DataStore in a segmented ( thus less-blocking ) processing approach.

Building the GUI-scene inside the OnInit() section of the Custom Indicator, one may still benefit from distributed processing, if external data source is to be read and/or any similar type inter-platform communications ( be it for a messaging or a signalling purpose ).


My choice would be the [A]

Mapping { Date, Time } onto a MQL4-datetime is trivial, MQL4 used to use since its beginning datetime as int seconds elapsed since 1970-01-01,00:00:00.000 - so simple, so easy.

user3666197
  • 1
  • 6
  • 50
  • 92
  • Thanks! Could you give me some details of the steps if I choose Alternative 1. I never wrote any indicator myself. – fyang Apr 08 '17 at 19:28
  • What have you tried so far? Post your data-import interface, be it file-based or message-based and sketch your desired GUI-scene. There are so many ways how to augment MT4-GUI to choose from. – user3666197 Apr 08 '17 at 20:17
  • Let's say, for each currency pair, I have a separate excel file, named as "concise_COT_USDCAD.xls", "concise_COT_USDJPY.xls", "concise_COT_EURUSD.xls", "concise_COT_GBPUSD.xls" and so on. In each excel file, there are 5 columns, named as "Date", "net_NonComm", "net_Comm", "differential" and "diff_52_Week_Percentile". In MT4, under the chart window, I want to make 2 more separate windows, the first one for the plot of "net_NonComm", "net_Comm" and "differential" and the second one for the plot of "diff_52_Week_Percentile". How should I do it? Thanks! – fyang Apr 08 '17 at 20:23
  • Well, MT4 has not .xls file import filter. One can either decide to go manually, and prepare data into .CSV imports and process it in a dumb way inside MT4 code, or elaborate some external ( python / java / C / C++ ) analytics platform and deliver such services into MT4 ecosystem in a much smarter way, via smart-messaging. Having several years operated the latter, I would never opt to the former. Running an external AI/ML-decision factory for predictions actually costs just about 75 [ms] RTT and the external facilitation of the data-processing is extremely comfortable to live with. – user3666197 Apr 08 '17 at 20:32
  • It's OK to change the format of the excel files. I used Matlab to generate it. It's quite easy. I just found the quality of the plots in Matlab is not so good as in MT4, so I wanted to switch to MT4. But I'm not so good at MT4. – fyang Apr 08 '17 at 20:35
  • By the way, I'm not a programmer. I use Matlab only for data analysis for my research. So, probably you have to explain in more detail. – fyang Apr 08 '17 at 20:39
  • There is one more way -- go into a distributed system **[tag:MATLAB]** ---- **[tag:MT4] Terminal**. Both code-execution environments have available ZeroMQ communication / signalling framework tools and your code can "speak" each with the other, in real-time, with low-latency. Cool? Yes, VERY COOL! Using this for many years ... worth an effort... – user3666197 Apr 11 '17 at 15:14
0

declare the indicator buffer:

double ExtBufferCOT[];

assign indexes of buffers

SetIndexStyle(  0, DRAW_LINE    );
SetIndexBuffer( 0, ExtBufferCOT );

in the OnCalculate() function - make sure it is time to check the levels again ( I think you do not need to update them every tick, right? Maybe once a day or once a week) and then read the file that you have ( we do not have example of file so senseless to describe how to do that here ), convert elements of the file, using StrToTime() and StrToDouble() the last step - get last N lines from your file, and map them to the indicator buffers:

double       value;
datetime     time;                      // - your values from file are here

int          shift  = iBarShift( _Symbol, 0, time );
ExtBufferCOT[shift] = value;            /* probably need to fill buffer
                                           of next candles too
                                           if your chart timeframe
                                           is smaller then frequency
                                           of observations in the file
                                           */
user3666197
  • 1
  • 6
  • 50
  • 92
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20