[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 427

 
rosomah:

Gentlemen, using OrderSelect(), we can easily find the opening price of the order. Can we use the quotes on the chart to find out if there is an order at a certain price or nothing at this point? It is very annoying to look through all orders on each quote in the chart (especially if there are a lot of them) to find out if something is there or not with this price. Can you throw me the code if it exists?

It's uncomfortable to put the trousers over your head © People say.

It's not you who's going through the motions, it's the algorithm. If you are so indigent, you can make all this stuff into a single function that will give you the results you need on demand. But in the body of the function you still have to write code that will search positions one by one.

 
Reshetov:

There's no way. Only by looping through one by one with OrderSelect().

Can you please tell me how to calculate the total volume of all orders (lots) by going through each order in a loop using OrderSelect()?
 
Elektronik:
Please tell me how to calculate the total volume of all orders (lots) using the OrderSelect() loop going through each order piece by piece.)
Start a variable with the total volume in lots and initialize it at 0
  1. Go through the orders in a loop
  2. After each OrderSelect(), you increase the variable value by the value OrderLots().

After the loop is finished, the variable will contain the total volume of all the orders searched

 
Elektronik:
Please tell me how to calculate the total volume of all orders (lots) by going through each order individually with OrderSelect().
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает сумму лотов открытых позиций                        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ( ""  - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - торговая операция          ( -1  - любая позиция)                  |
//|    mn - MagicNumber                ( -1  - любой магик)                    |
//+----------------------------------------------------------------------------+
double GetAmountLotFromOpenPos(string sy="", int op=-1, int mn=-1) {
  double l=0;
  int    i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              l+=OrderLots();
            }
          }
        }
      }
    }
  }
  return(l);
}
 


thanks pako:

did so:)

int start()
{
int i=0;
double lots=0;
int kollots=0;
int nets=0;
int netp=0;
for(i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;kollots=kollots+1;if(OrderStopLoss()<=0) nets=nets+1; if(OrderTakeProfit()<=0) netp=netp+1;
if((OrderType()==OP_BUY)){lots=lots+OrderLots();}
if((OrderType()==OP_SELL)){lots=lots-OrderLots();}
}
Comment("Общий объем: "+ DoubleToStr(lots,2));
}

RIGHT?

 
Elektronik:



make it so

//+------------------------------------------------------------------+
//|                                                     lots_kol.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  GetAmountLotFromOpenPos(); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
double GetAmountLotFromOpenPos(string sy="", int op=-1, int mn=-1) {
  double l=0;
  int    i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              l+=OrderLots();
            }
          }
        }
      }
    }
  }
  Comment("Количество лотoв                ",l);
  return(l);
}

так сделай

 

Good afternoon, gentlemen.

I am a beginner and I have a question: how do I optimise my robot correctly?

I know which buttons and checkboxes I have to press to run a strategy tester.

I am wondering, how to figure out what period to optimize it for? How to figure out how long the EA will work "well"?

How can we calculate it? It's not just the method of insight that can work...

 
impus:

Good afternoon, gentlemen.

I am a beginner and I have a question: how do I optimise my robot correctly?

I know which buttons and checkboxes I have to press to run a strategy tester.

I am wondering, how to figure out what period to optimize it for? How to figure out how long the EA will work "well"?

How can we calculate it? It's not just the method of insight that can work...

Search your local search for "forward tests" or "OOS". It has been discussed many times.
 
impus:

Good afternoon, gentlemen.

I am a beginner and I have a question: how do I optimise my robot correctly?

I know which buttons and checkboxes I have to press to run a strategy tester.

I am wondering, how to figure out what period to optimize it for? How to figure out how long the EA will work "well"?

How can we calculate it? It's not just the method of insight that can work...

If you don't understand how to optimise an EA, don't do the optimisation, but sort out your TS, and find out which parameters need to be optimised.
 
Reshetov:
Search your local search for "forward tests" or "OOS". It has been discussed many times.
Thanks. I'll look into it.
Reason: