Useful features from KimIV - page 119

 
M2012K:

Hello colleagues, I am still learning the codes, I can't understand the intricacies very well and am in a bit of a quandary.

As I understand it, we need to make a call to this function to correct the parameters before placing an order.

There is such a line to open an order:

if(buy == true && Open[0]>UpTr && Trade) {

buy=OrderSend(Symbol(),OP_BUYSTOP,LOT(),NormalizeDouble(op,Digits),slippage,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits), "T",Magic,0,MediumBlue);

is this where it should be addressed? And how to do it correctly. Or this command doesn't needCorrectingPrice()?

Thank you in advance.

Before sending a trade request to the server, you should have already calculated StopLoss and TakeProfit prices. They, as I see, are stored in variables, respectively sl and tp .

So, start this function, and insert the names of your variables into it:

CorrectingPrice(Symbol(), OP_BUY, Ask, sl, tp);

It'll correct them for you, if necessary...

And after calling this function, you can call the open position function

 

Good afternoon.

I use PriceOpenNearPos () function from KimIV. I noticed that sometimesthe closestpositionis lost and anotherposition is used. So I made code for a test where you can see how closestposition is lost in the log. Please check why this happens.

int    magic    = 665544;

bool flag = false;

 

int start()

  {

//----

if((PriceOpenNearPos(NULL, OP_BUY, magic) != 0

&& PriceOpenNearPos(NULL, OP_BUY, magic)- 0.1 <  Bid

&& PriceOpenNearPos(NULL, OP_BUY, magic)+ 0.1 > Bid))

flag = true;

else

flag = false;

 

Print("::::::::::::::::::::::::: flag = ",  flag );

Print("PriceOpenNearPos(NULL, OP_BUY, magic)= ", PriceOpenNearPos(NULL, OP_BUY, magic));

 

if(!flag)

OpenPosition(NULL, OP_BUY, 0.1,0,0,magic);  

//----

   return(0);

  }

According to the conditions, the positions should not overlap each other but when I run the tester I can see that the positions overlap. (usdjpy 5m).

 
artmedia70:

Before sending a trade request to the server, you should have already calculated StopLoss and TakeProfit prices. They, as I see, are stored in variables, respectively sl and tp .

So run this function, inserting the names of your variables into it:

It will adjust them for you if necessary...

And after this function is called, you can call the position opening function


Thanks, got it. :)
 
abeiks:

Good afternoon.

I use PriceOpenNearPos () function from KimIV. I notice that sometimesthe closestpositionis lost and anotherposition is used. So I made code for a test where you can see how closestposition is lost in the log. Please check why this happens.

According to the conditions, the positions should not overlap each other but when I run the tester I can see that the positions overlap. (usdjpy 5m).


Checked... in the tester... Everything's fine. Show me yourself how positions are lost. Or explain in more detail what exactly you call losing positions.

I attach here my ready for testing Expert Advisor with all the extra functions.

 

See appendix. According to the conditions, positions should not overlap each other, but in the terminal we can see that 3 and 9 positions open at the same price (also 4, 6, 8). Further we look at the log files and see that at some moment the position 98.179 is lost and appears 98.301. Therefore, the positions overlap.

 
abeiks:

See appendix. According to the conditions, positions should not overlap each other, but the terminal shows that 3 and 9 positions open at the same price (also 4, 6, 8). Further we look at the log files and see that at some moment the position 98.179 is lost and appears 98.301. Therefore the positions overlap.


Thank you for your code, the materials provided and your patience!

I fixed the function. Here is the new version:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.07.2013                                                     |
//|  Описание : Возвращает цену открытия ближайшей к рынку позиции.            |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
double PriceOpenNearPos(string sy="", int op=-1, int mn=-1) {
  double mi, oop=0, p;
  int    i, k=OrdersTotal(), pp=-1;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (OrderType()==OP_BUY)  mi=MarketInfo(OrderSymbol(), MODE_ASK);
            if (OrderType()==OP_SELL) mi=MarketInfo(OrderSymbol(), MODE_BID);
            p=MarketInfo(OrderSymbol(), MODE_POINT);
            if (pp<0 || pp>MathAbs(OrderOpenPrice()-mi)/p) {
              pp=MathAbs(OrderOpenPrice()-mi)/p;
              oop=OrderOpenPrice();
            }
          }
        }
      }
    }
  }
  return(oop);
}

Here's how it works now... no overlaps

 
KimIV:


Thanks for your code, materials provided and patience!

Fixed the function. Here's the new version:

Here's how it works now... no overlaps


Thanks, everything works ! :)
 
KimIV:


Fixed the function. Here's the new version:

Igor, is there somewhere posted your new libraries, with your new features or with some of your features amended?

In other words - updated libraries with amendments and additions already made...

 
artmedia70:

Igor, is there somewhere posted your new libraries, with your new features or with amendments to some of your features?

In other words - updated libraries with amendments and additions already made...


No posted ones yet... I haven't had the time... But anyway... I'm always tweaking them. And I've written 30 or more new ones. I post them here quietly when I have the time and inclination)))

SZY. I can send all libraries to email, as is, but if you publish it, it is necessary to prepare the description or at least the list and purpose of functions to specify...

 
KimIV:


No posted ones yet... I haven't had the time... But anyway... I'm always tweaking things in them. And I've written 30 or more new ones. I post them here quietly when I have the time and inclination)))

ZS. I can email all the libras as is, but if you publish it, you should prepare a description or at least indicate the list and purpose of the functions...

Oh... it'll be interesting to poke around :) I'll put it in my email.
Reason: