Errors, bugs, questions - page 1699

 
Karputov Vladimir:
You can't blame every wrong programming style on bugs.

What kind of a SURPRISE is this?! I point out an obvious bug, and I get this nonsense about "style".

I'm as far away from A100 and Meat as the moon. They show you bugs, though I don't understand them. But I'm not going to bring my "style" to the table.

 
fxsaber:
It doesn't work.

Here is the full code:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

double Buffer[];

int handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnInit()
  {
   SetIndexBuffer(0,Buffer,INDICATOR_DATA);

   handle=ChartIndicatorGet(0,1,ChartIndicatorName(0,1,0));
  }

#define  TOSTRING(A) #A + " = " + (string)A + "\n"
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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(handle!=INVALID_HANDLE)
   if(prev_calculated!=0)
     {
      Buffer[rates_total-1]=MathRand();

      double BufferCopy[];
      Print(__FUNCTION__);
      if(CopyBuffer(handle,0,0,1,BufferCopy)>0)
         Print(TOSTRING(BufferCopy[0])+TOSTRING(Buffer[rates_total-1]));
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int Reason)
  {
   Print("#1 OnDeinit");
   if(handle!=INVALID_HANDLE)
     {
      Print("#2 OnDeinit");
      IndicatorRelease(handle);
      Print("#3 OnDeinit");
     }
   Print("#4 OnDeinit");
   return;
  }
//+------------------------------------------------------------------+

and a printout:

2016.09.23 12:34:03.318 2 (SBRF-12.16,M1)       OnCalculate
2016.09.23 12:34:03.318 2 (SBRF-12.16,M1)       BufferCopy[0] = 265.0
2016.09.23 12:34:03.319 2 (SBRF-12.16,M1)       Buffer[rates_total-1] = 18992.0
2016.09.23 12:34:03.319 2 (SBRF-12.16,M1)       
2016.09.23 12:34:03.502 2 (SBRF-12.16,M1)       OnCalculate
2016.09.23 12:34:03.502 2 (SBRF-12.16,M1)       BufferCopy[0] = 265.0
2016.09.23 12:34:03.502 2 (SBRF-12.16,M1)       Buffer[rates_total-1] = 12498.0
2016.09.23 12:34:03.502 2 (SBRF-12.16,M1)       
... экономия бумаги :)
2016.09.23 12:34:31.804 2 (SBRF-12.16,M1)       
2016.09.23 12:34:33.159 2 (SBRF-12.16,M1)       OnCalculate
2016.09.23 12:34:33.159 2 (SBRF-12.16,M1)       BufferCopy[0] = 614.0
2016.09.23 12:34:33.159 2 (SBRF-12.16,M1)       Buffer[rates_total-1] = 5343.0
2016.09.23 12:34:33.159 2 (SBRF-12.16,M1)       
2016.09.23 12:34:36.870 2 (SBRF-12.16,M1)       OnCalculate
2016.09.23 12:34:36.870 2 (SBRF-12.16,M1)       BufferCopy[0] = 614.0
2016.09.23 12:34:36.870 2 (SBRF-12.16,M1)       Buffer[rates_total-1] = 17815.0
2016.09.23 12:34:36.870 2 (SBRF-12.16,M1)       
2016.09.23 12:34:38.445 2 (SBRF-12.16,M1)       #1 OnDeinit
2016.09.23 12:34:38.445 2 (SBRF-12.16,M1)       #2 OnDeinit
2016.09.23 12:34:38.445 2 (SBRF-12.16,M1)       #3 OnDeinit
2016.09.23 12:34:38.445 2 (SBRF-12.16,M1)       #4 OnDeinit
Files:
2.mq5  3 kb
 
Karputov Vladimir:

Here is the full code:

and a printout:

It doesn't work for me - it doesn't even get to OnDeinit.

And notice that my numbers match in the log, but yours do not. My log

PP      0       12:41:08.169    Test3 (RTS-12.16,H1)    OnCalculate
FE      0       12:41:08.169    Test3 (RTS-12.16,H1)    BufferCopy[0] = 13573.0
IQ      0       12:41:08.169    Test3 (RTS-12.16,H1)    Buffer[rates_total-1] = 13573.0
CF      0       12:41:08.169    Test3 (RTS-12.16,H1)    
JO      0       12:41:08.169    Test3 (RTS-12.16,H1)    OnCalculate
QI      0       12:41:08.169    Test3 (RTS-12.16,H1)    BufferCopy[0] = 25434.0
NM      0       12:41:08.169    Test3 (RTS-12.16,H1)    Buffer[rates_total-1] = 25434.0
MJ      0       12:41:08.169    Test3 (RTS-12.16,H1)    
DJ      0       12:41:08.187    Test3 (RTS-12.16,H1)    OnCalculate
QO      0       12:41:08.187    Test3 (RTS-12.16,H1)    BufferCopy[0] = 9469.0
HK      0       12:41:08.187    Test3 (RTS-12.16,H1)    Buffer[rates_total-1] = 9469.0
CM      0       12:41:08.187    Test3 (RTS-12.16,H1)    
JF      0       12:41:08.187    Test3 (RTS-12.16,H1)    OnCalculate
OS      0       12:41:08.187    Test3 (RTS-12.16,H1)    BufferCopy[0] = 1887.0
NG      0       12:41:08.187    Test3 (RTS-12.16,H1)    Buffer[rates_total-1] = 1887.0
I don't have a single indicator or EA running in my terminal.
 
fxsaber:

It doesn't work for me - it doesn't even get to OnDeinit.

And notice that my numbers match in the log, but yours do not. My log

I don't have any indicator or Expert Advisor running in my terminal.

I have this configuration:

2016.09.23 12:25:34.874 Terminal        MetaTrader 5 x64 build 1430 started (MetaQuotes Software Corp.)
2016.09.23 12:25:34.876 Terminal        Windows 10 Pro (x64 based PC), IE 11.00, UAC, Intel Core i3-3120 M  @ 2.50 GHz, RAM: 2446 / 8077 Mb, HDD: 40118 / 233310 Mb, GMT+02:00
2016.09.23 12:25:34.876 Terminal        C:\Users\KVN\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075

(After restarting the thermal, log tab, first three lines)

 
Karputov Vladimir:

I have this configuration:

(After restarting the thermal, Log tab, first three lines)

2016.09.23 12:42:22.405 Terminal        C:\Program Files\BCS Broker MetaTrader 5 Terminal
2016.09.23 12:42:22.405 Terminal        Windows 7 Ultimate (x64 based PC), IE 09.00, Intel Core i7-2700 K  @ 3.50 GHz, RAM: 8098 / 16301 Mb, HDD: 6387 / 30000 Mb, GMT+02:00
2016.09.23 12:42:22.405 Terminal        BCS Broker MetaTrader 5 Terminal x64 build 1430 started (BCS Broker)
 
fxsaber:

Ambiguous. On x32 machine:

2016.09.23 13:23:55.052 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
2016.09.23 13:23:55.052 Terminal        Windows 10 Home (X86 based PC), IE 11.00, UAC, Intel Atom  Z3740 @ 1.33 GHz, RAM: 607 / 1931 Mb, HDD: 20500 / 49784 Mb, GMT+02:00
2016.09.23 13:23:55.049 Terminal        MetaTrader 5 build 1430 started (MetaQuotes Software Corp.)


Doesn't work.

 
Andrey Barinov:
They "drop out", but there will be a compilation error when trying to call them.

I don't need it that way, I'm trying to do a lot of work to make my life easier in the future.

I've overcome my problem this way in the parent all protec and inherit goes under protec then override.

 
Karputov Vladimir:

Ambiguous. On x32 machine:


Doesn't work.

Application has been made, even though I'm sick of doing it so often.
 
fxsaber:

How do I know my handle on a chart in an indicator?ChartIndicatorName is not suitable, because it returns a short name. And with the same name may be already running the same indicator with different input parameters.

I need it to be able to remove the indicator from chart and calculations.

You may have already figured it out, but I will clarify it just in case. The handle of the indicator is actually only the reference to the description of the indicator inside the program that created it (i.e., Expert Advisor, indicator, script), we can consider it to be a kind of "number". This means that this "number" has no meaning outside of the program that created the indicator (that got its handle). Even the program that calls the ChartIndicatorGet() function doesn't get some global indicator handle, it only creates the description of this indicator and allocates its "number" for addressing. There is no global indicator handle, unique within the entire terminal.

Use of short name can be seen in the examples. You can do this:

   string short_name="unknown ma";
   switch(InpMAMethod)
     {
      case MODE_EMA :  short_name="EMA";  break;
      case MODE_LWMA : short_name="LWMA"; break;
      case MODE_SMA :  short_name="SMA";  break;
      case MODE_SMMA : short_name="SMMA"; break;
     }
   IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")");

This solves the problem of " the sameindicatorhas already been run with different input parameters".

And visually it is clearer which indicator works:


 
Anton:

You may have already figured it out, but I will clarify it just in case. The indicator handle is actually just an address to the description of the indicator inside the program that created it (i.e., Expert Advisor, indicator, script), we can consider it to be a kind of "number". This means that this "number" has no meaning outside of the program that created the indicator (that got its handle). Even the program that calls the ChartIndicatorGet() function doesn't get some global indicator handle, it only creates the description of this indicator and allocates its "number" for addressing. There is no global indicator handle, unique within the entire terminal.

You can see the use of ShortName in the examples. You can do it like this:

This solves the problem of " the sameindicatorhas already been run with different input parameters".

And visually it is easier to understand which indicator works:

Thanks, that's about how stringo explained it to me some time ago. I found several ways to determine that the handle belongs to "me":

  1. I change the extreme value of the indicator buffer and compare it with the corresponding CopyBuffer value. If it matches, it's "me". That's the idea behind the undeletable indicator.
  2. I change ShortName and compare with ChartIndicatorName.

Reason: