Questions from Beginners MQL4 MT4 MetaTrader 4 - page 141

 
Can you teach how to open and close a trade in MT4 from the market and from pending orders?
 

Hello dear programmers!!!
I am making a ticks counter for the candle, and something has gone wrong! I want to make it count ticks when the price is only going up, but it counts when it is going up and when it is going down (all ticks, and I want only growing ticks) Look at plz...

double CountTickBUY()
{

double old_price;
double delta_cur; 
double price = 0;
double old_open_price = 0;

for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
         if(OrderSymbol() == _Symbol && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
           {
           old_price = iClose(NULL, 0 , i);
           price = iOpen(NULL, 0 , i);

           delta_cur = old_price > price;
           if(delta_cur > 0) 
             {
             count_plusbuy++;
             }
           }
   }
   return(count_plusbuy);
}
 
sviter-pro:

Hello dear programmers!!!
I am making a ticks counter for the candle, and something has gone wrong! I want to make it count ticks when the price is only going up, but it counts when it is going up and when it is going down (all ticks, and I want only growing ticks) Look at plz...

int CountTickBUY()
{
   static double    old_price     = Bid;
   static datetime  time_bar      = Time[0];
   static int       count_plusbuy = 0;
   
   if( time_bar != Time[0] )
   {
      count_plusbuy = 0;
      time_bar      = Time[0];
   }
   
   if( Bid - old_price > 0 )
      count_plusbuy++;
   old_price = Bid;

   return(count_plusbuy);
}
 
Konstantin Nikitin:

Thank you so much!

 

Konstantin Nikitin: Считает тики на кождой свече хорошо, но по 2 раза! Тоесть если отсчет пошел от 1.00000 и дошел до 1.00100 он 100 пунктов щитает, потом когда спустилась цена до 1.00080 он ждет и не считает, но когда цена опять начинает расти от 1.00080 то опять начинает считать пункты, а надо что бы ждал до 1.00100 и от нее считал дальше!!!

int CountTickBUY()
{
   static double    old_price     = Bid;
   static datetime  time_bar      = Time[0];
   static int       count_plusbuy = 0;
   
   if( time_bar != Time[0] )
   {
      count_plusbuy = 0;
      time_bar      = Time[0];
   }
   
   if( Bid - old_price > 0 )
      count_plusbuy++;
   old_price = Bid;

   return(count_plusbuy);
}



 

Please explain what exactly the"IsTradeAllowed" function checks when its second form is called.

I know that the first form checks if automatic trading is allowed and if the trade flow is free. What about the second form? What exactly are the checks that take place when the second form is called?

 
Asa saas:

Please explain what exactly the"IsTradeAllowed" function checks when its second form is called.

I know that the first form checks if automatic trading is allowed and if the trade flow is free. What about the second form? What exactly are the checks that happen when the second form is called?

The second form returns information about the possibility to trade for a specified symbol at the specified time.


Whether the trade flow is free isTradeContextBusy

 
Alekseu Fedotov:

The second form of the call returns information about the ability to trade for a given symbol at a specified time.


Whether the trade flow is free isTradeContextBusy

Isn't the first form of the "IsTradeAllowed" function also checking if the trade thread is free or not?

I just use the second form of the "IsTradeAllowed" function to find out if the market is open before I execute orders.

However, I don't quite understand whether I need to use a separate function to check if a free flow like "IsTradeContextBusy" is available or if the second form of "IsTradeAllowed" already does this check.

 
Asa saas:

Doesn't the first form of "IsTradeAllowed" also check whether the trade flow is free or not?

I just use the second form of the "IsTradeAllowed" function to find out if the market is open before I execute orders.

However, I'm not quite sure if I need to use a function separately to check if a free flow like "IsTradeContextBusy" is available or if the second form of "IsTradeAllowed" already does that check.

1. No

2. No, it does not allow to trade using Expert Advisors, but it can do it manually

3. need to use another function to check the trade flow ("IsTradeContextBusy()")

 
Asa saas:

Doesn't the first form "IsTradeAllowed" also check if the trade flow is free or not?

Yes, it does. At least, it says so in the documentation. I myself don't know why it is done but the fact remains the same:

Возвращаемое значение

Возвращает true, если эксперту разрешено торговать и поток для выполнения торговых операций свободен, иначе возвращает false.

I simply use the second form of the "IsTradeAllowed" function to find out if the market is open before I execute orders.

However, I am not quite sure whether the function for checking if the free flow is available like "IsTradeContextBusy" must be used separately or whether the second form "IsTradeAllowed" already performs such check.

But it is not clear with the second form. It is responsible for the time in the future or the past.

Reason: