A bug in the OrderSend() function ? - page 9

 
borilunad:
Therefore, there is no need to set an exact ratio of swabs to bars. You can only consider swabs with swabs and it is better to use them as filters rather than signals.

Boris, You are partly right. Basically the bezels are a pointer. Although again there are a few options here. Some are looking to enter a counter-trend and some are looking to follow the trend. There are a lot of variations, but they haven't really worked yet :(
 
hoz:

Boris, you're partly right. Basically, the wagons are a pointer. Again, though, there are a few options here. Some are looking to go into a counter-trend, and some go into a trend... There are a lot of variations, but they have not worked out as expected yet :(
Do not be sad for others! Look for your own, and you will find it! If you do not know what to do, you cannot do it, because the price cannot keep up with it. You have to enter the market, its trends, at least there is less risk. And the main thing is to follow the position to the possible profit and optimal closing. :)
 

The point is not to be sad, nor is it to others. The bottom line is that there is a bug and support is not responding at all! Don't they really care about the customers. I am very curious about it. The request has been pending for almost a week, and there is no reaction at all... I do not know what to do with it... Maybe you may take a video and show the price on the current bar and the tare cuts right through it, but there are no pending orders? Yes, I did it, but I only did it to understand the reason. I will put it to test on Demo on Monday, but... But then again... if the tester is totally glitchy, what good will it do?

 
hoz:

... Maybe a video and show how the price goes and on the current bar, the tar cuts through the mach...

I didn't have that with the Machka.
 
tara:
I did not have it with Mashka.


Which Mashka?

I specifically wrote in which cases. Why are you trying to make it about you? This thread is already 9 pages long, but it's still there.

I'm attaching the code. Here's the same code for viewing:

//+-----------------------------------------------------------------------------------+
//|                                                                       test_Ma.mq4 |
//|                                                                               hoz |
//|                                                                                   |
//+-----------------------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""

extern string ___H0 = " ___________ Параметры МА ____________ ";
extern int i_TF = 0,
           i_fastMaPeriod = 10,
           i_slowMaPeriod = 21;
extern string ___H1 = " _____ Параметры ордера _______";
extern int i_magic = 3333021;
extern double i_thresholdFromMa = 5;                           // Отступ от МА
extern double buyHear = 10,                                    // Расстояние от МА до отложки на бай
              SellHear = 10;                                   // Расстояние от МА до отложки на шорт
// Машечки
double fastMa,
       slowMa;
double pt;
datetime lastBarTime;                                          // Время проведения последних рассчётов
// Переменные рыночного окружения
double g_spread,
       g_stopLevel,
       g_tickSize;
// Идентификаторы положений машек
#define MA_DIRECT_TO_UP      0                                 // Машки направлены вверх
#define MA_DIRECT_TO_DOWN    1                                 // Машки направлены вниз
#define MA_DIRECT_TO_NONE   -1                                 // Машки во флете
#define SIGNAL_BUY           0                                 // Сигнал на покупку
#define SIGNAL_SELL          1                                 // Сигнал на продажу
#define SIGNAL_NO           -1                                 // Сигнала нет

//+-------------------------------------------------------------------------------------+
//| Функция иницилизации                                                                |
//+-------------------------------------------------------------------------------------+
int init()
{
   GetMarketInfo();
   
   lastBarTime = 0;
   
   if (Digits  == 2 || Digits == 4)
       pt = Point;
   if (Digits == 1 || Digits == 3 || Digits == 5)
       pt = Point * 10;
   if (Digits == 6)
       pt = Point * 100;
   if (Digits == 7)
       pt = Point * 1000;
   

  return (0);
}
//+-------------------------------------------------------------------------------------+
//| Функция деиницилизации                                                              |
//+-------------------------------------------------------------------------------------+
int deinit()
{
//----
   
//----
  return (0);
}
//+-------------------------------------------------------------------------------------+
//| Сбор рыночных данных                                                                |
//+-------------------------------------------------------------------------------------+
void GetMarketInfo()
{
  g_spread = MarketInfo(Symbol(),MODE_SPREAD) * pt;
  g_stopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL) * pt;
  g_tickSize = MarketInfo(Symbol(),MODE_TICKSIZE) * pt;
}
//+-------------------------------------------------------------------------------------+
//| Функция нормализации                                                                |
//+-------------------------------------------------------------------------------------+
double ND(double A)
{
  return (NormalizeDouble(A, Digits));
}
//+-------------------------------------------------------------------------------------+
//| Открытие длинной позиции                                                            |
//+-------------------------------------------------------------------------------------+
bool OpenBuy()
{
   int ticket = -1;
   double OOP = fastMa + buyHear * pt;             // Получаем значение цны открытия
   
   if ((ND(OOP) - Ask) >= MathMax(g_stopLevel,g_spread))             // Проверка цену открытия на стоплевел          
   {
       if (ND(OOP) > Ask)           // Проверка что цена открытия выше Ask, т.к. у нас вход отложенником
       {
           Print("Bid = ", Bid);
           Print("Ask = ", Ask);
           Print("fastMa = ", fastMa);
           Print("Цена покупки = ", fastMa + buyHear * pt);
           Print("i_thresholdFromMa * pt = ", i_thresholdFromMa * pt);
           ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, ND(OOP), 3, 0, 0, NULL, i_magic, 0);
       }
   }
   if (ticket > 0)
   {
       return (true);
   }
   else
    
   Alert (GetLastError());
}
//+-------------------------------------------------------------------------------------+
//| Открытие короткой позиции                                                           |
//+-------------------------------------------------------------------------------------+
bool OpenSell()
{
   int ticket = -1;
   double OOP = fastMa - SellHear * pt;               // Получаем значение цны открытия
   
   if ((Bid - ND(OOP)) >= MathMax(g_stopLevel,g_spread))                // Проверка цену открытия на стоплевел
   {
       if (ND(OOP) < Bid)           // Проверка что цена открытия ниже Bid, т.к. у нас вход отложенником
       {
           Print("Bid = ", Bid);
           Print("Ask = ", Ask);
           Print("fastMa = ", fastMa);
           Print("fastMa + i_thresholdFromMa * pt = ", fastMa + i_thresholdFromMa * pt);
           Print("Цена покупки = ", fastMa + buyHear * pt);
           Print("i_thresholdFromMa * pt = ", i_thresholdFromMa * pt);
           ticket = OrderSend(Symbol(), OP_SELLSTOP, 0.1, ND(OOP), 3, 0, 0, NULL, i_magic, 0);
       }
   }
   if (ticket > 0)
   {
       return (true);
   }
   else
    
   Alert (GetLastError());
}
//+-------------------------------------------------------------------------------------+
//| Получаем относительное положение машек                                              |
//+-------------------------------------------------------------------------------------+
int GetStateMa(double fastMa, double slowMa)
{
   if (fastMa > slowMa)                          // Если условия выполнены, то..
       return (MA_DIRECT_TO_UP);                 // ..машки направлены вниз
   
   if (fastMa < slowMa)                          // Если условия выполнены, то..
       return (MA_DIRECT_TO_DOWN);               // машки направлены вверх
   
   return (MA_DIRECT_TO_NONE);                   // Машки не имеют выраженного направления
}
//+-------------------------------------------------------------------------------------+
//| Открытие позиций                                                                    |
//+-------------------------------------------------------------------------------------+
bool Trade(int signal)
{
   if (signal == SIGNAL_BUY)                     // Если сигнал на покупку..
       if (!OpenBuy())             // ..покупаем
          return(false);
   
   if (signal == SIGNAL_SELL)                   // Если сигнал на продажу..
       if (!OpenSell())           // ..продаём
          return(false);
       
   return (true);
}
//+-------------------------------------------------------------------------------------+
//| Получаем общий сигнал на открытие позиции                                           |
//+-------------------------------------------------------------------------------------+
int GetSignal()
{
 //  if (FindOrders() > 0)                                 // Если есть открытые ордера, то..
   //    return (SIGNAL_NO);                               //..ничего не делаем
   
   if (GetStateMa(fastMa, slowMa) == MA_DIRECT_TO_UP)
       if ( ND(MathAbs(fastMa - Ask)) <= i_thresholdFromMa * pt) // ..зазор между ценой покупки и машки, <= i_thresholdFromMa..
          return(SIGNAL_BUY);
   if (GetStateMa(fastMa, slowMa) == MA_DIRECT_TO_DOWN)
       if ( ND(MathAbs(fastMa - Bid)) <= i_thresholdFromMa * pt ) // ..зазор между ценой продажи и машки, <= i_thresholdFromMa..
       return(SIGNAL_SELL);
   
   return (SIGNAL_NO);
}
//+-------------------------------------------------------------------------------------+
//| Функция start                                                                       |
//+-------------------------------------------------------------------------------------+
int start()
{
   fastMa = iMA(NULL,i_TF,i_fastMaPeriod,0,MODE_EMA,MODE_OPEN,0);
   slowMa = iMA(NULL,i_TF,i_slowMaPeriod,0,MODE_EMA,MODE_OPEN,0);
   
 /*  Print("Bid = ", Bid);
   Print("Ask = ", Ask);
   Print("fastMa = ", fastMa);
   Print("i_thresholdFromMa * pt = ", i_thresholdFromMa * pt);
   */
// Отслеживание открытия нового бара
   if (lastBarTime == iTime(NULL, 0, 0))         // На текущем баре все необходимые действия..
       return (0);                      // ..уже были выполнены

// Рассчёт сигнала   
   int signal = GetSignal();
   
// Проведение торговых операций
   if (signal != SIGNAL_NO)
       if (!Trade(signal))
           return (0);
   
   lastBarTime = iTime(NULL, 0, 0);              // На текущем баре все необходимые действия..
                                       // .. успешно выполнены
  return (0);
}

SOME BARS ARE BLATANTLY IGNORED FOR NO REASON. And of course, there's no pending orders on them. The code is correct. There's nothing to fix, as far as I can see.

Here are screenshots showing positions that have not opened. The test dates are also visible there. Please help me to find the reason. I have already discussed everything in the thread, but not the original question.

1

2

3

Files:
test_ma_4.mq4  10 kb
 
pako:
If you don't mind formulating the ToR again, why do you need to control a new bar?



I'll put it in a nutshell! There's one more thing I haven't thought of, but I'll give you the whole point.

There should be no limit on the number of orders at all. I.e., the orders may be opened in any quantity... ... it does not matter how many we have, but we need only 1 order to be opened in the current bar. That is it.

I.e., a new bar opens, so we can open 1 order during this bar, but no more than 1 order in the current bar. The next order can be opened only on the next bar, not earlier.

Is that clear now?

And here you are wrong...

//+-------------------------------------------------------------------------------------+
//| Функция start                                                                       |
//+-------------------------------------------------------------------------------------+
int start()
{
   fastMa = iMA(NULL,i_TF,i_fastMaPeriod,0,MODE_EMA,MODE_OPEN,0); <---------------- fastMa == slowMa 
   slowMa = iMA(NULL,i_TF,i_slowMaPeriod,0,MODE_EMA,MODE_OPEN,0);  <--------------  fastMa == slowMa

   

The wave periods are different...i_fastMaPeriod andi_slowMaPeriod are 10 and 21 respectively!

 

Recommended reading

https://www.mql5.com/ru/articles/1411

 
hoz:


I do and it is easy! I have not thought of 1 more thing, but I will give you the whole idea.

There should be no limit on the number of orders at all. I.e. orders may be opened in any quantity... It does not matter how many there are, but only 1 order should be opened in the current bar. That is it.

I.e., a new bar opens, so we can open 1 order during this bar, but no more than 1 order in the current bar. The next order can be opened only on the next bar, not earlier.

Is that clear now?


Keep that on every bar only one position opens

//+------------------------------------------------------------------+
//|                                                     черновик.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(NewBar()==true)
       {
        int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Bid-250*Point,Ask+250*Point," ",16384,0,Green); 
       }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
bool NewBar() 
    {

       static datetime LastTime = 0;

       if (iTime(NULL,0,0) != LastTime) 
       {
          LastTime = iTime(NULL,0,0);      
          return (true);
       } else
          return (false);
    }
 
pako:


keep only one position open on each bar

You can't do that. If you don't get a condition on the first tick, the whole hour will go to waste.
 
hoz:


I will make it clear and easy! I have not thought of 1 more thing, but I will give you the whole idea.

There should be no limit on the number of orders at all. I.e. orders may be opened in any quantity... It does not matter how many there are, but only 1 order should be opened in the current bar. That is it.

I.e., a new bar opens, so we can open 1 order during this bar, but no more than 1 order in the current bar. The next order can only be opened on the next bar, not before.


So, in this case
lastBarTime = iTime(NULL, 0, 0);              // На текущем баре все необходимые действия..
We can open the order on the current bar only if it is opened. i.e. we should move this line in the function OpenBuy/Sell