[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 616

 
Naturally, you are right. The implication was that you already have a code for taking readings only once per bar.
 
sllawa3:
I think you're right... I have my doubts too...

You can use this method to monitor equity in order to close all positions and delete orders as soon as the specified percentage of equity profit is reached:

//--------------------------------------------------------------
// Описание глобальных переменных советника
// ----------------- Трал эквити -------------
extern double  PercentEquityForClose=15;
double         Equ_OLD,
               Equ_NEW,
               EquPerc,
               Equ_Start;

// ---- Дальнейшее описание глобальных переменных советника

//==========================================================

int init()                             // Функция init
{
   Equ_OLD=AccountEquity();
   Equ_Start=Equ_OLD; 
   EquPerc=Equ_Start/100*PercentEquityForClose;
   
// ---- Дальнейший код функции ----

   return;                             // Выход из init() 
}

//==========================================================
// ---- В функции слежения за событиями ----
// ---- вызываемой из функции start ----

   Equ_NEW=AccountEquity();                              // С новым тиком запоминаем текущее значение эквити
   if (Equ_OLD!=Equ_NEW)                                 // Если новое значение не равно старому, то
         {
            if (Equ_NEW>=Equ_OLD+EquPerc)                // Если эквити увеличилось по отношению к своему прошлому значению на EquPerc процентов,
               {                                         
                  ClosePosFirstProfit(NULL, -1, -1);     // то закрываем все позиции
                  DeleteOrders(NULL, -1, -1);            // и удаляем все ордера
                  Equ_NEW=AccountEquity();               // Запоминаем текущее значение эквити
                  Equ_OLD=Equ_NEW;                       // и заносим его в "прошлое" значение для проверки на изменение на след. тике
               }
         }

I wrote it on the spot, so there may be errors.
To track changes in equity on every bar, just check for the opening of a new bar and if so, you should execute this code fragment:

   Equ_NEW=AccountEquity();                              // С новым тиком запоминаем текущее значение эквити
   if (Equ_OLD!=Equ_NEW)                                 // Если новое значение не равно старому, то
         {
            if (Equ_NEW>=Equ_OLD+EquPerc)                // Если эквити увеличилось по отношению к своему прошлому значению на EquPerc процентов,
               {                                         
                  ClosePosFirstProfit(NULL, -1, -1);     // то закрываем все позиции
                  DeleteOrders(NULL, -1, -1);            // и удаляем все ордера
                  Equ_NEW=AccountEquity();               // Запоминаем текущее значение эквити
                  Equ_OLD=Equ_NEW;                       // и заносим его в "прошлое" значение для проверки на изменение на след. тике
               }
         }

I think it goes something like this...

 
Roger:
Naturally, you are right. The implication was that you already have a code to take readings only once per bar.
No, I don't, but I wrote something above to check equity on every tick. Just do a check on the opening of a new bar and if so, then check the equity... I don't think it's hard to do...
 
interested in the reversal of equity from rising to falling, provided equity is above balance... to close anything open...
 
sllawa3:
I am interested in the reversal of Equity from increasing to decreasing, provided that Equity is above balance... to close everything that is open...

Here is the function for defining a new bar:

//+------------------------------------------------------------------+
//|  возвращает признак появления нового бара для указанного периода |
//+------------------------------------------------------------------+
bool isNewBar(int timeFrame)
   {
   bool res=false;
   
   // массив содержит время открытия текущего (нулевого) бара
   // по 7 (семь) таймфреймам
   static datetime _sTime[7];  
   int i=6;
 
   switch (timeFrame) 
      {
      case 1  : i=0; break;
      case 5  : i=2; break;
      case 15 : i=3; break;
      case 30 : i=4; break;
      case 60 : i=5; break;
      case 240: break;
      case 1440:break;
      default:  timeFrame = 1440;
      }
//----
   if (_sTime[i]==0 || _sTime[i]!=iTime(Symbol(),timeFrame,0))
      {
      _sTime[i] = iTime(Symbol(),timeFrame,0);
      res=true;
      }
      
//----
   return(res);   
   }
   

... interested in the reversal of equity from rising to falling as long as equity is above balance... to close anything that is open...

Then we need to check equity on every tick. After all, if you work on ticks, for example, one hour before the next equity check, equity may lose its value...

So, we should not compare the increase in equity by 1%, but its increase or decrease relative to the status on the previous tick, recorded in the Equ-OLD variable with its current value in Equ_NEW

 
sllawa3:
interested in the reversal of the equity from rising to falling, provided the equity is above the balance... to close everything open...

Somewhere like this:

   Equ_NEW=AccountEquity();                              // С новым тиком запоминаем текущее значение эквити
   if (Equ_OLD!=Equ_NEW)                                 // Если новое значение не равно старому, то
         {
            if (NormalizeDouble(Equ_NEW-Equ_OLD,8)<0)    // Если эквити уменьшилось по отношению к своему прошлому значению,
               {                                         
                  ClosePosFirstProfit(NULL, -1, -1);     // то закрываем все позиции
                  DeleteOrders(NULL, -1, -1);            // и удаляем все ордера.
                  Equ_NEW=AccountEquity();               // Запоминаем текущее значение эквити
                  Equ_OLD=Equ_NEW;                       // и заносим его в "прошлое" значение для проверки на изменение на след. тике
               }
         }

// (NormalizeDouble(Equ_NEW-Equ_OLD,8)<0) - возможно здесь нужно сравнивать не с нулём, а с каким-то числом, 
                                         // а то может в последующем и не дать увеличиться балансу, 
                                         // постоянно закрывая вновь открываемые позиции (они ведь требуют залога)

However, this is just information to think about, not ready-made code...

 
drknn:

Sure. Only it's not called a stop, it's called a pending order. Open a terminal. Press F1 in it. In the window that appears open Contents - Trade - Order Types.

)))) thank you, but after funds confused/unaccustomed execution by bid and ask instead of trade, when something is confused - not shy to ask a stupid question to remove doubts. )))
 

Help . the dealer has five decimal places . iOpen (NULL,0,n) function gives only four decimal places (readings are taken via print) . how to solve the problem .

 
pips500:

Help . the dealer has five decimal places . iOpen(NULL,0,n) function gives only four decimal places (readings are taken via print) . how do I solve the problem . thank you in advance.

Print() rounds up to 4 digits to correctly output to the console the type double(which returns iOpen() 5 decimal places, in this case), you should use DoubleToStr() function

string DoubleToStr( double value, int digits)
Converts a numeric value to a text string containing a character representation of a number in the specified precision format.

Parameters:

value - Величина с плавающей точкой.

digits - Формат точности, число цифр после десятичной точки (0-8).

 
sllawa3:
I'm interested in equity reversal from ascending to descending, provided the equity is higher than the balance... to close everything open...

And here's an example of how it works... I deliberately made a position opening on each new bar... So, here we have "OC Killer"... :)


Enclosed tester report, where there is no limiters and opening of positions at every tick - huge percentage ... And no drawdown :) It's a pity nobody will let you work like this ...

Here is a picture of the report:


I've made lots of money with these "raids", with almost no drawdowns. I even did not manage to get to takeovers (you can see them at the top):