Indicator Programming Question

 

Hello,

I'm hoping that someone here can point me in the right direction.

I'm programming an indicator that is displayed in its own window, and I would like to add a label object to the indicator. I know that the chart window is 0, and that sub-windows open up starting at number 1. I can create the object, set its text, anchor points, etc. but I can't seem to get it to display in the correct window! It always shows up in the chart window.

My question is, how does an indicator get its own window index number? In other words, how does an indicator get the number of the window that it is currently drawing in?

I know I can get WindowsTotal (which would work if I assume this indicator is always LAST, but it may not be). And there is WindowHandle (0,0) which at first glance, seems like it should work, but it doesn't. Which of course makes sense, because its the actual handle of the OS window not the indicator window number.

I'm really stumped, and while it seems crazy, I'm starting to think that I'm asking the impossible.

Thanks for the help...

-cubesteak

 
cubesteak:
Hello,

I'm hoping that someone here can point me in the right direction.

I'm programming an indicator that is displayed in its own window, and I would like to add a label object to the indicator. I know that the chart window is 0, and that sub-windows open up starting at number 1. I can create the object, set its text, anchor points, etc. but I can't seem to get it to display in the correct window! It always shows up in the chart window.

My question is, how does an indicator get its own window index number? In other words, how does an indicator get the number of the window that it is currently drawing in?

I know I can get WindowsTotal (which would work if I assume this indicator is always LAST, but it may not be). And there is WindowHandle (0,0) which at first glance, seems like it should work, but it doesn't. Which of course makes sense, because its the actual handle of the OS window not the indicator window number.

I'm really stumped, and while it seems crazy, I'm starting to think that I'm asking the impossible.

Thanks for the help...

-cubesteak

Like that:

IndicatorShortName("MY IND") in the init function

and then WindowFind("MY IND") in the object create/move function

Regards

Kale

 
Kalenzo:
Like that:

IndicatorShortName("MY IND") in the init function

and then WindowFind("MY IND") in the object create/move function

Regards

Kale

Worked like a charm! Thanks!

Unfortunately, it doesn't seem like the init function actually does anything until it returns. If I set the short name and try to get the window index right afterwards, it only returns -1, which I suppose makes sense. But, its a bummer that you have to put the WindowFind in the Start - as it is very inefficient. No need to look this up all the time. Oooo... Just realized I could use a few indicator scope variables and get away with an IF each tick, rather than the lookup... Meaning set something to be done only once, and use a second indicator scope variable to hold the index...

hmmm... Sorry, coding in my head now.

Anyway, thanks again!

-Cubesteak

 
cubesteak:
Worked like a charm! Thanks!

Unfortunately, it doesn't seem like the init function actually does anything until it returns. If I set the short name and try to get the window index right afterwards, it only returns -1, which I suppose makes sense. But, its a bummer that you have to put the WindowFind in the Start - as it is very inefficient. No need to look this up all the time. Oooo... Just realized I could use a few indicator scope variables and get away with an IF each tick, rather than the lookup... Meaning set something to be done only once, and use a second indicator scope variable to hold the index...

hmmm... Sorry, coding in my head now.

Anyway, thanks again!

-Cubesteak

U can put create/move object in your custom function and then just run that function when u need it - not at every thick in the start function.

 
Kalenzo:
U can put create/move object in your custom function and then just run that function when u need it - not at every thick in the start function.

Hi Kalenzo,

That's essentialy what I did, but didn't put it in a function... I simply needed to put some static labels on a window, so I just needed to create the object once and then be done, so I just did the following (with bool first_time and int win_handle already declared):

if (first_time){

win_handle = WindowFind("My Window");

first_time = false;

ObjectCreate("Label", OBJ_LABEL, win_handle, 0, 0))

blah blah blah...

}

Worked like a charm. Thanks again!

BTW - you don't happen to know of any way to specify which indicator draws on top of the others? Seems like it is limited to when / how they are added and that you can't set an explicit "Z-Level" so to speak...

Is that true?

Thanks again,

Cubesteak

 
cubesteak:
Hi Kalenzo,

That's essentialy what I did, but didn't put it in a function... I simply needed to put some static labels on a window, so I just needed to create the object once and then be done, so I just did the following (with bool first_time and int win_handle already declared):

if (first_time){

win_handle = WindowFind("My Window");

first_time = false;

ObjectCreate("Label", OBJ_LABEL, win_handle, 0, 0))

blah blah blah...

}

Worked like a charm. Thanks again!

BTW - you don't happen to know of any way to specify which indicator draws on top of the others? Seems like it is limited to when / how they are added and that you can't set an explicit "Z-Level" so to speak...

Is that true?

Thanks again,

Cubesteak

U sloved it in the good way, but if u reset the indicator that variable will be reseted and the object will be draw again. If u do it in that way:

if (ObjectFind("Label")!=-1){

win_handle = WindowFind("My Window");

ObjectCreate("Label", OBJ_LABEL, win_handle, 0, 0))

blah blah blah...

}

The object will not be draw again if it will be at the chart

As for your second question I don't know anything about to slove it.

 

code to make an indicator reset itself every thirty seconds

Very interesting thread, I couldn't help if I wanted to because I don't know any code at all. So....my problem is that I found an indicator that is awesome but it repaints itself unless you open it up and reset it everytime. So I was thinking some of you experts here could give me a hand and enter the code to reset this indicator every thirty seconds would be fine. I will attach here if I can figure out how to put on attachment. thank you in advance .

Files:
super1.ex4  3 kb
super1.mq4  2 kb
 

[lang=pl]Hi,

I want to help but i'm dont understand what you want. Arrow isn't depends of time when you print it.

New arrows turns uo during the time. What is the difference when you reset indicator?[/lang]

bigfoot1945:
Very interesting thread, I couldn't help if I wanted to because I don't know any code at all. So....my problem is that I found an indicator that is awesome but it repaints itself unless you open it up and reset it everytime. So I was thinking some of you experts here could give me a hand and enter the code to reset this indicator every thirty seconds would be fine. I will attach here if I can figure out how to put on attachment. thank you in advance .
 

Hi now i see the problem. I dont have time now but tommorow i 'll give you solution.

cheers,

grzesiek

g.pociejewski:
[lang=pl]Hi,

I want to help but i'm dont understand what you want. Arrow isn't depends of time when you print it.

New arrows turns uo during the time. What is the difference when you reset indicator?[/lang]
bigfoot1945:
Very interesting thread, I couldn't help if I wanted to because I don't know any code at all. So....my problem is that I found an indicator that is awesome but it repaints itself unless you open it up and reset it everytime. So I was thinking some of you experts here could give me a hand and enter the code to reset this indicator every thirty seconds would be fine. I will attach here if I can figure out how to put on attachment. thank you in advance .
 
bigfoot1945:
Very interesting thread, I couldn't help if I wanted to because I don't know any code at all. So....my problem is that I found an indicator that is awesome but it repaints itself unless you open it up and reset it everytime. So I was thinking some of you experts here could give me a hand and enter the code to reset this indicator every thirty seconds would be fine. I will attach here if I can figure out how to put on attachment. thank you in advance .

Hello,

It is not possible to change it to not repaint if you wish to keep this indicator showing the same signals.

Here is why it is not possible:

hhb = Highest(NULL,0,MODE_HIGH,dist,i-dist/2);

Basicly the part that makes this indicator repaint is this : i-dist/2, if you will change it to i+1 then it won't repaint at all, but it will not show you the same signals as befofe - this will be different idea.

The way this indicator is working is like looking in the future. It is going from i = X lets say 2000 to i = 0, where i = 0 is first bar from right side - so it is current not closed bar which may repaint. But this indicator is looking in the future, if your distance is 24 (default value coded inside indicator) then when you are at index 0 (i=0 => current bar) then the indicator is trying to look in the future like i = 0 - 24/2 => i=-12 there is no -12 bar on the chart. The last one is 0 there is nothing less than this.

Once it passes 12 bars like i = 12 then it wont repaint, but signals that are generated in last 12 bars WILL repaint. Check it - you may try to put it on visual test with some default ea, and then you will see how this indicator repaint. After 12th bar it wont repaint.

 

[lang=pl]hmm I think that i its possible.

You should onlny add

b1 = EMPTY_VALUE;

b2 = EMPTY_VALUE;

at begin of the for loop.

super1.1.mq4[/lang]

Kalenzo:
Hello,

It is not possible to change it to not repaint if you wish to keep this indicator showing the same signals.

Here is why it is not possible:

hhb = Highest(NULL,0,MODE_HIGH,dist,i-dist/2);

Basicly the part that makes this indicator repaint is this : i-dist/2, if you will change it to i+1 then it won't repaint at all, but it will not show you the same signals as befofe - this will be different idea.

The way this indicator is working is like looking in the future. It is going from i = X lets say 2000 to i = 0, where i = 0 is first bar from right side - so it is current not closed bar which may repaint. But this indicator is looking in the future, if your distance is 24 (default value coded inside indicator) then when you are at index 0 (i=0 => current bar) then the indicator is trying to look in the future like i = 0 - 24/2 => i=-12 there is no -12 bar on the chart. The last one is 0 there is nothing less than this.

Once it passes 12 bars like i = 12 then it wont repaint, but signals that are generated in last 12 bars WILL repaint. Check it - you may try to put it on visual test with some default ea, and then you will see how this indicator repaint. After 12th bar it wont repaint.
Files:
super1.1.mq4  2 kb
Reason: