[01 martie 2015] Vamist este prima si cea mai mare comunitate Forex din Romania. A luat nastere in 2005 si de-a lungul timpului a trecut prin mai multe transformari. Acum, dupa 10 ani, primim orice fel de traderi si investitori. Deci, indiferent daca tranzactionezi sau investesti in actiuni, valute, marfuri sau orice alt instrument, bine ai venit!

Vamist se transforma in comunitatea traderilor retail. Aceasta versiune a forumului va fi in continuare accesibila pentru oricine, dar numai in format read only.

Noua adresa este vamist.ro. Te asteptam acolo la discutii generale despre trading.

# Breaking the candles in pieces: wax and string :D

Posted by tradelover, in MQL Treasure Cave 05 June 2008 · 15199 views

MQL Treasure Cave
Yarrr, ahoy me' pip pillager mates!

Haven't ye miss me? Yeah, I know, not at all... well.. today me be in a good mood! The market seems to be back in shape, and we just went out for booty. We came back with a treasure chest of few hundred pips from our favorite pairs, so now is the time to relax, no need to do any carpenting for our sloops, as they run out of the battle clean, this time.

Now is the time to relax and learn some MQL. Are ye ready? Wouldn't be fine to have a tool to break each candle in pieces? That is to put our magnifying glass on a H4 candle, and see at once all H1 or all M30 candles that added up to the main one in H4? That without searching the smaller time frames by hand. Without spending days and hours to make correspondence between opening date and time in different charts... well... in a work, just click and see?

Could it be useful? Yes it could, as shown in the following sketches:

or if we switch to a bigger time frame:

Yarrr... I bet my scimitar ye'll say that looks wonderful... And here is the toy that made the paints, beside of paintbrush program that I used to add the comments:

Detail_View_v1.1.mq4 (38.24KB)

Have fun! And say thanks when ye port back with yer coffers full of booty...

• 0

Maestre, esti genial!
• 0
• Quote
• Report
Guest
Hi there,

First of all your talent sir is IMPRESSIVE.

Secondly, for some reason I can't drag this damned arrow anywhere...any clue why ?
• 0
• Quote
• Report
Tradelover, the toy doesn't automatically refresh or I'm doing something wrong? To have the bars updated, I need to move the arrow a little bit.

@Guest, first you need to double click on the arrow and then drag-it (after you see a rectangle around the arrow)
• 0
• Quote
• Report
Hi all, and thanks for feedback.

Yo Stefan, ye did not read the comments inside of the source
It says gray on white that:

//store pointer's position, we should not waste the time to paint
//the screen every time, but only when the pointer was moved

well, this only in the case you did not change the default colors of MT4, otherwise the gray would be something else

That's right, the chart does not refresh as long as the pointer is not moved. That is not a bug, but it was designed like that, to get rid of the burden of calculus (MT4 need quite a time to search into the charts that are not open on the screen, i.e. to look into the smaller TF chart in our case). There is no reason to refresh, as long as the candles in the past should never change. Once painted they would stay on the screen as long as the pointer is not moved. This is in your advantage, you can "work" with the objects on the screen, eventually by hand, eventually delete few bars, and keep only important points, as the turning points of a reversed candle, for example, or whatever, or even use them in another expert (this is unlikely, as long you can access the data directly, if you have another expert). You also can skew the chart vertically, move the pointer - the detail is refreshed - then skew the chart back, to have the texts or candles arranged as you want. This is extremely useful when you have more than one candle decomposed on screen (i.e. more indicators added to the same chart), to arrange them in such a way to be convenient for reading.

I also had a long discussion on messenger with ener and he suggested to refresh the chart every time when a candle is completed on the smaller TF. Like for example if I am watching M30 but have a detail view in M5, then the detail view should be refreshed every 5 minutes. Well, this in my mind is same as refreshing it at every tick, there is no reason for it.

There will be no upgrade to refresh the chart at every tick, that is first of all not useful (you won't be able to move the stuff around, they would jump back to the old position when a new tick come) and second off all, the bars once painted, they won't change, for the past, third of all, this is not easy to be done, as there is no "timer" function in MQL, and the start() function is executed only when a tick come. That is, you can not execute the start() function in "between" the ticks. The start() function of every indicator/expert is just a kind of OnPriceMoved() event. There should be much better if MQL could have implemented such other events like OnObjectMoved(), OnMouseClick(), OnChartViewChanged(), or else, that could allow us to execute some code immediately when we move the pointer, for example, or when we scroll the chart. But this is not possible without using the right .DLL library. That means, making one... I have done some work in this direction, but unfortunately it is not distributable.

That is the reason why the chart is not refreshed immediately after you move the pointer, but it needs to wait for the next tick to come. When market is in a sleepy period, as during the night, this is annoying a lot, I know, but it is the only solution available now.

However, as ener pointed out, it could be useful to make the refresh if the pointer is pointing the last candle on the chart. In this case the candle is "under construction" in real time, so it make sense to update its detailed view periodically, as new candles are added to the smalled TF during the big one is built by the price action. It could be also useful to MOVE the pointer automatically, to stay on the last candle, if it was placed there, as new candles are added to the chart by the price action. Well, first part of this is quite easy to be done. You have to look in the code for a test like

//got rid of it! if we are here, the pointer is in the past
//was it moved?
if (ObjectGet(MagicNumber+"Pointer",OBJPROP_TIME1)==pointerTime &&
ObjectGet(MagicNumber+"Pointer",OBJPROP_PRICE1)==pointerPrice)

//nope, it was not moved, it has the same time and date and
//price like one year ago... :P, nothing to do, we are out of here
return (0);

and substitute it with

//got rid of it! if we are here, the pointer is in the past
//was it moved?
if (ObjectGet(MagicNumber+"Pointer",OBJPROP_TIME1)==pointerTime &&
ObjectGet(MagicNumber+"Pointer",OBJPROP_PRICE1)==pointerPrice &&
ObjectGet(MagicNumber+"Pointer",OBJPROP_TIME1)!=Time[0])

//nope, it was not moved, it has the same time and date and
//price like one year ago... :P, nothing to do, we are out of here
return (0);

Initially, we exit if the pointer was not moved. The updated version will exit if the pointer was not moved, but only in the case it was not positioned on the last candle. In this case, the exit branch will not be taken, and the code will stay in, and re-paint the bars.

As now is weekend, I can't really test how this works in real time, due to the market is closed. It could be that you see some "flickering" on the screen when the bars are updated, when the ticks will hurry into your chart (during market agitation). And moreover, this small update won't move the pointer to keep it on the last candle, when new candles are added to the chart. You still have to move it by hand, every time when a new candle is formed.

To keep the pointer on the last candle always, that is a bit more complicate to do, as you need to keep tracking the pointer position in code. When a new candle is formed, everything is shifted left, all candles, all objects, your pointer. The code must keep "tracking" the pointer position (time axis) AND the time of the last candle. If the position is Time[1] and a new candle was just formed (i.e. its Time[0] is different of "tracked time"), then "tracked time" will store the new time, and the pointer will be forced to move one candle to the right (back to "last candle", Time[0]). Well, this brings up another problem: what if the user wants to place the pointer to last CLOSED candle? This is the candle before the last one (last one is not closed yet, so from my point of view it could be reasonable to place the pointer at the candle having Time[1], it could be more useful for a trader). Welllll.... in that case our algorithm described above will move the pointer to last candle (with Time[0]) immediately after next tick... There is no simple way to know that the pointer was placed to ante-last candle by the user (in this case let it there!!!) or it was placed to ante-last candle by a candle-shift process (i.e. the user placed it on the last one, and last one finished, so it is now ante-last and a new one was started, in this case the pointer must be moved one candle to the right). The only solution to this problem involves keeping tracks of the pointer and last bar's time, comparing it with the time when the pointer was moved, or such equivalent method.

There will be a V1.2 version upgrade soon, to address this issue, but first let me convince myself that such a feature is useful. The reason to make this toy was initially to be able to spot reversed candles inside the belly of the trend, to be able to spot its retracement/reversal points. Well... you don't try to spot reversed candles before a fractal point to be formed... so placing the pointer on last 1, 2, 3 candles is - in my view - not so useful.

Till then, happy pipping
• 0
• Quote
• Report

Hi there,

First of all your talent sir is IMPRESSIVE.

Secondly, for some reason I can't drag this damned arrow anywhere...any clue why ?

Thanks a lot mattey!

As I wrote in the main post:

"All ye have to do is to put in yer indicator's folder, open yer favorite chart, add the indicator (single time, or more instances of it on the same chart) and then select the red pointer on the right and move it anywhere on the chart"

In MT4 ye can't move objects around before selecting them. That is, ye can only move (drag with the mouse) selected objects. To select/unselect an object, you can double click it, or rightclick (if selected) and choose "deselect" from the pull down menu, or right click on the chart and press "objects", or just press ctrl+B to get objects properties dialog box (once there, you can input any price/time parameters for object, change their selection by marking the checkbox in front of their name, etc etc).

Once selected (by any method above) you can move an object by dragging it with your mouse, or directly editing its time/price properties. There is no way to read or edit the selection property of an object by software, i.e. from inside of an EA (MetaQuotes promised to address this issue with a future release number of MT4 platform, but God knows when), so it is no way for me to select/deselect an object by software. Once selected (by you), an object will stay that way until you unselect it. And viceversa. So I could not paint the pointer ready-selected, that will cost you an additional double click on it, as Stefan said.

Much later edit: well, sorry, it IS a way to deselect an object by software, and this method I used in M-PF indicator posted here around, long time ago: read an object type and position, and all other properties that you can get (this does not include "selection", there is no "selection" property readable by MQL directly), then delete the object using ObjectDelete() fucntion, and create a new object using ObjectCreate() function, having the same position, type and properties like the old one. The new object is allways created "unselected". This method I used to clear multiple selections, in M-PF indicator. But this has nothing to do with our case here, I wrote this just for the sake of clarifying things.
• 0
• Quote
• Report
Tradelover, for the reversed candles I think you are looking for this post: http://forum.vamist....s...post&p=5329
• 0
• Quote
• Report