Coding help - page 522

 

Hi everyone,

I wish to know if this is the correct way to calculate indicator's value in a for loop (throughout all the available bars):

int OnCalculate(...)

{

//...

ArraySetAsSeries(SignalLine,false);

//...

for(int i=0; i<Bars; i++)

{

double ma=iMA(NULL,0,MaPeriod,0,MaMethod,MaPrice,i);

//...

SignalLine=ma;

}

//...

}

//...

return rates_total

}

P.S. Logically in this simple case I would like to represent and plot a MA replication by iMA object. But I am not sure of how I set the loop. I get a bit of difference compared to the one calculated with built-in MT4. I cannot figure out why!

Thanks

 
har:
Hi everyone,

I wish to know if this is the correct way to calculate indicator's value in a for loop (throughout all the available bars):

int OnCalculate(...)

{

//...

ArraySetAsSeries(SignalLine,false);

//...

for(int i=0; i<Bars; i++)

{

double ma=iMA(NULL,0,MaPeriod,0,MaMethod,MaPrice,i);

//...

SignalLine=ma;

}

//...

}

//...

return rates_total

}

P.S. Logically in this simple case I would like to represent and plot a MA replication by iMA object. But I am not sure of how I set the loop. I get a bit of difference compared to the one calculated with built-in MT4. I cannot figure out why!

Thanks

When you use iMA() it does not matter the order

But the correct way should be for(int i=Bars-1; i>=0; i--) - that way you shall avoid errors in a lot of cases

 

Thank you mladen. So if I set ArraySetAsSeries(SignalLine,false) I should iterate with

for (int i = 0; i < Bars; i++)

while, on the contrary, if ArraySetAsSeries(SignalLine,true) I should iterate with

for (int = Bars - 1; i >= 0; i--)

Is that right?

 
har:
Thank you mladen. This is because we use the ArraySetAsSeries() function then we should reversely iterate through the array, correct? Thanks!

That does not change anything - you will get element 0 with current value, and when a new current value comes, that element 0 of the SignalLine will be overwritten by the new value.

If SignalLine is a buffer, simply do not use the ArraySetAsSeries(SignalLine,false);

 

Hello mladen mr tools and Igorad

Hearty thanks for wisdom shared of yours and offered help.

I am too requesting your help again after a long gestation so hope would get your attention, your Indication T3 adaptive ma _ica.mq4 is my favourite indi for trading though visually good hard to follow manually due to non availability of time, so I wish someone to help me in coding an Expert advisor with that indicator arrows as buy sell signals to take orders with normal EA amenities like trailing, bep and sl,tp along with lot sizing.

Mladen and Igorad should be busy -if they can help I am gifted, if not someone willing to help can help me with this.If you need I can attach the indicator too. This is the page where the indicator T3 adaptive ma is located "https://c.mql5.com/forextsd/forum/167/t3_adaptive_ma_i-ca_2.01_alerts_nmc.mq4

I may also request with other indies with t3 cci but each indies working seperate in one EA with usage true or false option.Between anyone interested in lukas arrows and curves indicator based EA- still it needs improvement in analysing the real curve of the price turn, since its based on the ma, price is not analyzed but its all LIMITED in forex else everyone will be a millionaire by choice.

Hope it for live trading at the earliest with the help of forum friends.I tried to code it but I am not a programmer so all left in vain, hence I raise help request here.Without coding skills definitely its hard to impart very sophisticated indicators like T3 adaptive with super brain of mladen.Hard to code for a newbie and a non-techie.

Dream is big but what in hand is Tiny.

 

Oh okkkk... Thanks!

In C++ there were not this kind of problems..

 

Hello Mladen

Hope you would consider this help,pls have a look at this post -#5118 just one post above your post #5220.

It would a best gift for me with clear hands on it like yours.

 
har:
Oh okkkk... Thanks! In C++ there were not this kind of problems..

Since I always work with arrays the C/C++ like mode, the indexing in those arrays goes from 0 (oldest) to Bars-1 (newest) bar. If you use index 0 for the newest bar, it will always rewrite the 0th element

If you want to use it the C/C++ way, use an array, check if the size is equal to Bars, if not, resize it to Bars size, and then assign values to elements using Bars-i-1 as an index

If it is a buffer, the the indexing is inverted compared to C/C++ way and then you do not have to change anything in that loop - just remove the part that sets the array as series to false

 

Yep I saw! I have figured it out too.. Anyway just small differences between MQL and C++. There is a lot of C in MQL for what I saw! But I definitely like MQL

I wish to share my indicator once ready (and if I can understand if useful) and give an hand to you guys!

 
har:
Yep I saw! I have figured it out too.. Anyway just small differences between MQL and C++. There is a lot of C in MQL for what I saw! But I definitely like MQL I wish to share my indicator once ready (and if I can understand if useful) and give an hand to you guys!

Even they look-a-like they are far from being similar when you run them. ex4 is a P-code. Its execution speed is at least 100 time slower than an equvalent C/C++ counterpart

If you can, write the crucial parts in a C/C++ dll - it will be much faster

Reason: