Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1421

 
viktor:
Tell me where you can download MT4 1320
Alpari
 

The OBV indicator in mt5 has no possibility to select the type of price calculation

In mt4 this option is available.

Why?

In fact, OBV is calculated as the sum of all the volume on the entire history, where the candle is down the volume is "negative"
So why in mt4 is it possible to select the price type for the indicator calculation? if it is not involved in the calculation

 

There is part of the code to calculate the separate number of buy and sell orders. (b - buy orders, s - sell orders)

Then I want to write a condition whereby if a new order is opened or an existing order is closed. I.e. we need to compare the number of orders opened earlier and the number of subsequent changes, but I do not know how to write this in the code. How do I save changes in the number of orders? Please help.

double LB=0, LS=0;
double RaznSB=0, RaznBS=0;
int b=0,s=0;
int izmb=0, izms=0;
for (int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol())
{
int tip = OrderType();
if (tip==OP_BUY)
{
LB += OrderLots();
b++;
}
if (tip==OP_SELL)
{
LS += OrderLots();
s++;
}
}
}
}
if (izmb>b ||izmb<b || izms>s || izms<s) {
izmb=b;
izms=s
}
 
Roman Sharanov:

The OBV indicator in mt5 has no possibility to select the type of price calculation

In mt4 this option is available.

Why?

In fact, OBV is calculated as the sum of all volume on the whole history, where the candle is down the volume is "negative"
So why is it possible to select the price type for the indicator during its calculation in mt4? if it is not involved in the calculation

A good question is half the answer.

 
scomoroh:

There is part of the code to calculate a separate number of buy and sell orders.

And there is a place to insert it)

 
Artyom Trishkin:

A well-defined question contains half the answer.

So the choice of price type in mt4 ts OBV means nothing and does not affect anything?
 
MakarFX:

And there's somewhere to put it).

Then I will repeat the question.

There is a part of code to calculate separate number of buy and sell orders. (b - buy orders, s - sell orders)

Then I have written a condition whereby, if a new order is opened or an existing order is closed, the next action is triggered. I.e. we have to compare the number of orders opened earlier and the number of subsequent changes, but I do not know how to write this in the code. How do I save changes in the number of orders? Please help.


   double LB=0,LS=0;
   int b=0,s=0;
   int izmb=0, izms=0;
   
   for (int i=0; i<OrdersTotal(); i++)
   {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      { 
         if (OrderSymbol()==Symbol())
         { 
            int tip = OrderType(); 
            if (tip==OP_BUY)             
             {  
               LB  += OrderLots();
               b++; 
             }                                         
            if (tip==OP_SELL)        
             {
               LS  += OrderLots();
               s++;
            } 
         }
     }     
   }
   if (izmb>b ||izmb<b || izms>s || izms<s){ //условие сравнения количества ордеров, изменилось или нет,
    izmb=b;                                   //если изменилось то присваиваем новое значение, как его сохранить? Ведь с новым тиком
    izms=s                                    // оно опять будет равно "0"???
     }
 
Vitaly Muzichenko:

If anything, you have to do it statically, otherwise it resets.

I usually make flags global. Of course in the body of the function will redeclare and Static is needed. But why nobody noticed that curly brackets are missing)))) print & assignment should be in brackets)

And without static of course it will print on every function call sinceprintsimbol="" will become ZERO and symbol will be assigned the current value)

static string symbol, printsimbol="";
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            if(ChartSymbol(currChart)!=symbol)
                {
                 symbol=ChartSymbol(currChart);
                 if(printsimbol!=symbol)
                   { Print(symbol);printsimbol=symbol;}
                }
           } 
         currChart=ChartNext(currChart);  i++;
        }
 
scomoroh:

Then I will repeat the question.

There is a part of code to calculate separate number of buy and sell orders. (b - buy orders, s - sell orders)

Then I have written a condition whereby, if a new order is opened or an existing order is closed, the action is passed on. I.e. we have to compare the number of orders opened earlier and the number of subsequent changes, but I do not know how to write this in the code. How do I save changes in the number of orders? Please help.


I would try to do this

//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
int izmb,izms;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetMillisecondTimer(200);

   izmb=0; izms=0;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(CountOrders(0,0)!=izmb){izmb=CountOrders(0,0);}
   if(CountOrders(0,1)!=izms){izms=CountOrders(0,1);}
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
//|  0 - ордера типа BUY          1 - ордера типа SELL               |
//|  2 - ордера типа BUYLIMIT     3 - ордера типа SELLLIMIT          |
//|  4 - ордера типа BUYSTOP      5 - ордера типа SELLSTOP           |
//|  6 - ордера типа Balance     -1 - Все типы ордеров               |
//+------------------------------------------------------------------+
int CountOrders(string symb="", int or_ty=-1) 
  {
   int cnt=0;
   if(symb=="0") symb=_Symbol;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==symb || symb=="")
           {
            if(or_ty<0 || or_ty==OrderType()) cnt++;
           }
        }
     }
   return(cnt);
  }
//+------------------------------------------------------------------+
 
Who knows why the advisor in the tester works fine, puts requests, etc., but in the real account, the requests are not exposed although the robot is active
Reason: