Calculate All

Author: Copyright © 2019, Vladimir Karputov
Price Data Components
Series array that contains tick volumes of each bar
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
Calculate All
ÿþ//+------------------------------------------------------------------+

//|                                                Calculate All.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

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

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

#property copyright "Copyright © 2019, Vladimir Karputov"

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

#property version   "1.00"

//---

#include <Trade\PositionInfo.mqh>

#include <Trade\SymbolInfo.mqh>  

#include <Trade\OrderInfo.mqh>

CPositionInfo  m_position;                   // trade position object

CSymbolInfo    m_symbol;                     // symbol info object

COrderInfo     m_order;                      // pending orders object

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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   if(!m_symbol.Name(Symbol())) // sets symbol name

      return(INIT_FAILED);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   Comment("");

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   int count_buys=0,count_sells=0;

   double volume_buys=0.0,volume_sells=0.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()==m_symbol.Name())

           {

            if(m_position.PositionType()==POSITION_TYPE_BUY)

              {

               count_buys++;

               volume_buys+=m_position.Volume();

              }



            if(m_position.PositionType()==POSITION_TYPE_SELL)

              {

               count_sells++;

               volume_sells+=m_position.Volume();

              }

           }

   string text="";

   text="Buy          : "+IntegerToString(count_buys)+", "+DoubleToString(volume_buys,2)+" lot"+"\n"+

        "Sell           : "+IntegerToString(count_sells)+", "+DoubleToString(volume_sells,2)+" lot"+"\n";



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

   double volume_buy_limits=0.0,volume_sell_limits=0.0,volume_buy_stops=0.0,volume_sell_stops=0.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()==m_symbol.Name())

           {

            if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT)

              {

               count_buy_limits++;

               volume_buy_limits+=m_order.VolumeCurrent();

              }

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

              {

               count_sell_limits++;

               volume_sell_limits+=m_order.VolumeCurrent();

              }

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

              {

               count_buy_stops++;

               volume_buy_stops+=m_order.VolumeCurrent();

              }

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

              {

               count_sell_stops++;

               volume_sell_stops+=m_order.VolumeCurrent();

              }

           }



   text=text+

        "Buy limit   : "+IntegerToString(count_buy_limits)+", "+DoubleToString(volume_buy_limits,2)+" lot"+"\n"+

        "Sell limit    : "+IntegerToString(count_sell_limits)+", "+DoubleToString(volume_sell_limits,2)+" lot"+"\n"+

        "Buy stop   : "+IntegerToString(count_buy_stops)+", "+DoubleToString(volume_buy_stops,2)+" lot"+"\n"+

        "Sell stop    : "+IntegerToString(count_sell_stops)+", "+DoubleToString(volume_sell_stops,2)+" lot";



   Comment(text);

  }

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

Comments