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

 
Interesting:

I would still pay attention to the algorithm of working with buffers. If I understood it correctly, one buffer is enough (it just needs to be correctly calculated and drawn on the graph).

PS

And with the current variant I have an impression that the inducer displays "left" data (the very beginning of history) instead of "right" (current)....

Or I don't understand anything in the logic of this indicator at all....


If you output for example EURUSD to EURUSD or EURJPY to EURJPY, everything works fine.

So the output direction seems to be correct.

I have tried a lot of variants here and even like this:

handle1=iMA(InstrumentName,PERIOD_CURRENT,ex_Period_MA_1,0,MODE_SMA, PRICE_CLOSE);

...

copied=CopyBuffer(handle1,0,0,0,Counted_bars,Buf_0);

Still nothing comes out.

Does anyone have an example of displaying two different tools on one screen, somehow?

 
gisip:

What am I doing wrong, why can't I display the chart of another instrument normally?

Everything worked in MQL4, here it works only if you display it on the same instrument, then no errors.


It works in cropped form. Add checks and economics.

#property indicator_separate_window    // The indicator is drawn in a separate window
#property indicator_buffers 1

#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Aqua

input string InstrumentName="EURJPY";

//-- Indicator array
double ScreenBuffer[];

//-- Dynamic Buffer --
double ArrayBuffer[];
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int OnInit() // Special init() function
  {
//--------------------------------------------------------------------

   IndicatorSetString(INDICATOR_SHORTNAME,InstrumentName);
   SetIndexBuffer(0,ScreenBuffer,INDICATOR_DATA);
   ArraySetAsSeries(ArrayBuffer,true);
   ArraySetAsSeries(ScreenBuffer,true);
   return 0;                          // Exit
  }
//--------------------------------------------------------------------
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int Counted_bars;   // Number of bars to operate 
   int copied;

//--------------------------------------------------------------------
   copied=(int)SeriesInfoInteger(InstrumentName,0,SERIES_BARS_COUNT);
   copied=CopyClose(InstrumentName,PERIOD_M1,0,copied,ArrayBuffer);//-- Write data to memory buffer --

   for(int i=0; i<copied; i++)
     {
      ScreenBuffer[i]=ArrayBuffer[i];
     }

//--------------------------------------------------------------------
   return(rates_total);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,0,-1);             // all objects from the chart are deleted.
  }
 
gisip:

If you output for example EURUSD to EURUSD or EURJPY to EURJPY, everything works fine.

So the output direction is kind of correct.

I have tried a lot of variants here and even like this:

handle1=iMA(InstrumentName,PERIOD_CURRENT,ex_Period_MA_1,0,MODE_SMA, PRICE_CLOSE);

...

copied=CopyBuffer(handle1,0,0,0,Counted_bars,Buf_0);

Still nothing comes out.

Does anyone have an example of displaying two different tools on one screen, at least somehow?

Do you have a source code for MQL4?


I've already suggested an alternative, which is to make an index for the current instrument and debug it 100%. After that, you can easily call it with the necessary parameters in Expert Advisor or in another indictor.

With such an implementation, you need to change the basic logic of the indictor, because the parameters passed to the calculator are not quite correct for other instruments(the number of bars and other things may not match)....

And by and large this concept is not very "correct" (to put it mildly).


PS

In short, there are two options here:

1. Realise everything for the current TF and instrument and check its operability. After that use iCustom();

2. To rewrite the logic of the inducer in such a way that in the calculator it receives absolutely all data on the instrument specified in the parameters (costly and not very correct method).

Документация по MQL5: Доступ к таймсериям и индикаторам / Bars
Документация по MQL5: Доступ к таймсериям и индикаторам / Bars
  • www.mql5.com
Доступ к таймсериям и индикаторам / Bars - Документация по MQL5
 
gisip:
Changed it, still doesn't work, the chart is not true.

Do this in your indicator

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int OnInit() // Special init() function
  {
//--------------------------------------------------------------------

   IndicatorSetString(INDICATOR_SHORTNAME,InstrumentName);
   SetIndexBuffer(0,ScreenBuffer,INDICATOR_DATA);
   ArraySetAsSeries(ScreenBuffer,true);
   
   return 0;                          // Exit
  }

and read the section Indexing Direction in Arrays and Timeseries

 
DC2008:

The cropped form works. Add checks and economics.

These two things are not needed there.

//1

//-- Dynamic Buffer --
double ArrayBuffer[];
...............
ArraySetAsSeries(ArrayBuffer,true);

//2

   for(int i=0; i<copied; i++)
     {
      ScreenBuffer[i]=ArrayBuffer[i];
     }
 
Interesting:

Those are the two things you don't need in there.

Actually, yes.
 

Yeah, I think it worked!

Thank you all so much!!!

I will test it further.

 

Need to visualise trades. The Expert Advisor is multicurrency. Let's say it hangs on EURUSD and opens deals on other currency pairs. I have a difference in the results, I understand that it's my fault, but I can't check it (I can't open a chart with AUDUSD trades when the Expert Advisor is hanging on EURUSD).

If the Expert Advisor is hanging on AUDUSD, I open it and see that it works as I programmed it, but if it is hanging on EURUSD, the results are different, and I can't understand why. Visualisation of trades would be very helpful.

Документация по MQL5: Операции с графиками / ChartOpen
Документация по MQL5: Операции с графиками / ChartOpen
  • www.mql5.com
Операции с графиками / ChartOpen - Документация по MQL5
 

7.When testing Exp_TEMA.mq5, Told[] Tnew[1]expressions get the following values:
Told[] Expression could not be evaluated
Tnew[1] Invalid array range.
What do these values mean and how do they affect the result of the Expert Advisor's work?

8.Why does Exp_TEMA.mq5 open trades inside a bar during testing?

9.Will it lead to code reduction, reduction of trade execution time, reduction of slippage, reduction of costs (commissions, etc.), if instead of closing a position and opening a position in the opposite direction, we do a flip, i.e. open a position in the opposite direction with double volume?

Deals inside the bar.

 
ias:

7.When testing Exp_TEMA.mq5, the expressions Told[] Tnew[1]get the following values:
Told[] Expression could not be evaluated
Tnew[1] Invalid array range.
What do these values mean and how do they affect the Expert Advisor's work?

As for Tnew[1] Invalid array range, it seems to be an overrun of the range. Do not forget that the numbering of array items starts from 0!