Useful features from KimIV - page 87

 
keekkenen писал(а) >>

No, that will not work... one order - one lot, if you have opened an order with 3 lots then you cannot split the lot the way you want - first 1, then 1 and then 1 - the order closes the entire lot, i.e. the order closes with the same lot as it was opened, you cannot close orders in parts...

you are mistaken i have a trall which closes the order in parts.

 

no new orders of course ?

 
keekkenen 17.07.2009 15:48
hope писал(а) >> not the same. One third of the lot is closed (by one of the conditions - let's say the price has reached +150 bps). The second third will close, say, when +300pts from the opening, etc..

No, it doesn't work that way... one order - one lot, if you open an order with 3 lots then you can't split the lot in any way - first 1, then 1 and then 1 more - the order closes the whole lot, i.e. the order closes with the lot it was opened with, you cannot close orders piecemeal...

...........................

".... you cannot split the order into lots..." - why? Technically, it was implemented long ago, and thanks to Roger and KimIV on p.85 the error of 131 normalized lots was avoided. In addition, the statement "...one order, one lot, and if you open an order with 3 lots, then you can't split it as you want: first 1, then 1..." is incorrect: an order, as well as a lot, consists of the volume: 0.03, 0.3, 3... and is quietly closed by parts: 0.01, 0.1, 1... right?

 

And the point of my last request was this: is it possible to close ALL positions without resorting to arrays, but using standard calculations and adding them up like

   BuyTotalOp=0;                                // Количество Buy ордеров
   SellTotalOp=0;                               // Количество Sell ордеров
   for (int i=1; i<=OrdersTotal(); i++)         // Цикл перебора ордер
      {
      if (OrderSelect( i-1, SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         if (OrderSymbol()!= Symb)continue;      // Не наш фин. инструм
         if (OrderType()>1)                     // Попался отложенный
           {
            Alert("Обнаружен отложенный ордер. Эксперт не работает.");
            return;                             // Выход из start()
           }
         if (OrderType()==OP_BUY)
           {
            BuyTotalOp++;                         // Счётчик ордеров Buy

I just have the feeling of a tired ship that has sailed the ocean hoping for a lighthouse to tell me whether it's necessary to sail in this direction or to turn around and try another way ...

Igor - are we trashing your branch for nothing?

 

You can close all one pair at a time, but different pairs, e.g:

1,2,1,2,2,1,2 total overlapped volume 1-2-1+2+2+1+2=3 lots

Summing up, we obtain the buy-summer 3 lots and set the counter of this volume sell 3 lots

and then we close the Close bi.

*

But to answer the question: is it possible to close all positions?

yes it is possible, one after another, it's fast with the script, aap!

The scripts themselves or the closing functions have been published more than once...

And by setting them up you can close both all at once and by criteria, e.g.:

- by a specific symbol

- only bai or only sell

- only profitable

Correspondingly, combinations of criteria are possible...

 

Please help close the order at any condition you like and it just does not work.

Thank you in advance

Files:
help.rar  7 kb
 

Will cover everything!!!

void CloseAll() 
{ 
   for (int i=OrdersTotal()-1; i>=0; i--) 
      { 
      if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)==false) break; 
      if (OrderType()==OP_BUY      ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),100); 
      if (OrderType()==OP_SELL     ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),100); 
      if (OrderType()==OP_BUYSTOP  ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_SELLSTOP ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_BUYLIMIT ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); 
      }  
}

Will only close the open poses.

void CloseAll2() 
{ 
   for (int i=OrdersTotal()-1; i>=0; i--) 
      { 
      if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)==false) break; 
      if (OrderType()==OP_BUY      ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),100); 
      if (OrderType()==OP_SELL     ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),100); 
      } 
}

Example call.

// Скрипт. Закрыть все ордера.mq4 -----------------------------------
#include <WinUser32.mqh> 

void start() 
   { 
   if(MessageBox("Закрыть (удалить) все ордера?",
   "Скрипт", MB_YESNO| MB_ICONQUESTION)!= IDYES) return; 
   CloseAll(); 
   } 

Close script in full.

// Скрипт. Закрыть все.mq4 -----------------------------------
#property copyright "herurg@bk.ru" 
#include <WinUser32.mqh> 

void start() 
   { 
   if(MessageBox("Закрыть (удалить) все ордера?",
   "Скрипт", MB_YESNO| MB_ICONQUESTION)!= IDYES) return; 
   CloseAll(); 
   } 

void CloseAll() 
{ 
   for (int i=OrdersTotal()-1; i>=0; i--) 
      { 
      if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)==false) break; 
      if (OrderType()==OP_BUY      ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),100); 
      if (OrderType()==OP_SELL     ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),100); 
      if (OrderType()==OP_BUYSTOP  ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_SELLSTOP ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_BUYLIMIT ) OrderDelete(OrderTicket()); 
      if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); 
      }  
}
 

Kim you are the best. I take my hat off to you.

I have studied all your functions, but there is one hitch, or hitch. Now, when I write functions, I write them from my brain, but your functions are in my head :-).

I have studied many of your functions since the very beginning of my programming career.

Thank you.

 
gince >> :

Please help me close an order at any condition you like and it just does not work.

Thanks in advance

Explanation

Any strategy to close an order is unimportant Please help close an order using Kim's functions


int start()
{
  //----
  //Print (ExpertName);
  if(Bars<20) return(0);
  if ( CheckNevBar)
  if (! NevBar()) return(0);
   
  TradesInThisSymbol = ExistPositions( sy);
  if( TradesInThisSymbol > 0) return(0);
   
  if(AccountFreeMargin() < MarginMin) 
  {
  //Print("Not enough money to trade Strategy:", ExpertName);
  return(0);
  }
  sy=Symbol();
  Lots = GetSizeLot( sy, LotsWayChoice, LotsPercent, LotsDeltaDepo, LotsDepoForOne, LotsMax);
   
   
  if ( CheckForOpen_Sell())
  OpenPosition( sy, OP_SELL, Lots);           // Тут  работает
  if ( CheckForOpen_Buy())
  OpenPosition( sy, OP_BUY, Lots);            // Тут  работает
  
  if( CheckForClose_Buy())
  ClosePositions( sy, OP_BUY);                 // Тут  у меня что то неработает
  if( CheckForClose_Sell())  
  ClosePositions( sy, OP_SELL);               // Тут  у меня что то неработает
  
  //----
  return(0);
}

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

bool CheckForClose_Buy()
  {
  Indicat_Var();
  if ( ExistPositions( sy, OP_BUY, MagicNumber))
  {
  if( VininI_fast_trend == -1)return(true);   // Тут любое условие на закрытие
  //if(BB_MACD_2 > 0)return(true);           // Тут любое условие на закрытие
  else
  return(false);
  }  
  }
//------------------------
bool CheckForClose_Sell()
  {
  Indicat_Var();
  if ( NumberOfPositions( sy, OP_SELL, MagicNumber) >0)
  {
  if( VininI_fast_trend == 1)return(true);         // Тут любое условие на закрытие
  //if(BB_MACD_1 > 0)                             // Тут любое условие на закрытие
  //return(true);
  else
  return(false);  
  }
  }
 
There's something not working here, which means it doesn't close. No errors.