DLL on Metatrader 4 doesn't update with incoming ticks - dll

I have written a simple DLL as part of a custom indicator for Metatrader 4, which is called thus:
int start( ) {
double Rates[][6];
int MaximumRecords = ArrayCopyRates( Rates, Symbol(), 0 );
for( int zz = MaximumRecords; zz >= 0; zz-- ) {
OutPut[zz] = EMPTY;
}
GetSMAArray( Rates, MaximumRecords, Periods, OutPut );
return(0);
}
This works fine in that it plots as expected on the chart, but unfortunately it does not update with new, incoming ticks - it just plots on its initial call. What further code can I add to make the DLL update with incoming ticks? Almost all my searches have come up with variations on the use of
ExtCountedBars = IndicatorCounted();
to force a while loop to calculate, but these all apply to calculations contained in the .mq4 file itself. I want to force the DLL to recalculate. Secondly, I would like this recalculation to occur only on the completion of a bar and not on the arrival of all and every tick.

For the on new bar only thing, I technique is to keep last bar's (Bars[0]) date time information in a variable, and if it has changed, this means a new bar has come.
datetime lastBarDateTime;
int start(){
if(Time[0]==lastBarDateTime)
return(0);
lastBarDateTime = Time[0];
// codes to run on a new bar ...
}
For DLL part, I actually couldn't have understood where you are using DLL in that code.

Related

Go To Definition - getting back again

I am looking for a simple means of jumping back from a Go To Definition action, which goes directly back to the point from which I made the GTD jump.
The problem with the current workbench.action.navigateBack feature is that it revisits other locations over which I have moved the cursor (after making the GTD jump) before returning me to the point where I started. For instance:
public takeoff() {
this.landing();
}
public landing() {
let x = 1;
let y = 2;
...
...
}
If I choose Go To Definition to move from takeoff() to landing() and then move the cursor up and down the lines of code in landing(), when I issue the workbench.action.navigateBack I simply want to return to takeoff(), but instead I have to revisit various lines within landing() along the way. Aaargh!
Do you know how to achieve the functionality which I am looking for?

Implementing real time plot with Qt5 charts

I am new to Qt and trying to implement a real time plot using QSplineSeries with Qt 5.7. I need to scroll the x axis as new data comes in every 100ms. It seems the CPU usage reaches 100% if I do not purge the old data which was appended to the series, using graphSeriesX->remove(0). I found two ways of scrolling the x axis.
const uint8_t X_RANGE_COUNT = 50;
const uint8_t X_RANGE_MAX = X_RANGE_COUNT - 1;
qreal y = (axisX->max() - axisX->min()) / axisX->tickCount();
m_x += y;
if (m_x > axisX->max()) {
axisX->setMax(m_x);
axisX->setMin(m_x - 100);
}
if (graphSeries1->count() > X_RANGE_COUNT) {
graphSeries1->remove(0);
graphSeries2->remove(0);
graphSeries3->remove(0);
}
The problem with the above is that m_x is of type qreal and at some time if I keep the demo running continuously, it will reach it's MAX value and the axisX->setMax call will fail making the plot not work anymore. What would be the correct way to fix this use case?
qreal x = plotArea().width() / X_RANGE_MAX;
chart->scroll(x, 0)
if (graphSeries1->count() > X_RANGE_COUNT) {
graphSeries1->remove(0);
graphSeries2->remove(0);
graphSeries3->remove(0);
}
However it's not clear to me how can I use the graphSeriesX->remove(0) call in this scenario. The graph will keep getting wiped out since once the series get appended with X_RANGE_COUNT values, the if block will always be true removing 0th value but the scroll somehow does not work the way manually setting maximum for x axis works and after a while I have no graph. scroll works if I do not call remove but then my CPU usage reaches 100%.
Can someone point me in the right direction on how to use scroll while using remove to keep the CPU usage low?
It seems like the best way to update data for a QChart is through void QXYSeries::replace(QVector<QPointF> points). From the documentation, it's much faster than clearing all the data (and don't forget to use a vector instead of a list). The audio example from the documentation does exactly that. Updating the axes with setMin, setMax and setRange all seem to use a lot of CPU. I'll try to see if there's a way around that.
What do you mean by "does not work the way manually setting maximum for x axis works"? The Second method you have shown works if you define x-axis range to be between 0 and X_RANGE_MAX. Is this not what you are after?
Something like: chart->axisX()->setRange(0, X_RANGE_MAX);

How to draw a Filling like a Rectangle, in MQL5?

can anybody suggest a way how to achieve this kind of drawing, as the official mql5 documentation does not point out this.
I have done the sample provided herebut it only outputs this result,which is not what I wanted.
anybody has any suggestion?
The simpler part: ... better forget Custom Indicators ( all share single-thread / block )
For a faster and safer GUI, with a full control over painting these orthogonal shapes, the New-MQL4/MQL5 languages can use something like this:
// --------------------------------------------------------------------
#define GUI_aFontSIZE 10
#define GUI_aFontNAME "Courier New"
#define GUI_aTradeCOLOR C'80,0,80'
#define GUI_aTPed_COLOR clrDarkGreen
#define GUI_aSLed_COLOR clrDarkRed
#define GUI_isSELECTABLE True
long GUI_aMainWINDOW = CharID();
int GUI_anObjNUMBER = 0;
string anInterimObjNAME = StringFormat( "GUI.DEMO_RectangularOBJECT_[%d]", GUI_anObjNUMBER );
if ( ObjectFind( anInterimObjNAME ) == GUI_aMainWINDOW )
ObjectDelete( anInterimObjNAME ); //--- prevent collisions
ObjectCreate( GUI_aMainWINDOW, anInterimObjNAME, OBJ_RECTANGLE, 0, aTimeOfENTRY, anEntryPRICE,
aTimeOfEXIT, DBL_MIN
);
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_COLOR, GUI_aSLed_COLOR ); //--- set color
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_BACK, True ); //--- display in the foreground (false) or background (true) ~ FILL-IT ~
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_SELECTABLE, GUI_isSELECTABLE ); //---------------------------------------- MAY AVOID GUI interactions
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_SELECTED, False ); //--- set GUI-object as (non)-pre-SELECT-ed
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_HIDDEN, False ); //--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_ZORDER, 1 ); //--- set the "layered" priority for receiving a mouse-click-event in the chart
// --------------------------------------------------------------------
If in doubts, use the GUI objects dialogue-panels to experiment manually and derive the missing syntax explanation(s) in the language documentation.
May use a more complex & a way more risky approach:
If the story is to become based on a Custom Indicator, the toys get a bit more complex.
There is a hardcoded-engine, that processes data in a so called IndicatorBuffer.
In case, a particular data element there happens to equal to EMPTY_VALUE a special handling is provided for those particular bars.
Such EMPTY_VALUE constant signals to the processing-engine the values of indicators that are not shown in the chart, as did surprise you.
For example, for a built-in indicator Standard Deviation with a period of 20, the line for the first 19 bars in the history are not shown in the chart at all, using this feature trick. The same might be used anywhere further, all the way to the current bar[0], even dynamically, so as to emulate "vibrations" :o) ( do not risk this in production ... ).
This can also create "dropped" parts of the painted areas in aPriceDOMAIN displayed Custom Indicators.
For painting area "between" two generic Custom Indicator lines ( between "oscilating" curves ), one has to employ a few more tricks, using:
//--- plot dual-line-filled----------------------------------------------
#property indicator_label "DEMO-Custom-2-Line-Filled-Indicator"
#property indicator_type DRAW_FILLING // THE MAGIC FILL-STYLING
#property indicator_color clrAqua,clrSalmon // THE MAGIC FILL-STYLING
#property indicator_width 2
//--- Custom Indicator buffers -----------------------------------------
double aCustomIndicatorLineDATA_buffer1[];
double aCustomIndicatorLineDATA_buffer2[];
//--- Next, fill DATA as usually and the GUI shows the magic FILL-STYLING
Anyway:
Enjoy the Wild Worlds of MQL4/MQL5
Interested? May also like reading other MQL4 and low-latency trading posts

Random letters instead of numbers in dynamic text AS 2.0

So I'm trying to program a game using flash, and it's my very first time and I can't get something to work.
In the game, a ball will float across the screen and if you click on it you get 2 points. Except when I test it, the first time I click on the ball I get the letters 'eoceeeo' and if I click the ball again I get the letters 'eeoS'. The dynamic text is on a layer with the first frame having the AS of
var _root.score = 0;
gameScore.text = _root.score;
The dynamic text has a varible of _root.score and a name of gameScore
The floating ball has the AS of
on(release) { _root.score+=2; _root.gameScore.text = _root.score; }
If you click on your gameScore dynamic text field, you can scroll down to its Variable property and set that as _root.score. That way, you do not have to call gameScore.text = _root.score every time the score changes - it will simply update automatically.
Also, if you remove the var from in front of _root.score = 0, it will be easier for ActionScript to handle. Perhaps, you are casting the score variable as an integer, and the dynamic text field is having trouble displaying it as a string of characters. This can also be solved with String(_root.score) and score.toString().
That should make your code a bit less complex, and help for you to identity your random letters problem, which can't be solved specifically with the information you have here. Hope that helps!

Advice how to present calculation of #records

I have an app that have a lot of records that i am loading into a core data DB. The actual loading is done in a module called "loadDBRecords". This module is called from "MainViewController", which is connected to "MainViewController.xib".
As the loading takes quite some time i have added an UIActivityIndicatorView to the .xib during the load. However, i would like to use a UIProgressView. When i look at this i do not see any way of using that unless i move the loading code from "loadDBRecords" to the "MainViewController".
My question is: What is the best way of leveraging the UIProgressView with my setup?
You could add a "progressHandler" block to the -loadDBRecords method. Execute the block for every record you load, and pass back a floating-point value between 0.0 and 1.0 indicating the progress thus far. The block can then assign that value to the progress bar, or print it to the console, or whatever you need it to do. (Traditionally, this would be done with a function pointer or a delegate/selector combination, but I've found blocks tend to make your intent clearer—or at least make it easier to show your intent.)
- (void)loadDBRecords:(void (^)(CGFloat progress))progressHandler {
NSUInteger count = /* number of records*/;
for (NSUInteger i = 0; i < count; i++) {
/* load the record */
progressHandler((CGFloat)n / (CGFloat)count);
}
}