Something interesting, old thread - page 2

To add comments, please log in or register
drhouse7
704
drhouse7  
mladen:
Doc Use this one as a template. In the end you will find a working alerting code (there is no alert on current since this one is not a "buffering" one but is always calculating the current values). Alerting code is just above the text changing code so you can use same sets of conditions for alerts. I did not do that since I simply do not know what kind of alerts did you have in mind

I just started to fix it follow your template...thanks a lot.

Another question: why this indicator calculate all bars each time? It should calculate only the period of the highest MA...

or am I wrong?

Regards

doc

Mladen Rakic
106088
Mladen Rakic  

...

As far as calculation, it does not calculate all the bars

There is no "for" or "while" loop in in OnCalulate() at all, which means that it exclusively relies on the built in moving average and copies (now it is called so, a "CopyBuffer()") only last 2 values at a time. So it is OK as far as that is concerned.

dr.house7:
I just started to fix it follow your template...thanks a lot.

Another question: why this indicator calculate all bars each time? It should calculate only the period of the highest MA...

or am I wrong?

Regards

doc
drhouse7
704
drhouse7  
mladen:
As far as calculation, it does not calculate all the bars There is no "for" or "while" loop in in OnCalulate() at all, which means that it exclusively relies on the built in moving average and copies (now it is called so, a "CopyBuffer()") only last 2 values at a time. So it is OK as far as that is concerned.

Thanks,

I asked you this, cause the indicator is really slow if I set the maximum bar's number in my chart...any suggestion could be great!

Regards

doc

Mladen Rakic
106088
Mladen Rakic  

...

Doc

The indicator itself does not do that but it is using all in all 18 instances of indicators from 3 different time frames.

Apart from a big number of indicators used internally, in my experience metatrader 5 has some problems multi time frame operating (for example I saw examples when on one tick it returns all OK and on the next tick it returns an error "saying" that the target time frame does not exist, while the time frame did not change in the meantime at all) I do not know what does it do in cases when it fails to find a target time frame, but, if it resets, then you have the built in indicators calculating all the bars again. Unfortunately you can not do anything to improve that. As I said one "some maturity is still needed for metatrader 5 to become serious platform"

dr.house7:
Thanks,

I asked you this, cause the indicator is really slow if I set the maximum bar's number in my chart...any suggestion could be great!

Regards

doc
drhouse7
704
drhouse7  
mladen:
Doc

The indicator itself does not do that but it is using all in all 18 instances of indicators from 3 different time frames.

Apart from a big number of indicators used internally, in my experience metatrader 5 has some problems multi time frame operating (for example I saw examples when on one tick it returns all OK and on the next tick it returns an error "saying" that the target time frame does not exist, while the time frame did not change in the meantime at all) I do not know what does it do in cases when it fails to find a target time frame, but, if it resets, then you have the built in indicators calculating all the bars again. Unfortunately you can not do anything to improve that. As I said one "some maturity is still needed for metatrader 5 to become serious platform"

Thanks mladen for your patience,

I just add the final mq5 file of trend alexcud in the first post...

Have a nice weekend and best regards.

doc

drhouse7
704
drhouse7  
mladen:
Doc Use this one as a template. In the end you will find a working alerting code (there is no alert on current since this one is not a "buffering" one but is always calculating the current values). Alerting code is just above the text changing code so you can use same sets of conditions for alerts. I did not do that since I simply do not know what kind of alerts did you have in mind

Mladen,

how could I have an alert that warns only once and not every open bar?

Regards

doc

Mladen Rakic
106088
Mladen Rakic  

...

Doc

It would have to be written differently

For example, this would be the code for the template that would alert only when the condition changes :

if(AlertsOn)

{

if (uitog1v >= overPerc || ditog1v >= overPerc)

{

static datetime time1 = 0;

static string mess1 = "";

if (uitog1v >= overPerc) doAlert(time1,mess1,0," Alexcud changed to up");

if (ditog1v >= overPerc) doAlert(time1,mess1,0," Alexcud changed to down");

}

}

[/PHP]

As you can see time of the alert (originally it was time[rates_total-1]) is replaced with 0 (so it will not take into account the time of the bar issued, that way it will ignore a new bar) and it will alert only if the kind of the alert changed (the "up" or the "down") Just make sure that it can not have both conditions true (in that case you would not like what you get, since you would have 2 alerts on each and every tick )

For this kind of alerting you have to have an "opposite" alert too otherwise it would alert you once and it would not alert you ever more. In this case also, if you have a repeated alert after "retracing" it will not alert you either. For that (to alert you when it re-enters some kind of a "signal") you would need something like this[PHP]if(AlertsOn)

{

static datetime time1 = 0;

static string mess1 = "";

while (true)

{

if (uitog1v >= overPerc) { doAlert(time1,mess1,0," Alexcud changed to up"); break; }

if (ditog1v >= overPerc) { doAlert(time1,mess1,0," Alexcud changed to down"); break; }

doAlert(time1,mess1,0," Alexcud is in no trend zone"); break;

}

}

This way you would have one new kind of an alert (call it "retrace") which would ensure that when the "up" zone or the "down" zone are re-entered, you are alerted (new alert is not going to be raised until it retraces or has an opposite signal - so again it will alert only when the "kind" of alert changes)

PS: the last code will alert you on intial start too (since it will be in any of the 3 "states") but it will obey the rules described above

dr.house7:
Mladen,

how could I have an alert that warns only once and not every open bar?

Regards

doc
drhouse7
704
drhouse7  
mladen:
Doc

It would have to be written differently

For example, this would be the code for the template that would alert only when the condition changes :

if(AlertsOn)

{

if (uitog1v >= overPerc || ditog1v >= overPerc)

{

static datetime time1 = 0;

static string mess1 = "";

if (uitog1v >= overPerc) doAlert(time1,mess1,0," Alexcud changed to up");

if (ditog1v >= overPerc) doAlert(time1,mess1,0," Alexcud changed to down");

}

}

[/PHP]

As you can see time of the alert (originally it was time[rates_total-1]) is replaced with 0 (so it will not take into account the time of the bar issued, that way it will ignore a new bar) and it will alert only if the kind of the alert changed (the "up" or the "down") Just make sure that it can not have both conditions true (in that case you would not like what you get, since you would have 2 alerts on each and every tick )

For this kind of alerting you have to have an "opposite" alert too otherwise it would alert you once and it would not alert you ever more. In this case also, if you have a repeated alert after "retracing" it will not alert you either. For that (to alert you when it re-enters some kind of a "signal") you would need something like this[PHP]if(AlertsOn)

{

static datetime time1 = 0;

static string mess1 = "";

while (true)

{

if (uitog1v >= overPerc) { doAlert(time1,mess1,0," Alexcud changed to up"); break; }

if (ditog1v >= overPerc) { doAlert(time1,mess1,0," Alexcud changed to down"); break; }

doAlert(time1,mess1,0," Alexcud is in no trend zone"); break;

}

}

This way you would have one new kind of an alert (call it "retrace") which would ensure that when the "up" zone or the "down" zone are re-entered, you are alerted (new alert is not going to be raised until it retraces or has an opposite signal - so again it will alert only when the "kind" of alert changes)

PS: the last code will alert you on intial start too (since it will be in any of the 3 "states") but it will obey the rules described above

WOW!

What can I say? Thank you very very much for this great explanation! (very important for a beginner like me)

Last question:

is it difficult to insert an "nbars" input int parameter? For me it's difficult cause I don't know how to start, there's no calculation or loop like "for (int i=(int)MathMax... " to try to modify.

Best regards

doc

Mladen Rakic
106088
Mladen Rakic  

...

Doc

That indicator would need to be rewriten from the scratch then (since, as far as I see, it was written with only one idea : to calculate current values and all the code was done that way : object creations (they are created one by one instead of using some procedure for that that would make the code much easier to alter), temporary values, no calculating buffers nor arrays ...)

But then I have a question too: do you really need that? Since the concept of the indicator is to show current value, not historical values, how would it look with looped calculation and what would be the visual presentation then?

dr.house7:
WOW!

What can I say? Thank you very very much for this great explanation! (very important for a beginner like me)

Last question:

is it difficult to insert an "nbars" input int parameter? For me it's difficult cause I don't know how to start, there's no calculation or loop like "for (int i=(int)MathMax... " to try to modify.

Best regards

doc
drhouse7
704
drhouse7  
mladen:
Doc

That indicator would need to be rewriten from the scratch then (since, as far as I see, it was written with only one idea : to calculate current values and all the code was done that way : object creations (they are created one by one instead of using some procedure for that that would make the code much easier to alter), temporary values, no calculating buffers nor arrays ...)

But then I have a question too: do you really need that? Since the concept of the indicator is to show current value, not historical values, how would it look with looped calculation and what would be the visual presentation then?

Dear mladen,

I don't try to make a loop, but I would like to have a right calculation...probably as you said it's a metatrader problem, because if I attach this indy to a 10.000 bars chart and than to a 30.000 bars chart, I see a big difference (3x times slower) and I don't understand the reason cause it shouldn't count all bars but only what needed, so the max ma's value and nothing more...

How could I have something like this:

rates_total= max ma's value (so it calculates only the right bar's number needed)

Is it possible?

Regards

doc

To add comments, please log in or register