Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1441

 
MrBrooklin #:

Good morning and good mood, everyone!

Taking into account constructive criticism, I have changed the code of the check function:

CheckMoneyForTrade() and CheckVolumeValue() functions are not posted, as they are freely available and taken from here.

Will this minimum be enough to prevent the problem with the Expert Advisor that I had the day before yesterday?

Regards, Vladimir.

Yes, it seems to be normal, but it is better to check the volume and sufficiency in one function and change the logic on sufficiency. We check whether the margin lot is bigger or smaller, but do not reduce it, if the requested lot is smaller, I also calculate the lot in relation to the available margin, what lot can be set, and compare it with the minimum lot, and if it is smaller, then the trade is definitely over.

 

Good day everyone! I have an indicator Stochastic RSI. The problem is that it works very slowly. As far as I understand the main "brakes" creates this section because of the large period, which is used to search for the minimum and maximum in the arrays:

   lRsi = Buffer_Step1_RSI[i];   
   lLowestRsi = Buffer_Step1_RSI[ArrayMinimum(Buffer_Step1_RSI,i,StochLength)];
   lHighestRsi = Buffer_Step1_RSI[ArrayMaximum(Buffer_Step1_RSI,i,StochLength)];
   Buffer_Step2_Calculate[i] = ( (lRsi-lLowestRsi) / (lHighestRsi-lLowestRsi) ) * 100;   

Ideally, the solution could be if the indicator would go through all bars in the history during the first run, and would update only the last bar during the next ones. But I don't understand how to do it. Is it possible to do this? If yes, I will be grateful if you share a link or advice on how to do it.

Here is the whole code of the indicator:

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[])
{ // OnCalculate

ArraySetAsSeries(time,true);

if( t != time[0]) { // контроль бара
t = time[0];

ArrayInitialize(Buffer_Step1_RSI,0);
CopyBuffer(RSI_Handle,0,0,rates_total,Buffer_Step1_RSI);

double lRsi, lLowestRsi, lHighestRsi;
int ZZZ = rates_total - MathMax(MathMax(RsiLength,StochLength),MathMax(SmoothK,SmoothD)) - 1; 

for (int i = ZZZ; i >= 0; i-- ) { // Цикл расчета индикатора      
                  
   // ====== Calulate Stochastic of RSI ======   
   lRsi = Buffer_Step1_RSI[i];   
   lLowestRsi = Buffer_Step1_RSI[ArrayMinimum(Buffer_Step1_RSI,i,StochLength)];
   lHighestRsi = Buffer_Step1_RSI[ArrayMaximum(Buffer_Step1_RSI,i,StochLength)];
   Buffer_Step2_Calculate[i] = ( (lRsi-lLowestRsi) / (lHighestRsi-lLowestRsi) ) * 100;            
   
   
   // ====== Рассчитываем само значение предварительное (МА1) ======
   // Расчет для всех циклов, кроме первого (МА1)                          
   Step3_MA_Sum = Step3_MA_Sum - Buffer_Step2_Calculate[i + SmoothK + 1] + Buffer_Step2_Calculate[i+1];         
   // Расчет для первого цикла (идет 2-ым номером, т.к. в IF можно обнулить данные) (МА1)
   if (i == ZZZ) {
      Step3_MA_Sum = 0;
      for (int kk = i+1; kk <= i + SmoothK + 1; kk++) Step3_MA_Sum = Step3_MA_Sum + Buffer_Step2_Calculate[kk];
      }      
    Buffer_Step3_MA1[i] = Step3_MA_Sum / SmoothK;

          
   // ====== Расчитываем само значение индикатора (МА2) ======        
   // Расчет для всех циклов, кроме первого (МА2)
   Step4_MA_Sum = Step4_MA_Sum - Buffer_Step3_MA1[i + SmoothD+1] + Buffer_Step3_MA1[i+1];   
   // Расчет для первого цикла (идет 2-ым номером, т.к. в IF можно обнулить данные) (МА2)   
   if (i == ZZZ) {
      Step4_MA_Sum = 0;
      for (int kk = i+1; kk <= i + SmoothD + 1; kk++) Step4_MA_Sum = Step4_MA_Sum + Buffer_Step3_MA1[kk];
      }            
    Buffer_Step4_MA2_IndicatorData[i] = Step4_MA_Sum / SmoothD;
              
   FirstCycle = false;         
   } // Цикл расчета индикатора


} // контроль бара
return(rates_total);

 } // OnCalculate
 
Valeriy Yastremskiy #:

I think it's fine, but it's better to put the volume and sufficiency check in one function and change the logic for sufficiency too. We check whether the margin lot is more or less, but do not reduce it, if the requested lot is less, I also calculate the lot relative to the available margin, what lot can be set, and compare it with the minimum lot, and if it is less, then the trade is definitely over.

Thank you, Valery!

Regards, Vladimir.

 

And here are the first results of the function:

2023.02.02 14:41:05.466 Experts automated trading is disabled because the account has been changed
2023.02.02 14:41:09.990 Experts automated trading is enabled
2023.02.02 14:42:43.410 Experts automated trading is disabled because the account has been changed
2023.02.02 14:42:52.690 Experts automated trading is enabled
2023.02.02 14:43:33.882 Experts automated trading is disabled because the account has been changed
2023.02.02 14:43:44.869 Experts automated trading is enabled

It would be interesting to know what it is? Not in the sense of translation into Russian, as I have already translated it:

2023.02.02 14:41:05.466 Автоматическая торговля экспертов отключена, так как аккаунт был изменен

but in the sense of how an account can be changed? Can anyone tell me what the hell is going on with my account and what to do in such cases?

Maybe it is somehow connected with the fact that I temporarily switched from real to demo account?

Regards, Vladimir.

 
Greetings, is it possible to implement or is there a ready solution to stretch charts vertically without limits like in tradingview?
 
MrBrooklin #:

Maybe it is somehow connected with the fact that I temporarily switched from real to demo account?

Yes
 
Sergey Gridnev #:
Yes

Thank you, Sergey, now I will know.

Regards, Vladimir.

 
The Expert Advisor uses an indicator on the specified TF, how can I find out the TF from the indicator handle?
 
Aleksey Vyazmikin #:
The Expert Advisor uses an indicator on the specified TF, how can I find out the TF from the indicator handle?

I don't understand, the specified TF should be known. You need to elaborate on the situation.

 
Aleksey Vyazmikin #:
The Expert Advisor uses an indicator on the specified TF, how can I find out the TF by the indicator handle?

https://www.mql5.com/ru/docs/series/indicatorparameters

Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorParameters
Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorParameters
  • www.mql5.com
IndicatorParameters - Доступ к таймсериям и индикаторам - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Reason: