Discussion of article "Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events"

 

New article Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events has been published:

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the seventh part, we added tracking StopLimit orders activation and prepared the functionality for tracking other events involving orders and positions. In this article, we will develop the class for tracking order and position modification events.

Let's compile the EA.
Set StopLoss in points and TaleProfit in points values to zero to open positions and place pending orders without stop levels. Set StopLoss for modification (points) and TakeProfit for modification (points) to 20 and 60 accordingly (the default values) — these StopLoss and TakeProfit levels are to be set by pressing the buttons.
Launch the EA in the tester and set pending orders. Then press the buttons for setting StopLoss and TakeProfit one after another. The levels are set and the appropriate entries appear in the journal. Next, enable trailing and observe the orders as they follow the price and the appropriate entries appear in the journal. Positions triggered by orders have their StopLoss levels trailed, and the appropriate entries appear in the journal.

Netting:


Hedging:

Author: Artyom Trishkin

 

Good evening, Artem. You live and learn forever! And I am learning, using your work as a methodological material. Thank you for your considerable labour and experience.

Of course, not without misunderstandings, and to be even more precise - the more I learn, the more I do not understand.

In the attached file I tried to modify your Expert Advisor TestDoEasyPart08, adding a custom indicator, also your iCrossAD.

I used the iCustom(asymbol.Name(), _Period, "iCrossAD") function;

   CrossAD = iCustom(asymbol.Name(), _Period, "iCrossAD");
   if (CrossAD == INVALID_HANDLE)
   {
      Print("Failed to create iCrossAD indicator descriptor!");
      return(INIT_FAILED);
   }

Then I tried to copy the data from the indicator to the EA buffers and check how well I managed to do it.

void OnTick()
  {
//+------------------------------------------------------------------+//////////////////////////////
   int      buf_size = 30;
   double   Buf_Arrow_Sell[], Last_Arrow_Sell;
   double   Buf_Arrow_Buy[], Last_Arrow_Buy;
   
   ArraySetAsSeries(Buf_Arrow_Sell, true);
   ArraySetAsSeries(Buf_Arrow_Buy, true);
   
   if (CopyBuffer(CrossAD, 3, 0, buf_size, Buf_Arrow_Sell) != buf_size || ArraySize(Buf_Arrow_Sell) != buf_size)
   {  
      Print("Failed to copy data from iCrossAD correctly");
      return;
   }
      else Last_Arrow_Sell = Buf_Arrow_Sell[0];
   
   if (CopyBuffer(CrossAD, 2, 0, buf_size, Buf_Arrow_Buy) != buf_size || ArraySize(Buf_Arrow_Buy) != buf_size)
   {  
      Print("Failed to copy data from iCrossAD correctly");
      return;
   }
      else Last_Arrow_Buy = Buf_Arrow_Buy[0];
      
//+------------------------------------------------------------------+
Comment("Outputting fractal data.", 
         "\n Last_Arrow_Buy     = ",Last_Arrow_Buy,
         "\n ---------------------- ",
         "\n Last_Arrow_Sell    = ",Last_Arrow_Sell
         ); 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+//////////////////////////////

All this trick does not want to work, please tell me where I am doing wrong and how to do it really ????.

Files:
 
The idea is to use your TestDoEasyPart08 or its future, more powerful modifications as a basis, add to it data from various indicators and, depending on their combinations, manage trading by programmatically/virtually clicking on the buttons, if the course of trading does not please the terminal administrator, he can intervene manually, using the same buttons and mouse.
 
Sergey Voytsekhovsky:

Good evening, Artem. You live and learn forever! And I am learning, using your work as a methodological material. thank you for your considerable labour and experience.

Of course, it is not without misunderstandings, and to be even more precise - the more I learn, the more I don't understand.

In the attached file is an attempt to modify your Expert Advisor TestDoEasyPart08, adding a custom indicator, also your iCrossAD.

I used the function iCustom(asymbol.Name(), _Period, "iCrossAD");

Then I tried to copy the data from the indicator to the EA buffers and check how well I managed to do it

All this trick does not want to work, please tell me where I am doing wrong and how to do it really ???.

"Doesn't want to work" - what exactly doesn't work?

This is what I would do at the global level:

   int      buf_size = 30;
   double   Buf_Arrow_Sell[], Last_Arrow_Sell;
   double   Buf_Arrow_Buy[], Last_Arrow_Buy;

This one in OnInit():

   ArraySetAsSeries(Buf_Arrow_Sell, true);
   ArraySetAsSeries(Buf_Arrow_Buy, true);

And check if the indicator ever has values in the buffers at the zero bar - you only check them at the zero bar. I don't remember what it gives out there, and on what bar.

 
  • "what exactly is not working...?" - At this stage I am trying to see the values of the last Up and Down arrows from the indicator in the Comments. If I achieve this, I will be able to compare them by time, and therefore I will know which one was the last, and therefore "current". This can be considered as a signal when changing the value or as a filter for other signals (can/can't). But here's the trouble, I can't get these values into the Comments and even more - I can't see the Comments themselves, the text should be visible?

  • " This is what I would do on a global level: ..." - Moved it, tried to realise why it's like that, I think I got it, thanks for the science!!!!

  • "This is what I would do in OnInit(): ..." - Moved it, thanks a lot, I'll remember it.

  • "And check if the indicator ever has values in the buffers at the zero bar - ..." - I'll try to organise a comment inside the indicator and run the indicator to see the value itself with my eyes, but how will they then be displayed on one chart? Activate the indicator on a separate chart?

  • "you check them only on the zero bar ..." - Yes, I realise, by accessing the array with these arrows, I will probably get almost always an empty value and only rarely, when an arrow is drawn, the value will not be empty. So I need to organise either a switch of the last signal on the indicator side, or run a loop, write out the last values up to the first non-empty one here in the Expert Advisor? That is, exactly the same switch as on the indicator side?????

Please help with the Comment, I can't understand why it is not displayed!!!!

Files:
 
Sergey Voytsekhovsky:
  • "what exactly is not working...?" - At this stage I am trying to see the values of the last Up and Down arrows from the indicator in the Comments. If I achieve this, I will be able to compare them by time, and therefore I will know which one was the last, and therefore "current". This can be considered as a signal when changing the value or as a filter for other signals (can/can't). But here's the trouble, I can't get these values into the Comments and even more - I can't see the Comments themselves, the text should be visible?

  • " This is what I would do at the global level:" - Moved it, tried to realise why it's like this, I think I got it, thanks for the science!!!!

  • "This one in OnInit():" - Moved, thanks a lot, I'll remember.

  • "And check if the indicator ever has values in the buffers at the zero bar - ..." - I'll try to organise a comment inside the indicator and run the indicator to see the value itself with my eyes, but how will they then be displayed on one chart? Activate the indicator on a separate chart?

  • "you check them only on the zero bar ..." - Yes, I realise, by accessing the array with these arrows, I will probably get almost always an empty value and only rarely, when an arrow is drawn, the value will not be empty. So I need to organise either a switch of the last signal on the indicator side, or run a loop, write out the last values up to the first non-empty one? I mean exactly the same switch as on the indicator side????

Please help with the Comment, I can't understand why it is not displayed!!!!

What is written in the "Experts" log? Are indicator handles created?

 
Artyom Trishkin:

What is written in the "Experts" journal? Are indicator handles created?

Good afternoon. Yes, the handle is created, it is equal to 10.

I have made a little progress (very little!). There are Comment records

There are Print() records


2019.05.19 17:31:13.127 2018.01.02 00:00:00 Handle iCrossAD = 10

2019.05.19 17:31:13.580 2018.01.02 09:00:00:00 Copied data from the 2nd buffer of the iCrossAD indicator

2019.05.19 17:31:13.580 2018.01.02 09:00:00 CrossAD = 10, period_find = 400, Last_Arrow_Buy = 1.797693134862316e+308

2019.05.19 17:31:13.580 2018.01.02 09:00:00 Copied data from the 3rd buffer of iCrossAD indicator

2019.05.19 17:31:13.580 2018.01.02 09:00:00 CrossAD = 10, period_find = 400, Last_Arrow_Sell = 1.797693134862316e+308

2019.05.19 17:31:13.580 2018.01.02 09:00:20 Copied data from the 2nd buffer of iCrossAD indicator

2019.05.19 17:31:13.581 2018.01.02 09:00:20 CrossAD = 10, period_find = 400, Last_Arrow_Buy = 1.797693134862316e+308

2019.05.19 17:31:13.581 2018.01.02 09:00:20 Copied data from the 3rd buffer of iCrossAD indicator

2019.05.19 17:31:13.581 2018.01.02 09:00:20 CrossAD = 10, period_find = 400, Last_Arrow_Sell = 1.797693134862316e+308


Two buffers in the indicator, from which the data are copied, contain the values to which the indicator arrows are set. They are written there at the moment of arrow setting. Accordingly, I conclude that they should be filled with double prices at the moment of arrow formation. But for some reason I get a cosmic figure, if I'm not mistaken, it is the maximum of possible double values in MT5.

But I tried and achieved this in the tester, there were no quotes yesterday and today, today is Sunday.

If there is a desire, please help me to understand. Expert Advisor and indicator attached to the post. The Expert Advisor has been changed, I wrote about it above, the indicator is also yours, there are no changes in it.

Files:
 
Sergey Voytsekhovsky:

Good afternoon. Yes, the handle is created, it is equal to 10.

I have made a little progress (very little!). Comment records have appeared

There are Print() records


2019.05.19 17:31:13.127 2018.01.02 00:00:00 Handle iCrossAD = 10

2019.05.19 17:31:13.580 2018.01.02 09:00:00:00 Copied data from the 2nd buffer of the iCrossAD indicator

2019.05.19 17:31:13.580 2018.01.02 09:00:00 CrossAD = 10, period_find = 400, Last_Arrow_Buy = 1.797693134862316e+308

2019.05.19 17:31:13.580 2018.01.02 09:00:00 Copied data from the 3rd buffer of iCrossAD indicator

2019.05.19 17:31:13.580 2018.01.02 09:00:00 CrossAD = 10, period_find = 400, Last_Arrow_Sell = 1.79769313486262316e+308

2019.05.19 17:31:13.580 2018.01.02 09:00:20 Copied data from the 2nd buffer of iCrossAD indicator

2019.05.19 17:31:13.581 2018.01.02 09:00:20 CrossAD = 10, period_find = 400, Last_Arrow_Buy = 1.79769313486262316e+308

2019.05.19 17:31:13.581 2018.01.02 09:00:20 Copied data from the 3rd buffer of iCrossAD indicator

2019.05.19 17:31:13.581 2018.01.02 09:00:20 CrossAD = 10, period_find = 400, Last_Arrow_Sell = 1.79769313486262316e+308


Two buffers in the indicator, from which the data are copied, contain the values to which the indicator arrows are set. They are written there at the moment of arrow setting. Accordingly, I conclude that they should not be filled with double prices. But for some reason I have a cosmic figure, if I'm not mistaken, it is the maximum of possible double values in MT5.

However, I tried and achieved this in the tester, there were no quotes yesterday and today, today is Sunday.

If there is a desire, please help me to understand. Expert Advisor and indicator attached to the post. The Expert Advisor has been changed, I wrote about it above, the indicator is also yours, there are no changes in it.

Well, here we are discussing questions about the library, not trivial ignorance about empty values of indicator buffers. EMPTY_VALUE == DBL_MAX
 
Artyom Trishkin:
Well, here we discuss questions about the library, not trivial ignorance about empty values of indicator buffers. EMPTY_VALUE == DBL_MAX

Got it, heard it, thank you. I think I knew something about empty values, I'll study the question.

If it is not appropriate here, can you recommend some thread where I can get answers to such lamer questions from you or your colleagues?

If there is no such place, it would probably be worth creating one.

Sorry for disturbing you, but there are no lively conversations here, there is no one to interfere, and who but the author will give the best advice.

Besides, I am trying to use your library. Primitive, of course, but as best I can, sorry.

 
Sergey Voytsekhovsky:

Roger, heard you, thanks. I thought I knew something about empty values, I'll look into it.

If it is not appropriate here, can you recommend some other thread where I can get answers to such lamer questions from you or your colleagues?

If there is no such place, it would probably be worth creating one.

Sorry to bother you, but there are no lively discussions here, there is no one to disturb, and who but the author will give the best advice.

Besides, I am trying to use your library. Primitive of course, but as I can, sorry.

For questions not related to the library, please write here:

Любые вопросы новичков по MQL4, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4, помощь и обсуждение по алгоритмам и кодам
  • 2016.11.09
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
Artyom Trishkin:

For questions not related to the library, please post here:

Thanks a lot, went, looked, read. Just what I need, I will use it.

This website uses cookies. Learn more about our Cookies Policy.