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

 

6.Seems to be missing:

TradePerformer( 4, Symb4, Trade4, StLoss4, TkProfit4, Lots4, Slippage4, UpSignal, DnSignal, UpStop, DnStop);

in Exp_TEMA.mq5 ?

 
ias:

6.Seems to be missing

in Exp_TEMA.mq5?

Yes! I must have worked too hard and overheated in such an abnormal heat!
 
Renat:

Please make a reproducible example. That is, you need ready-made code that you can compile, throw on a chart and get results.

Without this, few people will understand what we are talking about.

Thought I'd cut back so as not to put people off for nothing.

Here is the full version:

#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);
   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;

//--------------------------------------------------------------------
   //1 input rates_total = 9667 / prev_calculated = 0 / Bars = 9667
   //-- then rates_total = 9667 / prev_calculated = 9667 / Bars = 9667
   //-- in process then rates_total = 9668 / prev_calculated = 9667 / Bars = 9668
   //Print("rates_total: " + (string)rates_total);
   if (rates_total == prev_calculated) return (rates_total);//-- It's still the same bar, so we're out--

   //-- Get the number of unprocessed bars (at the first input it is all, then 1)
   //-- The number of output bars refers to the chart itself, but we will be outputting another instrument
   //-- the number of bars may be different, so we first dump all data into the buffer --
   Counted_bars = rates_total-prev_calculated;
   
   // Print("Counted_bars: " + Counted_bars);
   Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(Symbol(),0));
   //-- Allocate memory by the number of bars of the main instrument --
   if (ArrayResize(ArrayBuffer, Counted_bars,0) == -1) return (rates_total);//-- Memory allocation error --
   //--- initialise array elements with EMPTY_VALUE value ----
   ArrayInitialize(ArrayBuffer,EMPTY_VALUE);
         
   //-- Get how many bars this instrument actually has --
   copied = (int)SeriesInfoInteger(InstrumentName,0,SERIES_BARS_COUNT);
   
   if (copied > 0){
      copied=CopyClose(InstrumentName,0,0,copied,ArrayBuffer);//-- Write data to memory buffer --
      if (copied <= 0) return (rates_total);//-- error
   } 
   else{

      return (rates_total);//-- error 
   }
    
   if (Counted_bars > copied) Counted_bars = copied;//-- Take the lower value --

   Counted_bars--;//-- Since counting from 0 --
   //-- Data is loaded into the memory buffer, now write it to the screen buffer from right to left --
   for (int i = Counted_bars; i > 0; i--){
      ScreenBuffer[i] = ArrayBuffer[i];
   }   
   
//--------------------------------------------------------------------
   return(rates_total);
}


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

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.

 
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.


I am not sure of the correctness of the implementation and the algorithm in general, but based on the code and what I was able to do with it, I assume that:

The string

// Print("Counted_bars: " + Counted_bars);
Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(Symbol(),0));

should look like this

// Print("Counted_bars: " + Counted_bars);
Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(InstrumentName,Period()));


Perhaps it would be more correct to change the period everywhere as "0" to PERIOD_CURRENT.

At least everything worked for me after such changes.....

PS

Perhaps it is not relevant, but this way the compiler MATTERS much less

Print("rates_total: ",rates_total," / prev_calculated: ",prev_calculated," / Bars: ",Bars(InstrumentName, PERIOD_CURRENT));
 
Interesting:

I'm not sure of the correct implementation and algorithm in general, but based on the code and what I was able to do with it I'll assume that:

The string

should look like this

PS

Perhaps it would be more correct to change the period everywhere as "0" to PERIOD_CURRENT.

At least everything worked for me after such changes....

Changed it, still doesn't work, the graph doesn't correspond to reality.
 

It looks like this on my screen:


Clearly wrong.
 

This is how it turned out for me

But since I didn't go into the logic of the inducer and its implementation, it's not for me to judge the correctness of the results.


PS

I would still get rid of the symbol in the parameter and make it by the current symbol and TF, and then use it in Expert Advisor or another tool using the usual iCustom().

Besides, I don't really understand the logic of working with buffers (I mean the tail of the calculator and so on). In my opinion, there is a lot to work on....

Files:
proba.mq5  4 kb
 
Interesting:

That's what I got

But since I didn't go into the logic of the inducer and its implementation, it's not for me to judge the correctness of the results.


PS

I would still get rid of the symbol in the parameter and make it according to the current symbol and TF, and then use it in Expert Advisor or any other tool using the usual iCustom().


Thanks for the advice, I will try it.
 

Interesting:

Besides, I don't really understand the logic of working with buffers (I mean the tail of the calculator and so on). In my opinion, there is a lot to work on....


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 chart).

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....

This website uses cookies. Learn more about our Cookies Policy.