Useful features from KimIV - page 59

 
Updated list of functions
Files:
f_kimiv_1.rar  12 kb
 

Igor, could you please tell me if there is a function that determines the minimum value in pips to place a pending order?

Thank you!

 
mozg писал(а) >>
Igor, could you please tell me if there is a function that defines the minimum value in pips to place a pending order?
MarketInfo(Symbol(), MODE_STOPLEVEL);
 

Hello Igor! Could you write a function that will stop the EA from replaying the signal? It means that the state, after adding this block of code should look like this: buy, sell, buy, sell, buy, sell.... etc...

 
Shniperson писал(а) >>

Hello Igor! Could you please write a function that will stop the EA from re-triggering the signal? ... That is, the state, after adding this block of code should look like this... buy,sell,buy,sell,buy,sell.... etc...

swings...

//+----------------------------------------------------------------------------+
//|  Управление позициями.                                                     |
//+----------------------------------------------------------------------------+
void ManagePositions() {
  double sl=0, tp=0;
  int    bs= GetTradeSignal();

  if ( bs>0) {
    if ( ExistPositions(NULL, OP_SELL, Magic)) ClosePositions(NULL, OP_SELL, Magic);
    if (! ExistPositions(NULL, OP_BUY, Magic)) {
      if ( StopLoss  >0) sl=Ask- StopLoss  *Point; else sl=0;
      if ( TakeProfit>0) tp=Ask+ TakeProfit*Point; else tp=0;
      OpenPosition(NULL, OP_BUY, Lots, sl, tp, Magic);
    }
  }
  if ( bs<0) {
    if ( ExistPositions(NULL, OP_BUY, Magic)) ClosePositions(NULL, OP_BUY, Magic);
    if (! ExistPositions(NULL, OP_SELL, Magic)) {
      if ( StopLoss  >0) sl=Bid+ StopLoss  *Point; else sl=0;
      if ( TakeProfit>0) tp=Bid- TakeProfit*Point; else tp=0;
      OpenPosition(NULL, OP_SELL, Lots, sl, tp, Magic);
    }
  }
}
//+----------------------------------------------------------------------------+
//|  Возвращает торговый сигнал:                                               |
//|     1 - покупай                                                            |
//|     0 - сиди, кури бамбук                                                  |
//|    -1 - продавай                                                           |
//+----------------------------------------------------------------------------+
int GetTradeSignal() {
  int bs=0;

  if ( условия для покупки) bs=1;
  if ( условия для продажи) bs=-1;

  return( bs);
}

ExistPositions()

ClosePositions()

 

The NormalizePrice() function.

This function returns the normalized price value. The normalization is performed using the values of the MarketInfo(MODE_TICKSIZE || MODE_DIGITS) function. The NormalizePrice() function takes the following parameters:

  • np - Normalized lot value. Required parameter.
  • sy - Name of trade instrument. NULL or "" - current symbol. Default value - "".
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 21.08.2008                                                     |
//|  Описание : Возвращает нормализованное под размер тика значение цены.      |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    np - нормализуемое значение цены.                                       |
//|    sy - наименование инструмента        ("" или NULL - текущий символ)     |
//+----------------------------------------------------------------------------+
double NormalizePrice(double np, string sy="") {
  if ( sy=="" || sy=="0") sy=Symbol();
  double pp, ts=MarketInfo(Symbol(), MODE_TICKSIZE);
  int    di=MarketInfo(Symbol(), MODE_DIGITS);

  if ( ts>0) pp=NormalizeDouble( np/ ts, 0)* ts;
  else {
    if ( di>0) pp=NormalizeDouble( np* di, 0)/ di; else pp= np;
  }
  return( pp);
}

SZZ. Attached is a script to test NormalizePrice() function.

Files:
 

(Newbie question).

Dear KimIV I've written a function:

GetExtremumZZPrice().


double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=1; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(zz);
    }
  }
  Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}
What kind of code should be used to store the prices of the last minimum and maximum in 2 variables ? ( my mind is fried ;((())
 
WroC писал(а) >>
What kind of code should be used to store the prices of the last minimum and maximum in 2 variables ?
void start() {
  double p1= GetExtremumZZPrice("", 0, 0);
  double p2= GetExtremumZZPrice("", 0, 1);

  if ( p1> p2) Comment("Последний максимум ", p1, "\n Последний минимум ", p2);
  else Comment("Последний максимум ", p2, "\n Последний минимум ", p1);
}
 

KimIV

Thank you!

 
Igor, hello!
As far as I am capable I have tried to understand the material you have presented. To be honest I haven't used expert advisors or scripts and I have no practical experience in working with them, but I need to create a script which would help me in placing a big number of orders.
The script's task is to facilitate placing pending orders (mainly Buy stop and Sell stop).
I.e., the script parameters are set as follows:
1. Level from which the orders are placed (for example, EUR / USD Buy Stop from 1.3000)
2. The size of each order (for example, 0.01).
Step of placing orders (e.g. 1 pip)
4. TP of each order (e.g. 3 pips)
5. The number of pending orders (e.g. 70) or the level up to which the pending orders should be placed (e.g. up to 1.3070).
Stop loss and trailing stop parameters in the script are desirable, but not necessary...
The script is supposed to start the computer every 3-4 hours, analyze the situation and decide to set orders to break the range upwards (or downwards), with 1 pip opening period, but with a minimum TP (3 pips). Thus, in case of a price movement to the necessary side these orders will start to be opened and if the necessary price is reached, they will be closed by TP. Then a variant is possible when they will all be closed on a TP - if the price movement passes all orders or a part of the orders (6 units) will be open and will be "minus". In this case we are supposed to set the next "staircase" of orders in the opposite direction with other parameters (lot size, step, TP, number of orders) that would seem to be the best to a trader.
At the end of a trading day "opposite positions" will be closed, thus leaving trader with about 6 orders directed either upwards (or downwards).
Thanks in advance for the expert answer!
Reason: