Experts: Cidomo

 

Cidomo:

The Expert Advisor uses Buy Stop and Sell Stop pending orders.

Cidomo

Author: Vladimir Karputov

 
Where is the ea

 
Habibur Rohman :
Where is the ea

The adviser did not go anywhere. Advisor is in its place:


 

I want to refine the Expert Advisor for myself, but to do this I need to understand a lot of things! (I don't understand a lot of things). I will ask questions in parts.

There is a code:

   if(m_need_delete_buy_stop || m_need_delete_sell_stop)
     {
      int count_buy_stops=0,count_sell_stops=0;
      CalculateAllPendingOrders(count_buy_stops,count_sell_stops);

      if(m_need_delete_buy_stop)
        {
         if(count_buy_stops>0)
           {
            DeleteOrders(ORDER_TYPE_BUY_STOP);
            return;
           }
         else
           {
            m_need_delete_buy_stop=false;
            return;
           }
        }
      if(m_need_delete_sell_stop)
        {
         if(count_sell_stops>0)
           {
            DeleteOrders(ORDER_TYPE_SELL_STOP);
            return;
           }
         else
           {
            m_need_delete_sell_stop=false;
            return;
           }
        }
     }

What does it do?

 
Sysmart:

I want to refine the Expert Advisor for myself, but to do this I need to understand a lot of things! (I don't understand a lot of things). I will ask questions in parts.

There is a code:

What does it do?

If flag'm_need_delete_buy_stop' ('need to delete pending buy stop orders ') or m_need_delete_sell_stop' ('need to delete pending sell stop orders') is raised

   if(m_need_delete_buy_stop || m_need_delete_sell_stop)
     {

proceed to deleting.


We calculate how many pending orders the Expert Advisor has placed at the moment:

      int count_buy_stops=0,count_sell_stops=0;
      CalculateAllPendingOrders(count_buy_stops,count_sell_stops);


If 'it is necessary to delete pending buy stop orders':

      if(m_need_delete_buy_stop)
        {
         if(count_buy_stops>0)
           {
            DeleteOrders(ORDER_TYPE_BUY_STOP);
            return;
           }
         else
           {
            m_need_delete_buy_stop=false;
            return;
           }
        }

and the number of placed buy stops is greater than zero ('count_buy_stops') - delete them. If the number is equal to zero - reset the'm_need_delete_buy_stop' flag.


We do the same if 'it is necessary to delete pending sell stop orders' ...

Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 

Thank you!

Another code I don't understand:

//--- we work only at the time of the birth of new bar
   static datetime PrevBars=0;
   datetime time_0=iTime(m_symbol.Name(),InpWorkTimeFrame,0);
   if(time_0==PrevBars)
      return;
   PrevBars=time_0;
   if(!RefreshRates())
     {
      PrevBars=0;
      return;
     }
 
Sysmart:

Thank you!

Another code I don't understand:

This code does the following: it works only once - when a new bar is born.

 
Vladimir Karputov:

This code does the following: it works only once - at the moment when a new bar is born.

Thank you. That's what I understood in the end:

//--- we work only at the time of the birth of new bar
   // remember the time of opening of the last bar in the static variable
   static datetime PrevBars=0;
   // current time (iTime - returns the value of bar opening time)
   datetime time_0=iTime(m_symbol.Name(),InpWorkTimeFrame,0);
   if(time_0==PrevBars)
      return;
   // if the time is different because the condition has passed if(time_0==PrevBars)
   // remember the time
   PrevBars=time_0;
   // if quotes have not been updated, then reset the time of the last bar opening
   if(!RefreshRates())
     {
      PrevBars=0;
      return;
     }
   // if you've reached this place, it's not a new bar.

Without your link I wouldn't have figured it out)

 
Sysmart:

Thank you. Here's what I realised in the end:

I wouldn't have figured it out without your link)

Small correction. This is

 // if you've reached this place, it's not a new bar.

is incorrect. It's correct:

 // you've reached this spot, so the bar is new.
 

By the way, right below is the code:

   if(!RefreshRates() || !m_symbol.Refresh())
     {
      PrevBars=0;
      return;
     }

I think it partially duplicates the code discussed above:

   if(!RefreshRates())
     {
      PrevBars=0;
      return;
     }

I think it can be deleted

 
Vladimir Karputov:

A small correction. This is

is incorrect. It's correct:

Thank you)!