Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1295

 
Michail_David:

Thank you, Vitaly. But still I get an error in line ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2); on element [i}.

1. Check indexes.

   SetIndexBuffer(2,ExtTempBuffer);
   SetIndexBuffer(2,ExtPriceBuffer);

2. Why do you need these 2 buffers

      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
      ExtPriceBuffer[i] = NormalizeDouble((close[i+1]-open[i+1])/Point(),2);

if

 ExtPriceBuffer[i] = ExtTempBuffer[i+1]
 
Michail_David:

gives an error in line ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2); on element [i}.

Catch

//+------------------------------------------------------------------+
//|                                                         MSBB.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrGreen
#property indicator_color2  clrRed
#property  indicator_width1  1
input int            InpMSBBPeriod=3;        // Period
input ENUM_MA_METHOD InpMSBBMethod=MODE_SMA;  // Method
//--- indicator buffers
double         ExtMSBBBuffer[];
double         ExtTempBuffer[];
double         ExtPriceBuffer[];
double         ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits);
//--- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMSBBBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,ExtTempBuffer);
   SetIndexBuffer(3,ExtPriceBuffer);
   SetIndexDrawBegin(1,InpMSBBPeriod);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MSBB("+IntegerToString(InpMSBBPeriod)+")");
   SetIndexLabel(0,"MSBB");
   SetIndexLabel(1,"Signal");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//------
   if((rates_total-prev_calculated-InpMSBBPeriod)<=0)return(0);
   
   for(int i=rates_total-prev_calculated-InpMSBBPeriod-1;i>=0;i--)
     {
      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
      ExtPriceBuffer[i] = NormalizeDouble((close[i+1]-open[i+1])/Point(),2);
      //ExtMSBBBuffer[i]=price_open+ExtTempBuffer[i];
      //Print("ExtPriceBuffer[i] = ", ExtPriceBuffer[i]);
      if(ExtTempBuffer[i]==0)
         ExtMSBBBuffer[i]=0.0;
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open>0 && price_close<0)||(price_open<0 && price_close>0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      //--- signal line counted in the 2-nd buffer
      //ExtSignalBuffer[i]=iMAOnArray(ExtMSBBBuffer,0,InpMSBBPeriod,0,InpMSBBMethod,0);
      SimpleMAOnBuffer(rates_total,prev_calculated,1,InpMSBBPeriod+2,ExtMSBBBuffer,ExtSignalBuffer);
      Print ("ExtSignalBuffer = ", ExtSignalBuffer[i]);
      //--- done
     }
   /* if(ExtPriceBuffer[i]>0||ExtPriceBuffer[i]<0)
     {
      ExtMSBBBuffer[i] = ExtPriceBuffer[i]+ExtTempBuffer[i];
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   if(ExtPriceBuffer[i]==0)
     {
      ExtMSBBBuffer[i] = 0.0;
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   }*/
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Hello! There isa modified indicator"iexposuregmini.mq4" based on iExposure.mq4 indicator built into the terminal. Can you please advise how to move the position (window) of the informer to the bottom left corner of the chart window? And after deletion of the indicator from a chart, the indicator bar remains... How can it be fixed? I am very grateful in advance!
Как заказать торгового робота на MQL5 и MQL4
Как заказать торгового робота на MQL5 и MQL4
  • www.mql5.com
Главным преимуществом торговых терминалов MetaTrader является возможность создания автоматических торговых систем, способных совершать торговые операции без вмешательства трейдера, что позволяет исключить влияние психологии на результаты торговли. Для этого нужно сформулировать торговую стратегию и реализовать ее в виде программы на языке MQL...
Files:
 
MakarFX:

1. Check the indices

2. Why do you need these 2 buffers?

With one buffer ExtTempBuffer[i]=ExtTempBuffer[i+1] didn't work, decided to try it this way, but it didn't work either.

 
Michail_David:

With one buffer ExtTempBuffer[i]=ExtTempBuffer[i+1] didn't work, I decided to try it this way, but it didn't work either.

I posted the working code

 
MakarFX:

Catch

Thanks Mark. Same error again on the same line when testing. It's not working in any way.

This is what 2020.11.03 23:38:19.815 2020.07.10 16:10:00 MSBB EURUSD,M5: array out of range in 'MSBB.mq4' (78,20)


 
Michail_David:

Thank you, Mark. Same error again on the same line when testing. It's not working in any way.

This is what it says 2020.11.03 23:38:19.815 2020.07.10 16:10:00 MSBB EURUSD,M5: array out of range in 'MSBB.mq4' (78,20)


I don't get any error, but logs are huge because of

Print ("ExtSignalBuffer = ", ExtSignalBuffer[i]);
 
MakarFX:

I'm not getting any errors, but the logs are huge because of

Yeah. Same. I don't seem to have accounted for all the conditions. On the signal value many are huge. Thanks for your help. I'll keep looking at the conditions.

 
Александр:

It does not open because one of the conditions is not met.

It's

or this

Comment out the two flashes // and you'll see which one it is. That's how you will find the error.

Thanks alexander!

 
MakarFX:

Catch

It compiles without any problems

'MSBB.mq4' MSBB.mq4 1 1
'MovingAverages.mqh' MovingAverages.mqh 1 1
0 errors, 0 warnings, 187 msec elapsed 1 1

Reason: