stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

ObjectGetValueByTime - help needed
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5482
Page 1 of 1
Author:  Bruster400 [ Wed Jun 20, 2018 10:03 am ]
Post subject:  ObjectGetValueByTime - help needed

Hi,

I've written a mod of the zigzag indicator that draws an equidistant channel based on the most recent confirmed zigzag points (not the very recent "wet paint" one). It's very simple, I just look back for the recent point's values and load them into an OBJ_CHANNEL - for which I've used the documented function. Works fine.

I now want to draw a pair of parallel lines outside this channel at the same vertical distance away as the vertical width of the original channel - so in effect, I'll get 4 parallel lines equidistant apart with that distance being set by the original channel. Simple enough surely.... I just have to find the vertical separation of the channel and add/subtract this from two points on each channel line and draw trend lines. The slight problem is that one of the channel lines only has one known point (the OBJ_CHANNEL function automatically draws it parallel without having to be given two points). The other issue is that none of the three known points are vertically aligned. Even so, I thought this would be easily solved using -

Code: Select all

double  ObjectGetValueByTime( 
   long       chart_id,      // chart ID 
   string     object_name,   // object name 
   datetime   time,          // time 
   int        line_id=0      // line ID 
   );
So I used this code to try to give me the two price values of the channel at one particular time (time_1):

Code: Select all

double price0 = ObjectGetValueByTime(ChartID(),channelName,time_1,0);
double price1 = ObjectGetValueByTime(ChartID(),channelName,time_1,1);
As you can see, I've used line_id = 0 and 1 to indicate the two lines - BUT the second one is not returning a correct value so this might be the problem? I can't find anything in the docs to say what the line ID's are.

By commenting the values of price0 and price1 I can see that price0 is correct but price1 doesn't relate to the chart - it's a massive number either positive or negative - and it's not EMPTY_VALUE. I haven't finished the code for drawing the extra lines because until I get these price values correct there's no point doing so.

So my (rather long winded, sorry) question is: Has anyone used ObjectGetValueByTime on a channel before and if so, how did you get it to report the correct value for the second line?

Thanks

Bruce
Author:  thetrader [ Wed Jun 20, 2018 2:04 pm ]
Post subject:  ObjectGetValueByTime - help needed

If you hard code it in, it does return a value for both lines.

double price0 = ObjectGetValueByTime(0,"channelName123",D'2018.06.20 00:00',0);
double price1 = ObjectGetValueByTime(0,"channelName123",D'2018.06.20 00:00',1);

Print("price0: ",price0" price1: ",price1);

Regards
Author:  Bruster400 [ Thu Jun 21, 2018 7:15 am ]
Post subject:  ObjectGetValueByTime - help needed

Hi,

Thanks for helping.... but I can't replicate your success. I've hard coded the object name and date as you've done - in my case:

Code: Select all

double price0 = ObjectGetValueByTime(ChartID(),"channel333",D'2018.06.19 12:00',0);
double price1 = ObjectGetValueByTime(ChartID(),"channel333",D'2018.06.19 12:00',1); 
and yet I'm still getting a strange value for id=1:
2018-06-21_0809.png
I've checked that the times I've used are open times of bars and I've tried different timeframes and different symbols but I can't get the second line value to be correct. All very strange.

Thanks for your help though, I'll let you know if I sort it! :-)

Bruster
Author:  Bruster400 [ Thu Jun 21, 2018 10:46 am ]
Post subject:  ObjectGetValueByTime - help needed

Partly solved. I've managed to get values for both lines at one time by making all prices and times globals and moving the calculations out of the channel drawing section. No idea why this works but it does. However, it only works for one of the time points! If I use the time of either of the other two points used in the channel then ObjectGetValueByTime delivers 0.

I'm sufficiently frustrated by this that I'm going to leave it for now and find another way.
Author:  SteveHopwood [ Sat Jun 23, 2018 7:51 pm ]
Post subject:  ObjectGetValueByTime - help needed

Bruster400 ยป Thu Jun 21, 2018 10:46 am wrote:Partly solved. I've managed to get values for both lines at one time by making all prices and times globals and moving the calculations out of the channel drawing section. No idea why this works but it does. However, it only works for one of the time points! If I use the time of either of the other two points used in the channel then ObjectGetValueByTime delivers 0.

I'm sufficiently frustrated by this that I'm going to leave it for now and find another way.
This will not help. I am merely offering some sympathy.

Compared to writing a 50 line custom indi, coding a 30,000 line EA is a doddle.

Indis are written by strange people accustomed to Speaking in Tongues. They have weird brains able to comprehend the strange dialect required to code them.

I am convinced that Rene, for example, is in fact an alien computer whose space ship crashed to earth a few years ago and which is keeping its existence secret by pretending to be a human who understands this stuff and making major contributions to our understanding of arcane coding, whilst awaiting rescue by his fellow galactic-trotting computers.

Not helpful at all I know; just saying that I feel your pain.

:xm: :rocket:
Author:  renexxxx [ Sun Jun 24, 2018 7:37 am ]
Post subject:  ObjectGetValueByTime - help needed

Hello Bruster,

Apologies for the late reply but I was taking my spaceship for a spin ...

The problem you seem to have is that the ObjectGetValueByTime() function is called too early, straight after the ChannelCreate() operation. The system hasn't had the time yet to properly initialize the channel, let alone reading data from it. I noticed that you put a Sleep(500) in there ... however, custom indicators don't sleep.

I have modified your code a little bit such that it uses the OnTimer() function to see if a new channel has been created. The OnTimer() function runs every second -- plenty of time for the new channel object to be initialized. A consequence of this was that I had to make several variables global as you can't pass arguments to the OnTimer() event handler. Once you are satisfied that this works, you can remove the 'if (true)' and replace it with the original if-statement.

Have a play.
Author:  Bruster400 [ Tue Jun 26, 2018 3:11 pm ]
Post subject:  ObjectGetValueByTime - help needed

Rene,

Once again, you've made me realise how far I have still to go on learning to code mql4!! Not only do you know how it all works but it seems you also know how it doesn't work!!! :shock: I hadn't considered that I wasn't getting figures because the object wasn't created - I'd wrongly assumed my "sleep" was covering that. Seems not! Especially since I now know that indicators don't sleep!

So, I've tried your example, which makes perfect sense and yes, and it works like a charm. When I next get chance I'll finish off the indicator by adding the outer two lines and I'll post the finished result here.

Thank you so much once again,

Bruster
Author:  Bruster400 [ Tue Jun 26, 2018 10:42 pm ]
Post subject:  ObjectGetValueByTime - help needed

Well, with a lot of help, it's actually working now. This indicator draws an equidistant channel based on recent ZigZag points - the user defines which ones using "Drawbackpeaks". The default of 1 is the most recent "set" points, excluding the "wet" recent point which might repaint. I use this default setting to look for new trades but it's also useful to be able to send the channel back in time to allow for a visual backtest.

I use this indi for spotting two types of trade. Here's a couple of examples from current H1 charts:

The first is a channel bounce - After setting 3 points to form the main channel, price moves away from the 3rd channel point and should then rejects from the other side:
2018-06-26_2317.png
Or a failed swing - which is where you're expecting price to go to the other side of the channel to form a "bounce" trade but it rejects early, before it reaches the other side and then breaks out of the channel:
2018-06-26_2326.png
I still end up drawing a lot of manual channels but this indi is a great help in spotting them initially and setting the target lines. If you're new to ZigZag, please make sure you understand how the most recent point re-paints before using this - you have to make sure the main channel is based on "set" points.

Enjoy.

Bruster
Author:  Eamonn [ Wed Jun 27, 2018 9:49 am ]
Post subject:  ObjectGetValueByTime - help needed

Hi Bruster,Renexxxx,

great indicator :!!: :!!: :!!: :!!: :!!:





:smile: :smile: :smile:


Cheers

Eamonn.
All times are UTC Page 1 of 1