Questions from a "dummy" - page 53

 
Do not confuse the unconditional and stupid (from ignorance) re-creation of indicators on every tick with the intelligent (rare and necessary) creation of an indicator. In the first case you get a hundredfold brake and resource leakage, and in the second you get perfect performance.
 
Renat:
Do not confuse the unconditional and stupid (from ignorance) re-creation of indicators on every tick with the intelligent (rare and necessary) creation of an indicator. In the first case you get a hundredfold brake and leakage of resources, and in the second - perfect work.

I am well aware that Karlson has ignorantly made a mistake, and I also understand the nature of that mistake.

But suggest a reasonable scheme to solve his problem. The person needs to use the code written in the indicator but this code's parameter(s) are determined dynamically before each access to the indicator data?

I have a solution, it does contain dll, but you want to use pure mql, so propose a solution in mql.

HZ I already mentioned OnCalculate() and calculations in events, but you can pass three parameters via event. In my solution, a long dll will give you the address of an array with parameters and the indicator will receive data at this address.

If you have mql solution, just point the finger.

 
Urain:

I am well aware that Karlson has ignorantly made a mistake, and I also understand the nature of that mistake.

But suggest a reasonable scheme to solve his problem. The person needs to use the code written in the indicator, but the parameter(s) of this code are determined dynamically before each reference to the indicator data?

How many different indicators should be created in reality? Probably no more than 10, otherwise it will be a senseless waste of resources.

Since there are no parameter changes, you can create a collection of indicators, and the necessary one will be added to it when necessary. If there are less than 10 indicators and they have a clear meaning (initial, confirming, correcting, etc.), you can create named variables of handles with needed parameters.

 
Urain:

But suggest a reasonable scheme to solve his problem. The person needs to use the code written in the indicator, but the parameter(s) of this code are determined dynamically before each reference to the indicator data?

I've given it some thought. If the code parameters are dynamically determined before each access to the indicator data, why not include the procedure of determination of these parameters in the indicator code? In other words, all calculations should be implemented in the indicator.

Or there are situations, when such approach is impossible in principle?

 
Can you please tell me why in such a simple indicator the zero bar (first from the right) is not calculated everywhere except for the weekly graph?

#include <MovingAverages.mqh>
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_color1 LightBlue
#property indicator_type1   DRAW_LINE
#property indicator_width1 2

input int PERIOD = 80;
input ENUM_MA_METHOD  method = MODE_SMA;
input ENUM_APPLIED_PRICE PRICE = PRICE_CLOSE;
double Uptrend[];
double ExtRsiArray_TF2[];
double mabuf[];
int handleMA,handleMA2;

int OnInit()
  {
   SetIndexBuffer(0, Uptrend);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);  
   ArraySetAsSeries(Uptrend,true);
   handleMA=iMA(NULL, 0, PERIOD, 0, method, PRICE);
   handleMA2=iMA(NULL, 0, PERIOD/2, 0, method, PRICE);
   return(0);
  }
  
double WMA(int ai_0,int a_period_4) {
int some;
if(a_period_4==PERIOD)
 if(CopyBuffer(handleMA,0,ai_0,1,ExtRsiArray_TF2)<=0)
  {Alert("Error",GetLastError());
   return(0);
  }
some=PERIOD/2;
if(a_period_4==some)
 if(CopyBuffer(handleMA2,0,ai_0,1,ExtRsiArray_TF2)<=0)
  {Alert("Error",GetLastError());
   return(0);
  }
return (ExtRsiArray_TF2[0]);
}

int OnCalculate (const int rates_total,      
                 const int prev_calculated, 
                 const int begin,          
                 const double& price[] 
   )
  { ArraySetAsSeries(price,true);
    int counted_bars = prev_calculated; 
    if(counted_bars < 0) return(-1); 
    int x = 0; 
    int p = MathSqrt(PERIOD);              
    int e = rates_total - counted_bars + PERIOD + 1; 
    double vect[], trend[]; 
    if(e > rates_total) e = rates_total;    
    ArrayResize(vect, e); 
    ArraySetAsSeries(vect, true);
    ArrayResize(trend, e); 
    ArraySetAsSeries(trend, true);
    ArrayResize(mabuf, e); 
    ArraySetAsSeries(mabuf, true);
    for(x = 0; x < e; x++)        vect[x] = 2*WMA(x, PERIOD/2) - WMA(x, PERIOD);
    if(method==MODE_SMA)
    SimpleMAOnBuffer(e,prev_calculated,PERIOD+1,p,vect,mabuf);

    for(x = 0; x < e-PERIOD; x++) Uptrend[x] = mabuf[x];
    return(rates_total);                
  }
 
Yedelkin:

I've been thinking for a while. If the code parameter(s) are dynamically determined before each use of the indicator data, why don't we include the procedure of determining these parameters in the indicator code? In other words, all calculations should be implemented in the indicator.

Or there are situations, when such approach is impossible in principle?

There are situations, when parameters are calculated by another indicator and returned to the Expert Advisor, and the Expert Advisor decides which model to use based on the neuronics. We do not know in advance which set of parameters will be applied.

 
Expert:
Can you please tell me why in such a simple indicator the zero (first from the right) bar is not calculated everywhere except the weekly graph?


Oops) I put here:SimpleMAOnBuffer(e,prev_calculated,PERIOD+1,p,vect,mabuf); instead of e - rates_total and everything works)
 
Expert:
Oops) substituted here:SimpleMAOnBuffer(e,prev_calculated,PERIOD+1,p,vect,mabuf); instead of e - rates_total and everything worked)

Fix bugs man with nickname Expert? it should be in the theme humor.
 

I am trying to build a multicurrency Expert Advisor. So far I've decided on the scheme proposed by Nikolay Kositsin in his article"Creating an Expert Advisor that trades on different symbols". I faced the problem that the results are different when running a test using different symbols but the same parameters. I scrolled through the forum and found that many have come to the conclusion that this issue can be solved using the OnTimer() function. Andrey Khatimlansky advised it here:

Отвяжитесь от тиков конкретного инструмента (OnTick) - это же мультивалютник! Работайте по таймеру или ловите момент образования бара на всех рабочих инструментах, это будет надежнее.

I tried catching the moment of bar formation on all instruments, but I failed to achieve the desired result.

For example:

In the function that is intended to detect a new bar, I explicitly specify the instrument and timeframe.

bool isNewBar(string Symbol_, ENUM_TIMEFRAMES Timeframe)
{
 // В статической переменной будем помнить время открытия последнего бара
 static datetime last_time = 0;
 // Текущее время
 datetime lastbar_time = (ENUM_SERIES_INFO_INTEGER)SeriesInfoInteger(Symbol_,Timeframe,SERIES_LASTBAR_DATE);

 // Если это первый вызов функции
 if(last_time == 0)
   {
    // Установим время и выйдем 
    last_time = lastbar_time;
    return(false);
   }

 // Если время отличается
 if(last_time != lastbar_time)
   {
    // Запомним время и вернем true
    last_time = lastbar_time;
    return(true);
   }
 // Дошли до этого места - значит бар не новый, вернем false
 return(false);
}

In the OnTick() function, the scheme suggested by Nikolay Kositsin.

For example:

void OnTick()
{ 
 // Объявление массивов переменных для торговых сигналов  
 static bool UpSignal[2], DnSignal[2];

 // Получение торговых сигналов
 TradeSignalCounter(0, остальные параметры);
 TradeSignalCounter(1, остальные параметры);

 // Совершение торговых операций
 TradePerformer(0, остальные параметры);
 TradePerformer(1, остальные параметры);
}


The isNewBar(Symbol,Timeframe) function is called in the function in which the trade is executed, i.e. TradePerformer(parameters).

For example:

bool TradePerformer(параметры)
{

...

 if(isNewBar(Symbol_,Timeframe))
   {
    Trailing_Stop(параметры);
   
    Open_Source_Position(параметры);
   }
 return(true);
}


That is, a new bar is checked for each symbol separately. If there is no new bar, we check the next symbol. And so it happens with every tick. But this variant does not work.

Please advise how to implement correctly the checking of a new bar in a multi-currency Expert Advisor in the given scheme.
 
Urain:
Should be in the humour thread to correct mistakes made by someone called Expert?
In this forum you can and should correct errors in Expert code, regardless of race or timeframe :)
Reason: