 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
At the moment we have:
- Expert Advisor BlackBox, that can track two events;
- indicator Ticks, that reflects the tick chart.
We would like the Expert Advisor to be able to determine the fact of opening and closing an order in an instrument. An order may be opened manually, a pending order may work or it can be opened by another Advisor, it doesn’t matter for us. It can close when it reaches Take Profit, when Stop Loss works out, it can be closed manually or by the Advisor. It would be good to record everything in the log-file or in a distinct file. And it would be great to save the screenshots of such moments.
A year ago it was possible to record such moments only sitting at the monitor, or having created a complicated construction of several programs. But even is this case the success wasn’t guaranteed. A man cannot track several charts simultaneously for 24 hours a day. While video-grabbers can work only with one monitor, meaning that each chart would require a monitor.
But now in MT4 there is such function as ScreenShot(), which I called a remarkable function.
|
|
|
|
Very often it happened so that a trader opened an order with a set Stop Loss, went away from the terminal for some time and on returning back found out that the price touched the stop loss level and moved away in the needed direction. Or vice versa, the opened order reached some level of the minimum profit, after which the price returned to the opening level, and trader couldn’t venture to close the transaction. Most often in such cases the price developed then in the unfavorable direction, but how to distinguish these two moments? Or the third variant — we have an Expert Advisor that trades online and we would like to improve the algorithm of its exits after having watched transactions. In general in all these cases it would be desirable to save the video sequence, gallery of pictures which could be seen later in the slide show mode.
It is logic to combine the work of the Advisor BlackBox with recording such pictures, at the same time tracking the status of the indicators we need. We will save the Advisor with the name BlackBox-2 and will start modification. In the Ticks indicator there was one lack — the line Bid wasn’t displayed. We will add it with the help of our Advisor, and at the same time we will learn how to create and move the horizontal line, which we will call bidLine. It is naturally to insert this code in the EveryTick() function:
|
|
|
|
This example shows interaction between the Advisor and the indicator window. At first we seek for the line with the name bidLine, if we find it we move it, if not, we create it. You may delete this line and the Advisor will create it again.
Next, to record screenshots from the terminal we need to add parameters — to start recording a series of screenshots once the order is opened or closed, how many shots should be made for each of these events, how many ticks should be between shots.
|
|
|
|
Besides we introduced new global variables: orderShotCounter will decrease after each call of ScreenShot(), while shots will be made each time once tickRateCounter reaches the value 0 (i.e. each 10 ticks in this case). In all NumberShots (100) shots will be recorded for each event.
|
|
|
|
It is logic that the record will be kept in the function that is called on each tick.
This block will work only in case if orderShotCounter becomes more than zero, that’s why it is very simple to launch a series of shots – we need to determine the moment of opening or closing of the order and set the value orderShotCounter equal to the needed number of shots. Before shot its time and number are displayed with the help of Comment().
|
|
|
|
We had to add three new functions. The SymbolOrderTotals() function is simple, it counts the number of opened orders in our symbol. The AddNewOrderLine() and DeleteClosedOrderLine() functions were added for appearance, the first one added in the window of the Ticks indicator a horizontal line at the opening price of the new order, and the second one deletes this line.
|
|
|
|
The search of the new order is implemented as follows: we sort out all orders in the loop, for each order in our instrument we look for a horizontal line with the name equal to the order ticket, if such line isn’t found this order is our new order. In such case we create a horizontal line with the name is lineName=DoubleToStr(OrderTicket(),0). We had to use the DoubleToStr() function to modify the number of ticket OrderTicket() in the string type.
|
|
|
|
The color of the line depends on the type of orders, buy orders are drawn by the blue color, sell orders by the red color. The search of the last closed order is implemented in reverse order: all horizontal lines on the chart are sorted out, and for the lines that have description «order» the order is sought by the ticket. It is necessary to specify that one can define the closed order only with the help of the OrderCloseTime(), function, that for opened and pending order returns the value 0, i.e. there haven’t been yet the fact of deleting a pending order or closing a market order.
|
|
|
|
In practice we used the set of horizontal lines as an array for remembering the list of opened orders. Such method has its advantage: even if one closes the terminal or changes the profile — the list of opened orders will be saved in the form of a set of objects — horizontal lines.
The last detail — we will count the number of orders in our instrument and will plot the lines of orders (if there is such necessity) when the Advisor is launched for the first time. You may comment all superfluous log file entries by yourself, they are made for convenience of understanding and debugging the program. The logic of the Advisor is not all-purpose, an it won’t be able to track complicated combinations of opening/closing orders.
|
|
|
|
In order to make shots when the non-farm payroll statistic was reported I had opened a sell order on the demo account a few minutes before the news. The Advisor found out the new order and shooting began. A series of 100 shots in 800x600 format occupied a little more than 1Mb, but during strong moves the bidLine doesn’t manage to follow the price, and the terminal may hang up for several minutes on computers that are not enough large-powered. That’s why at first it is necessary to test the work of the Advisor under such conditions in order to prevent hindrances for trading on a live account.
|
|
|
|
You may download the code of the Expert Advisor here .
Go to article «Arrays and technical indicators on them».
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
+7 (495) 710-76-76
|
© 1998—2008 «Alpari» |
|