Discussion of article "Creating an Expert Advisor, which Trades on a Number of Instruments" - page 5

 
Interesting:
By Tnew[1] Invalid array range - it seems to be a range overrun. Don't forget that the numbering of array elements begins with the beginning of the array range.

no access to edit message from 2010.07.16 22:41 2010.07.16 22:41:25 2010.07.16 22:41:25 #

Replace:8.Why Exp_TEMA.mq5, when testing, opens trades inside a bar? by

8.Why Exp_TEMA.mq5, when testing, opens multiple trades in one bar?

 
ias:
no access to edit message from 2010.07.16 22:41 2010.07.16 22:41:25 2010.07.16 22:41:25 #

Posts can only be edited within 3 days of posting.

 

ias:

8.Why Exp_TEMA.mq5, when testing, opens multiple trades in one bar?

It would be logical to assume that there is no check for the presence of previously opened positions and set orders....
 

Interesting:
Логично будт предположить то, что там нет проверки наличия ранее открытых позиций и установленных отложников...

Interesting:
It would be logical to assume that there is no check of previously opened positions and set pending orders....

Pending orders are not used in Exp_TEMA.mq5. Previously opened positions are checked in:

//+X================================================================X+
bool BuyPositionOpen
                    ...
   if(PositionSelect(symbol))return(false);
//+X================================================================X+
bool SellPositionOpen
                    ...
   if(PositionSelect(symbol))return(false);
//+X================================================================X+
bool BuyPositionClose(const string symbol, ulong deviation)
...
   if(PositionSelect(symbol))
     {
      if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_BUY) return(false);
     }
    else  return(false);
//+X================================================================X+
bool SellPositionClose(const string symbol, ulong deviation)
...
   if(PositionSelect(symbol))
    {
     if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_SELL)return(false);
    }
   else return(false); 

Perhaps something is wrong, in:

//+X================================================================X+
bool IsNewBar(int Number, string symbol, ENUM_TIMEFRAMES timeframe)
  {
//----+
   static datetime Told[];
   datetime Tnew[1];
   
   //----+ Variable declaration for storing sizes of variable arrays
   static int Size_ = 0;
   
   //----+ Resizing variable arrays
   if (Number + 1 > Size_)
    {
     uint size = Number + 1;
     //----
     if (ArrayResize(Told, size) == -1)
      {
       string word = "";
       StringConcatenate(word, "IsNewBar( ", Number,
                    " ): Error!!! Failed to resize variable arrays!!!"); 
       Print(word); 
       //---- 
       int error = GetLastError();
       ResetLastError();
       if (error > 4000)
        {
         StringConcatenate(word, "IsNewBar( ", Number, " ): Error code ", error);
         Print(word); 
        }  
       //---- 
       Size_ = -2;
       return(false);
      }
    }
   
   CopyTime(symbol, timeframe, 0, 1, Tnew); 
   if (Tnew[0] != Told[Number])
    {
     Told[Number] = Tnew[0];
     return(true);
    }
//----+
   return(false);
  }

or in:

//+X================================================================X+
bool TradeSignalCounter
                      (
                       int Number,
                       string Symbol_,
                       bool Trade,
                       int period,
                       ENUM_APPLIED_PRICE ApPrice,
                       bool& UpSignal[],
                       bool& DnSignal[],
                       bool& UpStop[],
                       bool& DnStop[]
                      )
  
  {
//----+
   //----+ Trade ban check
   if (!Trade)return(true);
   
   //----+ Declare a variable to store the total size of variable arrays
   static int Size_ = 0;
   
   //----+ Declaring an array for storing indicator handles as a static variable
   static int Handle[];
   
   static int Recount[], MinBars[];
   double TEMA[4], dtema1, dtema2;
   
   //----+ Initialisation 
   if (Number + 1 > Size_) // Entry into the initialisation block only on the first start
    {
     Size_ = Number + 1; // Entry to the block is closed for this number
     
     //---- Resizing variable arrays
     ArrayResize(Handle,   Size_);
     ArrayResize(Recount,  Size_);
     ArrayResize(MinBars,  Size_);
     
     //---- Determining the minimum number of bars sufficient for calculation 
     MinBars[Number] = 3 * period;
     
     //---- Preliminary zeroing of array cells
     DnSignal[Number] = false;
     UpSignal[Number] = false;
     DnStop  [Number] = false;
     UpStop  [Number] = false;
     
     //---- Use the array as a time series
     ArraySetAsSeries(TEMA, true);
     
     //----+ Getting indicator handle
     Handle[Number] = iTEMA(Symbol_, PERIOD_CURRENT, period, 0, ApPrice);
    }
     
   //----+ Checking the number of bars for sufficiency for calculation 
   if (Bars(Symbol_, 0) < MinBars[Number])return(true);

   //----+ Receiving trading signals 
   if (IsNewBar(Number, Symbol_, PERIOD_CURRENT) || Recount[Number]) // Entry to the block on bar change or failed data copying
    {
     DnSignal[Number] = false;
     UpSignal[Number] = false;
     DnStop  [Number] = false;
     UpStop  [Number] = false;
     
     //----+ Using the indicator handles, copy the values of the indicator's
                   // buffers into a specially prepared static array
     if (CopyBuffer(Handle[Number], 0, 0, 4, TEMA) < 0)
      {
       Recount[Number] = true; // since the data is not received, you should return 
                                 // into this block of receiving trading signals on the next tick!
       return(false); // exit the TradeSignalCounter() function without receiving trade signals
      }
      
     //---- All operations of copying from the indicator buffer are completed successfully
     Recount[Number] = false; // it is possible not to return to this block until the next bar change
     
     int Digits_ = SymbolInfoInteger(Symbol_, SYMBOL_DIGITS) + 4;
     dtema2 = NormalizeDouble(TEMA[2] - TEMA[3], Digits_);
     dtema1 = NormalizeDouble(TEMA[1] - TEMA[2], Digits_);
     
     //---- Definition of input signals
     if (dtema2 > 0 && dtema1 < 0) DnSignal[Number] = true;
     if (dtema2 < 0 && dtema1 > 0) UpSignal[Number] = true;
     
     //---- Definition of output signals
     if (dtema1 > 0) DnStop[Number] = true;
     if (dtema1 < 0) UpStop[Number] = true;
    }
//----+
   return(true);
  } 

Multiple trades in one bar when testing Exp_TEMA.mq5 on EURUSD, period D1

 
ias, that's better to go to the author of the article....
 
ias:

Why Exp_TEMA.mq5, when testing, opens trades inside the bar? on

Why Exp_TEMA.mq5, when testing, opens multiple trades in one bar?

The point is that in the context of this article, the task was to implement a simple multicurrency Expert Advisor without cluttering the main idea with minor details that interfere with understanding the essence. And everyone has his own way of filling in details. In your situation, everything is solved elementary. Variables of trading signals are made as input for trading functions and are linked by the link, and these variables are reset after the transaction inside trading functions.
Документация по MQL5: Торговые функции
Документация по MQL5: Торговые функции
  • www.mql5.com
Торговые функции - Документация по MQL5
 
GODZILLA:
The point is that in the context of this article, the goal was to implement a simple multicurrency Expert Advisor without cluttering the main idea with minor details that interfere with understanding the essence. And everyone has his own way of filling in details. In your situation, everything is solved elementary. Variables of trading signals are made as input for trading functions and are linked, and these variables are reset after a deal is executed inside trading functions.
Please show me how to do it on the example of your Expert Advisor Exp_TEMA.mq5.
 

ias:
Покажите, пожалустайста, на примере вышего эксперта Exp_TEMA.mq5, как это сделать.

In my opinion, learning and understanding a programming language consists in that an individual solves small tasks of rearranging the code for his own needs. Otherwise, why do you need this site and programming articles at all? To demonstrate the abilities of the authors of the articles? Those who don't want to understand it themselves can use the resource https://www.mql5.com/ru/job
For example, in MQL4 I have implemented this approach in its simplest form like this https://www.mql5.com/en/articles/1516. For MQL5, nothing changes and everything is done in the same way.

.

 
GODZILLA:

I have great respect for the author of the article "Creating an Expert Advisor that trades on different instruments".
1.The code of the Expert Advisor Exp_TEMA.mq5 presented in the article opens multiple trades in one bar during testing,
as reported earlier on this topic. This fact confirms the presence of an incorrect code or a bug in the Expert Advisor, which many site visitors are interested in eliminating.
2..Roche's reply on the topic "Expert Advisors:Multicast": "Besides, the function of determining a new bar can be implemented without using the function of time copying." - also confirms the possibility of a more rational writing of the IsNewBar() function in the Expert Advisor.
I would like to see how the author will professionally eliminate these defects, since everyone can make mistakes, and only professionals can correct them correctly.
 
ias:

If you look closely at the trading systems presented in the article, you can conclude that they are overturn systems. Stoploss in such systems plays a secondary role and is placed at a very decent distance from the entry, counted in several candles at least. Professionalism in the presentation of the material consists in unfolding the subject in the simplest possible form without cluttering it with additional gimmicks, and not on the basis of the public who do not want to think for themselves. Any textbook is always flawed in terms of the ideal. And this is considered acceptable and normal. In the future there will be such an order of detailed presentation of this detail of building trading systems, there will be a detailed review of the implementation, which is also not so simple.
As for time copying, I can say quite definitely, I myself did not see any significant difference from more rational writing of the IsNewBar() function in the Expert Advisor, although I measured it! I even wrote an article on this topic. It would be understandable then if there was a significant deterioration of the code's work.
And if I wanted to, I, for example, could tear any article from this site to pieces without any problems. But I appreciate information first of all because it is available, not because it corresponds to my ideas about the ideal.
So I am not going to eliminate far-fetched flaws and at the same time significantly clutter up the code, which is not so simple as it is, for quite understandable and quite professional reasons.