Trading Account Status

Author: Copyright © 2019, Vladimir Karputov
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
Trading Account Status
ÿþ//+------------------------------------------------------------------+

//|                                       Trading Account Status.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

//---

#include <Trade\PositionInfo.mqh>

#include <Trade\OrderInfo.mqh>

CPositionInfo  m_position;                   // trade position object

COrderInfo     m_order;                      // pending orders object

//--- input parameters

input ushort   InpMinutes=15;    // Set Timer (in Minutes)

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- create timer

   ResetLastError();

   if(!EventSetTimer(InpMinutes*60))

     {

      Sleep(1000);

      ResetLastError();

      if(!EventSetTimer(InpMinutes*60))

        {

         Sleep(1000);

         ResetLastError();

         if(!EventSetTimer(InpMinutes*60))

           {

            Print(__FUNCTION__,", ERROR: Set Timer #",GetLastError());

            return(INIT_FAILED);

           }

        }

     }

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//--- destroy timer

   EventKillTimer();



  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---



  }

//+------------------------------------------------------------------+

//| Timer function                                                   |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---

   int count_buys=0,count_sells=0;

   int count_buy_limits=0,count_sell_limits=0,count_buy_stops=0,count_sell_stops=0;

   CalculateAllPositions(count_buys,count_sells);

   CalculateAllPendingOrders(count_buy_limits,count_sell_limits,count_buy_stops,count_sell_stops);



   string text="Buy "+IntegerToString(count_buys)+

               "Sell "+IntegerToString(count_sells)+

               "Buy limit "+IntegerToString(count_buy_limits)+

               "Sell limit "+IntegerToString(count_sell_limits)+

               "Buy stop "+IntegerToString(count_buy_stops)+

               "Sell stop "+IntegerToString(count_sell_stops);

   SendNotification(text);

  }

//+------------------------------------------------------------------+

//| Calculate all positions Buy and Sell                             |

//+------------------------------------------------------------------+

void CalculateAllPositions(int &count_buys,int &count_sells)

  {

   count_buys=0;

   count_sells=0;



   for(int i=PositionsTotal()-1;i>=0;i--)

      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties

         if(m_position.Symbol()==Symbol())

           {

            if(m_position.PositionType()==POSITION_TYPE_BUY)

               count_buys++;



            if(m_position.PositionType()==POSITION_TYPE_SELL)

               count_sells++;

           }

//---

   return;

  }

//+------------------------------------------------------------------+

//| Calculate all pending orders                                     |

//+------------------------------------------------------------------+

void CalculateAllPendingOrders(int &count_buy_limits,int &count_sell_limits,int &count_buy_stops,int &count_sell_stops)

  {

   count_buy_limits  = 0;

   count_sell_limits = 0;

   count_buy_stops   = 0;

   count_sell_stops  = 0;



   for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders

      if(m_order.SelectByIndex(i))     // selects the pending order by index for further access to its properties

         if(m_order.Symbol()==Symbol())

           {

            if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT)

               count_buy_limits++;

            else if(m_order.OrderType()==ORDER_TYPE_SELL_LIMIT)

               count_sell_limits++;

            else if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)

               count_buy_stops++;

            else if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)

               count_sell_stops++;

           }

  }

//+------------------------------------------------------------------+

Comments