Useful features from KimIV - page 109

 
Tweaked the function a bit. Now it calculates intersections without crashing.
Input Parameters: |
nm1 - name of the first line |

nm2 - second line name

output M is the price level.

void Middle(string nm1,string nm2)
  {
  double x1, x2, x3, x4;
  double y1, y2, y3, y4;
  double k1, k3;
  
  if(ObjectFind(nm1)==0 && ObjectFind(nm2)==0)
    {
    y1=ObjectGet(nm1, OBJPROP_PRICE1);
    y2=ObjectGet(nm1, OBJPROP_PRICE2);
    x1=ObjectGetShiftByValue(nm1, y1);
    x2=ObjectGetShiftByValue(nm1, y2);
    
    y3=ObjectGet(nm2, OBJPROP_PRICE1);
    y4=ObjectGet(nm2, OBJPROP_PRICE2);
    x3=ObjectGetShiftByValue(nm2, y3);
    x4=ObjectGetShiftByValue(nm2, y4);
    
    k1=(y2-y1)/(x2-x1); 
    k3=(y4-y3)/(x4-x3);
    
    if(k1 != k3)
      {
      T = (y1 - y3 + k3*x3 - k1*x1)/(k3 - k1);
      M = y1 + k1*(T - x1);
      }
    }
  return(0);
  }

PS. Sorry to the author of this thread for posting my code here. Just thought, maybe someone struggled with crossings too...

 
Shuba: I just thought, maybe someone also struggled with crossovers...

It comes to mind (already in the Annals):

Novozar 23.07.2011 12:18
Please tell me the way out. I have an indicator called Average Directional Movement Index and it draws dashed lines. I want to catch crossover lines. I don't think it's necessary to draw dashed lines.
 
Shuba:

PS. I apologise to the author of this thread for posting my code here. Just thought that maybe someone also struggled with intersections...

All right. Forgive him...
 
Shuba:
I tweaked the function a bit. Now it calculates intersections without crashing.
Input Parameters: |
nm1 - first line name |

nm2 - second line name

output M - price level.

PS. I'm sorry to the author of this thread for posting my code here. Just thought, maybe someone struggled with crossing too...

Well, maybe this function should return this very price level (as in the previous variant)! Also, there is an undeclared variable "T" in your code.
 
TarasBY:
Well, maybe this function should return this very price level (as in the previous variant)! Besides, your code contains an undeclared variable "T".

Well, it returns it)

about undeclared variables - sorry. I stand corrected.

double M - crossing price level. This variable is declared at the beginning.

void Middle(string nm1,string nm2)
  {
  double x1, x2, x3, x4;
  double y1, y2, y3, y4;
  double k1, k3;
  
  if(ObjectFind(nm1)==0 && ObjectFind(nm2)==0)
    {
    y1=ObjectGet(nm1, OBJPROP_PRICE1);
    y2=ObjectGet(nm1, OBJPROP_PRICE2);
    x1=ObjectGetShiftByValue(nm1, y1);
    x2=ObjectGetShiftByValue(nm1, y2);
    
    y3=ObjectGet(nm2, OBJPROP_PRICE1);
    y4=ObjectGet(nm2, OBJPROP_PRICE2);
    x3=ObjectGetShiftByValue(nm2, y3);
    x4=ObjectGetShiftByValue(nm2, y4);
    
    k1=(y2-y1)/(x2-x1); 
    k3=(y4-y3)/(x4-x3);
    
    if(k1 != k3)
      {
      double T = (y1 - y3 + k3*x3 - k1*x1)/(k3 - k1);
      M = y1 + k1*(T - x1);
      }
    }
  return(0);
  }

The trailer is an Expert Advisor to see how the function works.

 

I couldn't get it to load right away...

Files:
proba_per_1.mq4  11 kb
 
Shuba:

I couldn't get it to load right away...


You should not stir the waters, IMHO - bombard the function libraries with descriptions here and that's all...

Those who need it will find it.

 

The ClosePosByTakeProfitZone() function.

This function closes a position at the market price if the price stomps for a number of bars in the zone close to the TakeProfit or tries to exit this zone. Selection of positions to be closed is specified using external parameters:

  • sy - Name of instrument. If we set this parameter, the function will only check positions of the specified instrument. NULL means the current instrument, while "" (by default) means any 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). The default value of -1 means any MagicNumber.
  • tf - Chart timeframe, on which to count the bars, during which the price stomps in the TakeProfit zone. The default value 0 is the current timeframe.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.04.2012                                                     |
//|  Описание : Закрытие позиций при нахождении цены в зоне TakeProfit         |
//|             в течение заданного количества баров,                          |
//|             а также при попыте выйти из этой зоны.                         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//|    tf - таймфрейм                  ( 0   - текущий таймфрейм)              |
//+----------------------------------------------------------------------------+
void ClosePosByTakeProfitZone(string sy="", int op=-1, int mn=-1, int tf=0) {
  double pa, pb, po, pp, tp;
  int    i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if ((mn<0 || OrderMagicNumber()==mn) && OrderTakeProfit()>0) {
          po=MarketInfo(OrderSymbol(), MODE_POINT);
          if (po==0) Message("В обзоре рынка отсутствует символ "+OrderSymbol());
          else {
            if (OrderType()==OP_BUY) {
              RefreshRates();
              pb=MarketInfo(OrderSymbol(), MODE_BID);
              pp=iLow(OrderSymbol(), tf, iLowest(OrderSymbol(), tf, MODE_LOW, TP.ZoneBars, 0));
              tp=OrderTakeProfit()-TP.ZonePoint*po;
              if (pp>tp || (pb<tp && (iHigh(OrderSymbol(), tf, 0)>tp) || (iHigh(OrderSymbol(), tf, 1)>tp))) ClosePosBySelect();
            }
            if (OrderType()==OP_SELL) {
              RefreshRates();
              pa=MarketInfo(OrderSymbol(), MODE_ASK);
              pp=iHigh(OrderSymbol(), tf, iHighest(OrderSymbol(), tf, MODE_HIGH, TP.ZoneBars, 0));
              tp=OrderTakeProfit()+TP.ZonePoint*po;
              if (pp<tp || (pb>tp && (iLow(OrderSymbol(), tf, 0)<tp) || (iLow(OrderSymbol(), tf, 1)<tp))) ClosePosBySelect();
            }
          }
        }
      }
    }
  }
}
Attached is an Expert Advisor for testing the ClosePosByTakeProfitZone() function. you can test it both in the tester and online.
 

Good evening, Igor!

Started studying your functions not too long ago, on page 36 I didn't quite understand the functions, please help me to understand:


Function GetArrowInterval().


//+------------------------------------------------------------------+
//| Returns signal pointer setting interval |
//+------------------------------------------------------------------+
int GetArrowInterval() {
int p = Period();

switch (p) {
case 1: return(4);
case 5: return(5);
case 15: return(6);
case 30: return(8);
case 60: return(10);
case 240: return(20);
case 1440: return(40);
case 10080: return(80);
case 43200: return(150);
} xml-ph-0015@deep

i.e. this function was used to set arrows using SetArrow() function, namely instead of price level in the line ObjectCreate(nm, OBJ_ARROW, 0, 0,0), tell me how it happened, it's not clear to me what the return values mean (4,5,6,8,10....)


The new version of the function also remains unclear:





//+----------------------------------------------------------------------------+
//| Author : Kim Igor V. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Version : 12.10.2007 |
//+----------------------------------------------------------------------------+
//| Description : Returns signal pointer interval |
//| Parameters: |
//| pr - percentage relative to window price size |
//+-------------------

return((WindowPriceMax()-WindowPriceMin())/100*pr/Point);


The WindowPriceMax() function returns the maximum value of the vertical scale, i.e. this is the maximum price value, but over what period?

And thanks for your hard work....))))

 
Lisi4ka330:

Started studying your functions not so long ago, on page 36 I didn't quite understand the functions, please help me to understand:

i.e. this function was used to set arrows using the SetArrow() function, namely instead of the price level in the line ObjectCreate(nm, OBJ_ARROW, 0, 0,0), tell me how this was done...

You must have misunderstood the purpose of these functions. They do not operate with prices and do not put icons; they only return distance in pips depending on the current timeframe. Please refer to the image below.

If you place such a marker not close to the price, but at a certain distance and for example on the H1 timeframe, and then you switch to M1, you will probably not see the marker. The scale will change and the icon will go either far down or up. The functions you mentioned are designed to ensure that the icons are always visible on the chart at any timeframe.

Lisi4ka330:

...what do the return values (4,5,6,8,10....) mean

Distance in pips, depending on the current timeframe.


Lisi4ka330:

WindowPriceMax() function returns the maximum value of the vertical scale, i.e. it is the maximum price value, but over what period?

Not for any period... Just in the current window. For example, in the figure below, the maximum price is 97.35