Sari la conținut
  • intrări
    18
  • comentarii
    51
  • citiri
    3.433.684

Breaking the candles in pieces: wax and string :D


tradelover

16.500 citiri

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:

 

blogentry-1272-1212645161_thumb.jpg

 

or if we switch to a bigger time frame:

 

blogentry-1272-1212645203_thumb.jpg

 

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

 

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. Please read carefully all the speeches inside of the source code. You will shot two rabbits with a single bullet (or as a pirate could say, ye'll cut to heads with a single stoke of the blade ....). First rabbit, ye have a toy to play with. As usual, my toys are sharp blades, if ye know how to use them. It could save ye a lot of pips. There is a lot of theory behind, about how to use such toy, but that is not the subject of this post. Go read some books. Second rabbit, the comments inside are so... didactic, that only a stupid student won't learn how to write his own indicator, by reading them. I spent a lot of time to make all the details and add the right comments. Don't disappoint me!

 

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

6 Comentarii


Comentarii Recomandate

Vizitator Guest

Postat

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 ?

Link spre comentariu
  • Management

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)

Link spre comentariu
  • Moderators

Hi all, and thanks for feedback.

 

Yo Stefan, ye did not read the comments inside of the source :P

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 :P

 

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.

 

As I got a lot of requests to write some tips about how this toy can be used in trading, I am going to extend this discussion into a new blog entry, about direct and reversed candles in different patterns, as long as I have time to type it. That will be some "pure theory" posts :D, no MQL code. I remember that in the past we had some talk on vamist about this, I put some bitmaps which I don't have anymore, and I have no time to search for them on the forum, does anyone know where that thread is? Please post a link here, as I have no time to make the sketches again now (about reversed and direct candles). That could be helpful as a start for the new topic.

 

Till then, happy pipping :D

Link spre comentariu
  • Moderators
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.

Link spre comentariu
Vizitator
Adaugă un comentariu...

×   Alipit ca text avansat.   Alipește ca text simplu

  Doar 75 emoji sunt permise.

×   Linkul tău a fost încorporat automat.   Afișează ca link în schimb

×   Conținutul tău precedent a fost resetat.   Curăță editor

×   Nu poți lipi imagini direct. Încarcă sau inserează imagini din URL.

×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.