how can i store the lot sizes in a buffer

To add comments, please log in or register
Changamire Chinje Chivhanganye
68
Changamire Chinje Chivhanganye  

i have been trying to store the sum of order buy lots and the order sell lots in a buffer can  anyone help pliz, thanks in advance


//+------------------------------------------------------------------+
//|                                                        chang.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 DeepPink
#property indicator_width1 1
#property indicator_width2 1
   double totalBuyLots[];
   double totalSellLots[];
    

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void PrintText(string object, string text, int x, int y)
{
   ObjectCreate(object, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(object, text, 9, "Verdana", Yellow);
   ObjectSet(object, OBJPROP_CORNER, 0);
   ObjectSet(object, OBJPROP_XDISTANCE, x);
   ObjectSet(object, OBJPROP_YDISTANCE, y);
}

void CalculateLots()
{
      double totalBuyLots = 0;
      double totalSellLots = 0;
    
      for(int i=0; i < OrdersTotal(); i++)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            //if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
            }
         }  
      }
    
      string sBuyText = "Total Buy = ";
      sBuyText += DoubleToString(totalBuyLots, 2);
      string sSellText = "Total Sell = ";
      sSellText += DoubleToString(totalSellLots, 2);
    
      PrintText("BuyObject", sBuyText, 20, 20);
      PrintText("SellObject", sSellText, 20, 40);
}

int OnInit()
  {
//--- indicator buffers mapping
  //UP Arrow Buffer
  SetIndexEmptyValue(0,0.0);
  SetIndexStyle(0,DRAW_ARROW,0,EMPTY);
  SetIndexArrow(0,233);
  SetIndexBuffer(0,totalBuyLots);

  //DOWN Arrow Buffer
  SetIndexEmptyValue(1,0.0);
  SetIndexStyle(1,DRAW_ARROW,0,EMPTY);
  SetIndexArrow(1,234);
  SetIndexBuffer(1,totalSellLots);
//---
   CalculateLots();
//---
   return(INIT_SUCCEEDED);
 
 
  }
  //+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      CalculateLots();
  }
//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. EA difficulty trading on real account. I...
Files:
Icham Aidibe
11675
Icham Aidibe  
chinje:

i have been trying to store the sum of order buy lots and the order sell lots in a buffer can  anyone help pliz, thanks in advance


//+------------------------------------------------------------------+
//|                                                        chang.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 DeepPink
#property indicator_width1 1
#property indicator_width2 1
   double totalBuyLots[];
   double totalSellLots[];
    

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void PrintText(string object, string text, int x, int y)
{
   ObjectCreate(object, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(object, text, 9, "Verdana", Yellow);
   ObjectSet(object, OBJPROP_CORNER, 0);
   ObjectSet(object, OBJPROP_XDISTANCE, x);
   ObjectSet(object, OBJPROP_YDISTANCE, y);
}

void CalculateLots()
{
      double totalBuyLots = 0;
      double totalSellLots = 0;
    
      for(int i=0; i < OrdersTotal(); i++)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            //if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
            }
         }  
      }
    
      string sBuyText = "Total Buy = ";
      sBuyText += DoubleToString(totalBuyLots, 2);
      string sSellText = "Total Sell = ";
      sSellText += DoubleToString(totalSellLots, 2);
    
      PrintText("BuyObject", sBuyText, 20, 20);
      PrintText("SellObject", sSellText, 20, 40);
}

int OnInit()
  {
//--- indicator buffers mapping
  //UP Arrow Buffer
  SetIndexEmptyValue(0,0.0);
  SetIndexStyle(0,DRAW_ARROW,0,EMPTY);
  SetIndexArrow(0,233);
  SetIndexBuffer(0,totalBuyLots);

  //DOWN Arrow Buffer
  SetIndexEmptyValue(1,0.0);
  SetIndexStyle(1,DRAW_ARROW,0,EMPTY);
  SetIndexArrow(1,234);
  SetIndexBuffer(1,totalSellLots);
//---
   CalculateLots();
//---
   return(INIT_SUCCEEDED);
 
 
  }
  //+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      CalculateLots();
  }
//+------------------------------------------------------------------+


void CalculateLots()
{
      double totalBuyLots = 0;
      double totalSellLots = 0;
      double BuyLots[]; double SellLots[];
     
      for(int i=0; i < OrdersTotal(); i++)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            //if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
                  ArrayResize(BuyLots,ArraySize(BuyLots)+1); BuyLots[ArraySize(BuyLots)-1] = OrdersLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
                  .... same
            }
         }   
      }
Sergey Golubev
Moderator
114250
Sergey Golubev  
chinje:

i have been trying to store the sum of order buy lots and the order sell lots in a buffer can  anyone help pliz, thanks in advance

...

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.


William Roeder
20208
William Roeder  

chinje:  have been trying to store the sum of order buy lots and the order sell lots in a buffer can  anyone help pliz,

  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3. int OnInit(){
       CalculateLots();
    Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.

  4.       for(int i=0; i < OrdersTotal(); i++){
             if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
               {                               
                //if(OrderSymbol() == Symbol())
                {  // What is the purpose of the extra braces?
                   if(OrderType() == OP_BUY)
                      totalBuyLots += OrderLots();
                   if(OrderType() == OP_SELL)
                      totalSellLots += OrderLots();
                }  // What is the purpose of the extra braces?
             }   // if
          } // for
    
    What is the purpose of the extra braces?
  5. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  6. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

  7. You have buffers, where do you store into them? Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using CODE button) and state the nature of your problem.
              No free help
              urgent help.

  8. Icham Aidibe:

    He already has buffers, no need for internal arrays.

To add comments, please log in or register