Useful features from KimIV - page 55

 
Rosh писал(а) >>

There is no such function. Objects can only be created and managed on the chart to which the EA is attached.

Thank you for your prompt reply. Will it be available in Metatrader version 5?

 
KimIV, isn't there a script in your collection that would close all open Oredar: buy, sell, buystop, sellstop, buylimit, selllimit - forcibly, cyclically, to close without errors and all?
 

http://forum.alpari-idc.ru/showpost.php?p=368730&postcount=24

Found it here already.

 
KimIV, do you have a script in your collection, like this one - ByMarketBuySymbols and ByMarketSellSymbols, only common, so that let's say the script opens 5 positions for buy and 2 for sell?
 
Dear KimIV,

Thank you very much for a job well done.

A suggestion: if possible, in the first post, post and update a list of your features/scripts with links to the relevant branch pages and a short description. Then it will be super-tool! Otherwise, someone somewhere about something "will send to Kim" and then flick here long to find ...

 

Function MovingInWL().

Moves the StopLoss price level of open positions to Breakeven. Function MovingInWL() accepts the following optional parameters:

  • sy - Name of the instrument. "" - any symbol, NULL - current symbol. Default value is "".
  • op - Trade operation. Valid values: -1, OP_BUY, OP_SELL. The default value is -1 - any trade.
  • mn - Trade identifier, MagicNumber. Default value -1 - any magik.

Moreover, MovingInWL() function has global variables (external parameters of script or Expert Advisor):

  • int LevelProfit - Level of profit in points, which a position must reach to have its stop moved to Breakeven level.
  • int LevelWLoss - Breakeven level in points, to which the stop will be transferred after its profit reaches the LevelProfit level in points.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 11.09.2008                                                     |
//|  Описание : Перенос уровня стопа в безубыток                               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ( ""  - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   ( -1  - любая позиция)                  |
//|    mn - MagicNumber                ( -1  - любой магик)                    |
//+----------------------------------------------------------------------------+
void MovingInWL(string sy="", int op=-1, int mn=-1) {
  double po, pp;
  int    i, k=OrdersTotal();

  for ( i=0; i< k; i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) {
      po=MarketInfo(OrderSymbol(), MODE_POINT);
      if (OrderType()==OP_BUY) {
        if (OrderStopLoss()-OrderOpenPrice()< LevelWLoss* po) {
          pp=MarketInfo(OrderSymbol(), MODE_BID);
          if ( pp-OrderOpenPrice()> LevelProfit* po) {
            ModifyOrder(-1, OrderOpenPrice()+ LevelWLoss* po, -1);
          }
        }
      }
      if (OrderType()==OP_SELL) {
        if (OrderStopLoss()==0 || OrderOpenPrice()-OrderStopLoss()< LevelWLoss* po) {
          pp=MarketInfo(OrderSymbol(), MODE_ASK);
          if (OrderOpenPrice()- pp> LevelProfit* po) {
            ModifyOrder(-1, OrderOpenPrice()- LevelWLoss* po, -1);
          }
        }
      }
    }
  }
}

SZZ. You can find an Expert Advisor with an example of using the MovingInWL() function here.

 
mamma писал(а) >>
If it's possible, in the first post, put and update list of your features/scripts with links to branch pages and brief descriptions.

The front page is already impossible...

I'll post it here... If the post to update gets blocked, I'll re-post it. So keep an eye on the thread :-)

Files:
f_kimiv_1.rar  11 kb
 

SimpleTrailing() function.

Moves the StopLoss price level of open positions using the TrailingStop algorithm. Function SimpleTrailing() accepts the following optional parameters:

  • sy - Name of the instrument. "" - any symbol, NULL - current symbol. Default value is "".
  • op - Trade operation. Valid values: -1, OP_BUY, OP_SELL. The default value is -1 - any trade.
  • mn - Trade identifier, MagicNumber. Default value -1 - any magik.

In addition, the SimpleTrailing() function implies global variables (external parameters of the script or Expert Advisor):

  • bool TSProfitOnly - Switches the zone in which the trawl starts. If True, the trawl will only start working when the position profit reaches the value of TStop.Buy/Sell+TrailingStep points. If False, the Expert Advisor will simply make sure that the stop position relative to the current price is always no further than TStop.Buy/Sell+TrailingStep pips. In other words, if True, the Expert Advisor works only in the profit zone of the position, while if False it works in the negative zone of the position.
  • int TStop.Buy - Size of the trall in points to buy.
  • intTStop.Sell - Trawl size in points for selling.
  • int TrailingStep - Trailing step in points. This is necessary to avoid frequent requests to the dealer.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 11.09.2008                                                     |
//|  Описание : Сопровождение позиций простым тралом                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ( ""  - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   ( -1  - любая позиция)                  |
//|    mn - MagicNumber                ( -1  - любой магик)                    |
//+----------------------------------------------------------------------------+
void SimpleTrailing(string sy="", int op=-1, int mn=-1) {
  double po, pp;
  int    i, k=OrdersTotal();

  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)) {
        po=MarketInfo(OrderSymbol(), MODE_POINT);
        if ( mn<0 || OrderMagicNumber()== mn) {
          if (OrderType()==OP_BUY) {
            pp=MarketInfo(OrderSymbol(), MODE_BID);
            if (! TSProfitOnly || pp-OrderOpenPrice()> TStop. Buy* po) {
              if (OrderStopLoss()< pp-( TStop. Buy+ TrailingStep-1)* po) {
                ModifyOrder(-1, pp- TStop. Buy* po, -1);
              }
            }
          }
          if (OrderType()==OP_SELL) {
            pp=MarketInfo(OrderSymbol(), MODE_ASK);
            if (! TSProfitOnly || OrderOpenPrice()- pp> TStop. Sell* po) {
              if (OrderStopLoss()> pp+( TStop. Sell+ TrailingStep-1)* po || OrderStopLoss()==0) {
                ModifyOrder(-1, pp+ TStop. Sell* po, -1);
              }
            }
          }
        }
      }
    }
  }
}

SZZ. An Expert Advisor with an example of SimpleTrailing() function use can be found here.

 

//------- Connection of external modules -----------------------------------------+

#include "b-Positions.mqh" // Work with positions

Where to find this file?

 
beginner писал(а) >>

//------- Connection of external modules -----------------------------------------+

#include "b-Positions.mqh" // Work with positions

Where to find this file?

here

Reason: