Only "Useful features from KimIV". - page 11

 
All I got was these functions, and I decided to understand the programmer's logic. That's why I'm asking questions. That's what this forum is for.
 
satop:

DistMarketAndPos() function.

Here we go! Here come more interesting functions! For example, it returns the distance in pips between the market and the nearest position. More accurate selection of positions to be checked is set by external parameters:

  • sy - Name of the instrument. If this parameter is set, the function will only check positions of the specified instrument. The "" or NULL means the current symbol.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
  • mn - Position identifier (MagicNumber). The default value of -1 means any MagicNumber.


satop:

The DistMarketAndPos() function.

Here we go! Let's go to more interesting functions! For example, it returns the distance, in points, between the market and the nearest position. The more accurate selection of positions to be checked is set by external parameters:

  • sy - Name of the instrument. If this parameter is set, the function will only check positions of the specified instrument. The "" or NULL means the current symbol.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
  • mn - Position identifier (MagicNumber). Default value -1 means any MagicNumber.


Itry to make it work back and forth and open orders back and forth. I have one error, help me to fix it.

extern int TakeProfit = 150;

extern double Lot = 0.01;

extern inttern MAGIC = 1234;

int start()

{

if (DistMarketAndPos()>150)

{

OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,Ask+TakeProfit*Point)

}

return(0);

}

int DistMarketAndPos(string sy="", int op=OP_BUY, int mn=-1)

{

double d, p;

int i, k=OrdersTotal(), r=1000000;


if (sy=="" || sy=="0") sy=Symbol();

p=MarketInfo(sy, MODE_POINT);

if (p==0) if (StringFind(sy, "")<0) p=0.00001; else p=0.01;

for (i=0; i<k; i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if ((OrderSymbol()==sy) && (op<0 || OrderType()==op))

{

if (mn<0 || OrderMagicNumber()==mn)

{

if (OrderType()==OP_BUY)

{

d=MathAbs(MarketInfo(sy, MODE_ASK)-OrderOpenPrice())/p;

if (r>d) r=NormalizeDouble(d, 0);

}

if (OrderType()==OP_SELL)

{

d=MathAbs(OrderOpenPrice()-MarketInfo(sy, MODE_BID))/p;

if (r>d) r=NormalizeDouble(d, 0);

}

}

}

}

}

//----------------------------------------------------------------------------------------------------------------------------------------------


if (DistMarketAndPos()>150)

{

OrderSend(Symbol(),OP_SELL,Lot,Ask,3,0,Ask-TakeProfit*Point);

}

return(0);


{

int DistMarketAndPos(string sy="", int op=OP_SELL, int mn=-1) //this line gives 1 error,

//if this line is removed,

//it compiles, but then

//I don't put op=OP_SELL,

//and without it, the Expert Advisor will think,

//that the order from which you want to calculate

//distance is OP_BUY

if (sy=="" || sy=="0") sy=Symbol();

p=MarketInfo(sy, MODE_POINT);

if (p==0) if (StringFind(sy, "")<0) p=0.00001; else p=0.01;

for (i=0; i<k; i++)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if ((OrderSymbol()==sy) && (op<0 || OrderType()==op))

{

if (mn<0 || OrderMagicNumber()==mn)

{

if (OrderType()==OP_BUY)

{

d=MathAbs(MarketInfo(sy, MODE_ASK)-OrderOpenPrice())/p;

if (r>d) r=NormalizeDouble(d, 0);

}

if (OrderType()==OP_SELL)

{

d=MathAbs(OrderOpenPrice()-MarketInfo(sy, MODE_BID))/p;

if (r>d) r=NormalizeDouble(d, 0);

}

}

}

}

}

return(r);

return(r);

}

}

//-------------------------------------------------------------------------------------------

THANK YOU

 
qwanya:


Iamtrying to make it work back and forth and open orders back and forth with it. I have one bug that I cannot get rid of, please help me to fix it.

THANK YOU


You should try it:

And with questions here...

extern  int     TakeProfit = 150;
extern  double  Lot        = 0.01;
extern  int     MAGIC=1234;
      
      
//=====================================================================
  int    start()
      {
     if (DistMarketAndPos(NULL,OP_BUY)>150)
            {                                     
            OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,Ask+TakeProfit*Point);
            }
          
     if (DistMarketAndPos(NULL,OP_SELL)>150)
            {                                     
         OrderSend(Symbol(),OP_SELL,Lot,Ask,3,0,Ask-TakeProfit*Point);   
            }            
       return(0);
       }
          
//========================================================================          
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает расстояние в пунктах между рынком и ближайшей       |
//|             позицей                                                        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//|    op - торговая операция          (    -1      - любая позиция)           |
//|    mn - MagicNumber                (    -1      - любой магик)             |
//+----------------------------------------------------------------------------+
int DistMarketAndPos(string sy="", int op=-1, int mn=-1) {
  double d, p;
  int i, k=OrdersTotal(), r=1000000;

  if (sy=="" || sy=="0") sy=Symbol();
  p=MarketInfo(sy, MODE_POINT);
  if (p==0) if (StringFind(sy, "JPY")<0) p=0.0001; else p=0.01;
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy) && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (OrderType()==OP_BUY) {
            d=MathAbs(MarketInfo(sy, MODE_ASK)-OrderOpenPrice())/p;
            if (r>d) r=NormalizeDouble(d, 0);
          }
          if (OrderType()==OP_SELL) {
            d=MathAbs(OrderOpenPrice()-MarketInfo(sy, MODE_BID))/p;
            if (r>d) r=NormalizeDouble(d, 0);
          }
        }
      }
    }
  }
  return(r);
}
 
Please leave your comments in the source branch. Door to source (Useful features from KimIV).
 
Please leave your comments in the source branch. Door to source (Useful features from KimIV).
 
satop:

MovingInWL() function.

Can someone explain why you should post functions that don't work?

'LevelWLoss' - undeclared identifier
'LevelProfit' - undeclared identifier
'ModifyOrder' - function not defined
'LevelWLoss' - undeclared identifier
'LevelProfit' - undeclared identifier
'ModifyOrder' - function not defined
6 error(s), 0 warning(s)

and this within the function itself

 
DenisovOleg:

Can someone explain why you should post functions that don't work?

'LevelWLoss' - undeclared identifier
'LevelProfit' - undeclared identifier
'ModifyOrder' - function not defined
'LevelWLoss' - undeclared identifier
'LevelProfit' - undeclared identifier
'ModifyOrder' - function not defined
6 error(s), 0 warning(s)

and this is inside the function itself

The function works, but it calls the ModifyOrder function, which should be added to the EA code and also add to the EA the variables LevelWLoss and LevelProfit, something like this

extern int LevelProfit = 1000;

extern int LevelWLoss = 50;

 
Виктор
Iurii Tokman

Thank you so much for this forum thread. Biggest thanks to lurii Tokman for the features. Personally, I am almost ready to equate it to Stroustrup.
Thank you!

 
Iurii Tokman:

The GetAmountLotFromOpenPos() function.

This function returns the sum of lots of open positions. A more accurate selection of positions to be taken into account is specified by external parameters:

  • sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified symbol. The default value "" means any market instrument. NULL means the current instrument.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
  • mn - Position identifier, MagicNumber. Default value -1 means any identifier.

Does not return!!!

no matter how I do it, either zeros or "event handling function not found 4.mq4 1 1
"

 
Aleksey Maryaskin:

Thank you so much for this forum thread. Biggest thanks to lurii Tokman for the features. Personally, I am almost ready to equate him to Stroustrup.
Thank you!

Don't forget to thank the author of the features as well.
Reason: