Useful features from KimIV - page 117

 
tim-time:

...add PUSH notifications to YOURe-SignalOfTrade EA?

Done... download from my website...
 
KimIV:

I have put together the ErrorRU() function, which returns a short or detailed Russian description of an error by its code. Both errors returned by the trade server and errors of executing MQL programs are detected. Not all errors, however, have a detailed description with recommendations "What to do", but that's how it is.

I am publishing the function in the script for testing it.

If someone needs a variation in the form of MQH-file, you can get it from my website.


Greetings Igor. Thanks for the feature, it's very useful
 

Hello KimIV.

You have a wonderful function i-Profit.mq4 on your website.

Could you please tell me how to extract balance data from it?

// 0 - current balance

// 1 - balance at the beginning of the day.

// 2 - balance at the beginning of the week.

// 3 - balance sheet at the beginning of the month

// 4 - balance at the beginning of the quarter

// 5 - balance at the beginning of the year

// 6 - balance sheet as of the user date

 

The ProfitByPrice() function.

This function is one of my small set of predictive functions. Predictive in the sense that they show the future, i.e. they answer the question: "What will happen if some event happens? This function, for example, returns a profit in the currency of the deposit if the current positions are closed at the price passed as a parameter.

  • op- Trade operation, position type. Valid values: OP_BUY,OP_SELL or-1. The default value-1 means any trade operation.
  • mn- Position identifier, MagicNumber. The default value-1 means any identifier.
  • cp- Expected closing price. Default value0 means current Bid price.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 29.04.2013                                                     |
//|  Описание : Возвращает профит в валюте депозита, если текущие позиции      |
//|             будут закрыты по цене, переданной в качестве параметра.        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    op - операция                             (-1 - любая позиция)          |
//|    mn - MagicNumber                          (-1 - любой магик)            |
//|    cp - цена предполагаемого закрытия (Bid)  ( 0 - текущая цена)           |
//+----------------------------------------------------------------------------+
double ProfitByPrice(int op=-1, int mn=-1, double cp=0) {
  double pr=0;
  double po=MarketInfo(Symbol(), MODE_POINT);
  double sp=MarketInfo(Symbol(), MODE_SPREAD);
  double tv=MarketInfo(Symbol(), MODE_TICKVALUE);
  int    i, k=OrdersTotal();

  RefreshRates();
  if (cp<=0) cp=Bid;
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (OrderType()==OP_BUY) {
            pr+=(cp-OrderOpenPrice())/po*OrderLots()*tv;
            pr+=OrderCommission()+OrderSwap();
          }
          if (OrderType()==OP_SELL) {
            pr+=(OrderOpenPrice()-cp-Ask+Bid)/po*OrderLots()*tv;
            pr+=OrderCommission()+OrderSwap();
          }
        }
      }
    }
  }
  return(pr);
}

ZZY. Attached is a traditional script for testing the function.

ZZZY. There is no traditional sy among the parameters as the price passed in the other parameter should be linked to a trade instrument. I decided not to bother with it too much and link it to the current symbol.

Files:
 
Dear Igor, thank you for your functions that make our first steps in programming easier! Could you help me, I need a function to close one position, but without referring to other functions, but to have Select, 3 attempts and error handling! And in the start I would prescribe conditions with check functions without Select so as not to slow down the process. So far I am usinga Selekt loop in the startwith various checks, calling the close function without Selekt, which slows down almost twice as much! What can you advise me? Thanks!
 

KimIV:

We need to set a pending order at a calculated price, provided that there are no other orders or positions within Distanc distance of that price. You don't seem to have such a function: the existence of an order or position at a distance from a given price?

 
I guess KimIV doesn't look here! :(
 
khorosh:

KimIV:

We need to set a pending order at a settlement price, provided there are no other orders or positions within Distanc distance of that price. You don't seem to have such a feature: The existence of an order or a position at a distance from a given price?


You can draw something similar to this one...

update...

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 24.06.2013                                                     |
//|  Описание : Возвращает флаг существования ордера или позиции               |
//|             около заданной цены.                                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    zp - заданная цена                                                      |
//|    sy - наименование инструмента        ("" или NULL - текущий символ)     |
//|    op - торговая операция               (    -1      - любая операция)     |
//|    mn - MagicNumber                     (    -1      - любой магик)        |
//|    ds - расстояние в пунктах от цены    (  1000000   - по умолчанию)       |
//+----------------------------------------------------------------------------+
bool ExistOPNearPrice(double zp, string sy="", int op=-1, int mn=-1, int ds=1000000) {
  int i, k=OrdersTotal(), ot;

  if (sy=="" || sy=="0") sy=Symbol();
  double p=MarketInfo(sy, MODE_POINT);
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ot=OrderType();
      if ((OrderSymbol()==sy) && (op<0 || ot==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (MathAbs(OrderOpenPrice()-zp)<ds*p) return(True);
        }
      }
    }
  }
  return(False);
}

Attached is a script to test the ExistOPNearPrice() function

 
borilunad:
Dear Igor, thank you for your functions that make our first steps in programming easier! Could you help me, I need a function to close one position, but without reference to other functions, but to have Select, 3 attempts and error handling! And in the start I would prescribe conditions with check functions without Select so as not to slow down the process. So far I'm usinga Selekt loop in the startwith various checks, calling the close function without Selekt, which slows down almost twice as much! What can you advise me? Thanks!
Isn't ClosePosBySelect()?
 
artmedia70:
Isn't ClosePosBySelect() something?
It is that, but not that, a lot of unnecessary calls to other functions with resulting errors!
Reason: