How to figure out the close price when position ran into stop loss? - page 2

To add comments, please log in or register
Doerk Hilger
1062
Doerk Hilger  
Icham Aidibe:

Thank you. But this is a workaround and does not solve the problem when there are multiple entries at the same price. 

Doerk Hilger
1062
Doerk Hilger  

Which is which? 3 Positions at different prices, but all closed with an SL at the same price. 

Sample

Icham Aidibe
11287
Icham Aidibe  
Doerk Hilger:

Thank you. But this is a workaround and does not solve the problem when there are multiple entries at the same price. 

No it's not a workaround, looping thru the history is the only way to do it. Then, it's possible to get the position id of an entry with DEAL_POSITION_ID & use HistorySelectByPosition as you did.

https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties#enum_deal_property_integer
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by properties that allow to obtain information about it. In order to read values of properties, functions of the Identifier of a position, in the opening, modification or closing of which this deal...
Doerk Hilger
1062
Doerk Hilger  
Icham Aidibe:

No it's not a workaround, looping thru the history is the only way to do it. Then, it's possible to get the position id of an entry with DEAL_POSITION_ID & use HistorySelectByPosition as you did.

If this is the only way, MQ must be kidding. I don´t know what I should look for in the history, because I don´t have the position ID that I need. What I have is my original position ID, and absolutely no information about the SL, nor vice versa from the SL deal to the original one. 

Doerk Hilger
1062
Doerk Hilger  
Icham Aidibe:

No it's not a workaround, looping thru the history is the only way to do it. Then, it's possible to get the position id of an entry with DEAL_POSITION_ID & use HistorySelectByPosition as you did.

https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties#enum_deal_property_integer

If I am wrong, please tell me. Once again: The only thing I know in my EA is the Position ID. How can I find/identify the corresponding SL deal in the history? 

Doerk Hilger
1062
Doerk Hilger  
Or did you mean, that DEAL_POSITION_ID returns the original position when I loop through the history?
Icham Aidibe
11287
Icham Aidibe  
Doerk Hilger:

If I am wrong, please tell me. Once again: The only thing I know in my EA is the Position ID. How can I find/identify the corresponding SL deal in the history? 

HistorySelect list all the deals, you can filter symbols, profit etc ... and get the position id from there.

THEN HistorySelectPosition will retrieve the list of deals involved in that position. You have to reloop thru. 

Icham Aidibe
11287
Icham Aidibe  
//+------------------------------------------------------------------+
//|                                                      Example.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\DealInfo.mqh>
CDealInfo         m_deal;   
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   HistorySelect(0,TimeCurrent());
   for(int i=0;i<HistoryDealsTotal();i++)
     {
      if(m_deal.SelectByIndex(i))
        {
         if(m_deal.Symbol()=="EURUSD")
           {

            if(HistorySelectByPosition(m_deal.PositionId()))
              {
               for(int j=0;j<HistoryDealsTotal();j++) 
                 {
                  m_deal.SelectByIndex(j);
                  printf("**** Symbol: %s",m_deal.Symbol());
                  printf("**** Deals involved : %g",HistoryDealsTotal());
                  printf("**** Price : %g",m_deal.Price());
                  printf("**** Type : %s",m_deal.TypeDescription());
                  printf("**** Entry : %s",m_deal.EntryDescription());
                  printf("**** Profit : %g",m_deal.Profit());
                  printf("****************************************");
                 }
              }
           }
        }

     }
  }
//+------------------------------------------------------------------+
Use the standard lib for that, it's more convenient, original function are boring to use.
Doerk Hilger
1062
Doerk Hilger  
Icham Aidibe:
Use the standard lib for that, it's more convenient, original function are boring to use.

Thank you for your effort. 

Amir Yacoby
1219
Amir Yacoby  
Doerk Hilger:
The problem is, when you execute HistorySelectByPosition(1253268), there are no results, all fields are empty when SL was executed, no close price, close time etc. 
If you use HistorySelectByPosition with the POSITION_IDENTIFIER you get nothing? Position identifier is not the same as position ticket.
123
To add comments, please log in or register