Automatic detection of indicator buffers and styles - mql4

In MetaTrader 4 the styles (e.g. arrows or lines) that are used in an indicator are not chart objects. ObjectsTotal() returns 0. Of course I can read this out via iCustom(). But what, if the EA should react to all indicators with such symbols. So without knowing the number of buffers and/or the settings of the indicator. Is there a way to automatically search for such indicator styles in the chart and use them? Or to automatically recognize the styles used and the associated buffers in an indicator?

Q : "Is there a way to automatically search for such indicator styles in the chart and use them?"
No, there is not.
As of 2020-10, having spent 13+ years with MetaTrader4 trading automation projects, there is no support for such an automated feature re-discovery.
The code-units of Custom Indicator type hard-code the composition of Indicator Buffers (having external access-method via an iCustom() procedural interface) and GUI-style properties, not accessible at all by the user-level MQL4-{ Script | EA | Custom Indicator }-code.
If this were changed in the future releases of MetaTrader4/5 terminal, you would find details inside the documentation.

maybe not exactly what u want but a oppurtunity
double ObjectGet(
string object_name, // object name
int index // object property
);

Related

MQL4 Object to buffer for reading

I'm quite new to mql4 coding and ran in some issues.
I am using PINS in combination with the AEX dashboard for mt4 to manage trades from my indicator, this indicator has a buffer (12) which the value is 1>long -1>short. I am using JagzFX Onepin which allows me to set buffer values for trades, but need a dedicated buffer for long/short. My question is, I want and indicator (simple) that converts objects placed on chart (long arrow/short arrow) convert to buffer values so JagzFX Onepin can read the signals.
What would be code be for this?
JagzFX onepin:

How to set the default font used in the MT4 Comment() function?

The default font used for the Comment("some text") function is not not a fixed-width (aka monotype) and it is often too small.
How can I change the default font used for Comment()?
Q : How can I change the default font used for Comment()?
Having used MQL4 since 2007+ there is, so far, no way to change a font used for Comment() (or the graph Time-/Price-axes).
As #Daniel has remarked, there are some chances to build tools to circumvent this trouble.
I have used a similarly motivated Comment()-based approach for a text-editor, for a (row,col)-addressable text-screen ( still inside a Comment()-text-block ), for an independent overlay with a (row,col,font,color)-text-screen and last, but not least, years ago I started to use a distributed-computing approach, so as not to remain blocked with the absence of screen-controls for the text-part of the GUI ( having a freedom of using several independent graphical views ( multi-time-frame views, views with AI/ML-analytical post-processing graphing and many others ).
Using the Terminal-GUI for a default look-and-feel is accompanied with any number of "remote"-screens ( implemented in python and other, non-MQL4, domain languages, some HPC-languages on remote computers ) that are used in-sync with the flow of MQL4-processed events.
This is the safest way to work with text-and-graphs in a user-controlled manner.
To the best of my belief, there is no way to change font type and size of the Comment() function. If they are too small for you - you have to draw Labels on the chart yourself(even though it might be a bit inconvenient to parse the text looking for "\n" objects in order to go next line).
If you are happy to change the default font for everything (not just comments) you can modify
#define CONTROLS_FONT_NAME "Tahoma"
#define CONTROLS_FONT_SIZE (8)//changed from 12
in the defines.mqh file.

Apache Beam - Delta between windows

Apologies, in trying to be concise and clear my previous description of my question turned into a special case of the general case I'm trying to solve.
New Description
I'm trying to Compare the last emitted value of an Aggregation Function (Let's say Sum()) with a each element that I aggregate over in the current window.
Worth noting, that the ideal (I think) solution would include
The T2(from t-1) element used at time = t is the one that was created during the previous window.
I've been playing with several ideas/experiments but I'm struggling to find a way to accomplish this in a way is elegant and "empathetic" to Beam's compute model (which I'm still trying to fully Grock after many an article/blog/doc and book :)
Side inputs seem unwieldy because It looks like I have to shift the emitted 5M#T-1 Aggregation's timestamp into the 5M#T's window in order to align it with the current 5M window
In attempting this with side inputs (as I understand them), I ended up with some nasty code that was quite "circularly referential", but not in an elegant recursive way :)
Any help in the right direction would be much appreciated.
Edit:
Modified diagram and improved description to more clearly show:
the intent of using emitted T2(from t-1) to calculate T2 at t
that the desired T2(from t-1) used to calculate T2 is the one with the correct key
Instead of modifying the timestamp of records that are materialized so that they appear in the current window, you should supply a window mapping fn which just maps the current window on to the past one.
You'll want to create a custom WindowFn which implements the window mapping behavior that you want paying special attention to overriding the getDefaultWindowMappingFn function.
Your pipeline would be like:
PCollection<T> mySource = /* data */
PCollectionView<SumT> view = mySource
.apply(Window.into(myCustomWindowFnWithNewWindowMappingFn))
.apply(Combine.globally(myCombiner).asSingletonView());
mySource.apply(ParDo.of(/* DoFn that consumes side input */).withSideInputs(view));
Pay special attention to the default value the combiner will produce since this will be the default value when the view has had no data emitted to it.
Also, the easiest way to write your own custom window function is to copy an existing one.

Wrapper for slow indicator for backtesting

If a technical indicator works very slow, and I wish to include it in an EA ( using iCustom() ), is there a some "wrapper" that could cache the indicator results to a file based on the particular indicator inputs?
This way I could get a better speed next time when I backtest it using the same set of parameters, since the "wrapper" could read the result from file rather than recalculate the result from the indicator.
I heard that some developers did that for their needs in order to speed up backtesting, but as far as i know, there's no publicly available solution.
If I had to solve this problem, I would create a class with two fields (datetime and indicator value, or N buffers of the indicator), and a collection class similar to CArrayObj.mqh but with an option to apply binary search, or to start looking for element from a specific index, not from the very beginning of the array.
Recent MT4 Builds added VERY restrictive conditions for Indicators
In early years of MT4, this was not so cruel as it is these days.
FACT#1: fileIO is 10.000x ~ 100.000x slower than memIO:
This means, there is no benefit from "pre-caching" values to disk.
FACT#2: Processing Performance has HARD CEILING:
All, yes ALL, Custom Indicators, that are being used in MetaTrader4 Terminal ( be it directly in GUI, or indirectly, via Template(s) or called via iCustom() calls & in Strategy Tester via .tpl + iCustom() ) ALL THESE SHARE A SINGLE THREAD ...
FACT#3: Strategy Tester has the most demanding needs for speed:
Thus - eliminate all, indeed ALL, non-core indicators from tester.tpl template and save it as "blank", to avoid any part of such non-core processing.
Next, re-design the Custom Indicator, where possible, so as to avoid any CPU-ops & MEM-allocation(s), that are not necessary.
I remember a Custom Indicatore designs with indeed deep-convolutions, which could have been re-engineered so as to keep just a triangular sparse-matrix with necessary updates, that has increased the speed of Indicator processing more than 10.000x, so code-revision is the way.
So, rather run a separate MetaTrader4 Terminal, just for BackTesting, than having to wait for many hours just due to un-compressible nature of numerical processing under a traffic-jam congestion in the shared use of the CustomIndicator-solo-Thread that none scheduling could improve.
FACT#4: O/S can increase a process priority:
Having got to the Devil's zone, it is a common practice to spin-up the PRIO for the StrategyTester MT4, up to the "RealTime PRIO" in the O/S tools.
One may even additionally "lock" this MT4-process onto a certain CPU-core(s) and setup all other processes with adjacent CPU-core-AFFINITY, so that these two distinct groups of processes do not jump one to the other group's CPU-core(s). Hard, but if squeezing the performance to the bleeding edge, this is a must.

To set a value on a PowerBuilder textbox

I am developing a billing system using PowerBuilder 12.5 Classic and I need to set 0 for a textbox; like in vb.net txtchange.Text = 0
i have two drop down list boxes
ddlb_price (defines the price value of an item)
ddlb_cash (the cash amount given by the customer)
sle_change (the change that the cashier is to give the customer)
the system should set the value for sle_change when the cashier inputs the cash.
1. this gives me syntax error;
if cash=price then
sle_fare.settext=0
end if
2. this gives 'incompatible types in assinment
if cash=price then
sle_fare.text=0
end if
The single line edit (sle) control is designed to hold text. You're trying to assign it a numeric value. You will have to change the number into a string if you want the sle to display it:
sle_fare.text = "0"
or
sle_fare.text = string(variableHere)
Once again, I'm going to step back, ignore the actual questions, and look at how a DataWindow would help as an alternative.
You seem to want a control with a data type behind it. The DataWindow has those types of controls. Don't forget that a DataWindow doesn't have to have a SELECT statement behind it; it can have a stored procedure, web service, or nothing at all (external DataWindow) behind the data set. Once you have a control with a numeric data type behind it, you get (for free) some basic editing controls, such as not allowing alpha characters in the field and making sure the entered value is really a number (e.g. "0-.2.1" would fail).
A step beyond that is looking at one of your coming requirements: calculating change. On a DataWindow, you can create a compute with an expression that will automagically calculate your change for you, once price and cash are entered.
I certainly don't want to say you can't do things the way you're proceeding, but there are many issues that a DataWindow would remove over some other approach. The strength of PowerBuilder is in the DataWindow.
Good luck,
Terry

Resources