Equity oscillator by MQL5 means - page 2

 
DV2010: but why is a changing Equity value not shown on the Indicator, although changing values (checked!) are written to the Indicator array?

Nothing is written there, the loop is not called. Check it yourself.
 

That's the thing: the loop is called on all ticks!

See for yourself! I put the output into the body of the loop on purpose:

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[]){
   for (int i = prev_calculated; i <= rates_total-1; ++i){
      Print("Equity - OnCalculate - Cycle: prev_calculated=",prev_calculated,"   rates_total=",rates_total);
      Print("Equity - OnCalculate - Cycle: AccountInfoDouble(ACCOUNT_EQUITY)=", AccountInfoDouble(ACCOUNT_EQUITY));
      Values[i] = AccountInfoDouble(ACCOUNT_EQUITY);
   }
   return rates_total;
}

And here's the end result:

2011.01.20 13:58:56     Core 1  OnTester result 0
2011.01.20 13:58:56     Core 1  2011.01.14 23:59:59   order performed sell 0.15 at 1.33829 [#13 sell 0.15 EURUSD at 1.33829]
2011.01.20 13:58:56     Core 1  2011.01.14 23:59:59   deal performed [#13 sell 0.15 EURUSD at 1.33829]
2011.01.20 13:58:56     Core 1  2011.01.14 23:59:59   deal #13 sell 0.15 EURUSD at 1.33829 done (based on order #13)
2011.01.20 13:58:56     Core 1  2011.01.14 23:59:59   position closed due end of test at 1.33829 [buy 0.15 EURUSD 1.33593]
2011.01.20 13:58:56     Core 1  2011.01.14 22:00:00   Equity - OnCalculate - Cycle: AccountInfoDouble(ACCOUNT_EQUITY)=9949.299999999999
2011.01.20 13:58:56     Core 1  2011.01.14 22:00:00   Equity - OnCalculate - Cycle: prev_calculated=6418   rates_total=6419
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   CTrade::PositionOpen: instant buy 0.15 EURUSD at 1.33593 [done at 0.00000]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   order performed buy 0.15 at 1.33593 [#12 buy 0.15 EURUSD at 1.33593]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   deal performed [#12 buy 0.15 EURUSD at 1.33593]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   deal #12 buy 0.15 EURUSD at 1.33593 done (based on order #12)
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   instant buy 0.15 EURUSD at 1.33593 (1.33577 / 1.33593 / 1.33577)
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   CTrade::PositionClose: instant buy 0.15 EURUSD at 1.33593 [done at 0.00000]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   order performed buy 0.15 at 1.33593 [#11 buy 0.15 EURUSD at 1.33593]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   deal performed [#11 buy 0.15 EURUSD at 1.33593]
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   deal #11 buy 0.15 EURUSD at 1.33593 done (based on order #11)
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   instant buy 0.15 EURUSD at 1.33593 (1.33577 / 1.33593 / 1.33577)
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   Equity - OnCalculate - Cycle: AccountInfoDouble(ACCOUNT_EQUITY)=9929.65
2011.01.20 13:58:56     Core 1  2011.01.14 21:00:00   Equity - OnCalculate - Cycle: prev_calculated=6417   rates_total=6418
 
DV2010:

That's the thing: the loop is called on all ticks!

See for yourself! I put the output into the body of the loop on purpose:

And here's the end result:

What does testing have to do with it? Run the indicator on the chart and you will see. Just don't forget to make my edits.
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
  • www.mql5.com
Операции с графиками / ChartIndicatorAdd - Документация по MQL5
 

The testing here is that I need to see the change of Equity within the tested period on the history.

I have made your corrections, I ran the indicator both in testing mode and by dragging it to a new chart.

The indicator works for the entire period, up to the current quotes, as well as for any timeframe (or what exactly does it mean "you will see everything"?)

Nevertheless the Equity value remains constant, although the output to the log shows that it changes.

( Otherwise, how else can we tell if the loop is working or not, other than through Print? )

...Just in case, here is the "skeleton" of the Expert Advisor with indicator attached:

#property copyright "Copyright 2010, Pavlov Sergei"
#property link      ""
#property version   "1.00"

#include <\..\Experts\_My\Classes\ClassExpert\ClassExpert.mqh>
ClassExpert Expert1;

int Equity1=0;
void OnInit(){
   Equity1 = iCustom(NULL,0,"Equity",
                          5,          // Период
                          0,          // Смещение
                          MODE_SMA,   // Метод рассчета
                          PRICE_CLOSE // считаем по ценам закрытия)
                          );
   Expert1.Init();
}
void OnTick(){
   Expert1.OnTick();
}
void OnDeinit(const int reason){
   Expert1.Deinit();
}
 
DV2010:

The reason for testing here is that I need to see the change of Equity within the tested period on the history.

I have made your corrections, I ran the indicator both in test mode and by dragging and dropping it on a new chart.

The indicator works for the entire period, up to the current quotes, as well as for any timeframe (or what exactly does it mean "you will see everything"?)

Nevertheless the Equity value remains constant, although the output to the log shows that it changes.

( Otherwise, how else can we tell if the loop is working or not, other than through Print? )

...Just in case, here is the "skeleton" of the Expert Advisor with indicator attached:

There is no point in putting the wrong indicator into an EA, it won't make it any better. You still haven't checked my option?
 

Maybe I am mistaken, but don't you compare the indicator's appearance on the chart after the testing is completed with the calculations made during the testing?

The point is that the results (calculation arrays) of the custom indicator from the tester are not transferred to the chart in any way, but the specified indicator is simply launched on a new calculation on the chart.

Документация по MQL5: Операции с графиками / ChartIndicatorAdd
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
  • www.mql5.com
Операции с графиками / ChartIndicatorAdd - Документация по MQL5
 

Run this indicator on a minute chart (if you have an open position) and after 10-15 minutes you will get a picture like this.


Code:

//+------------------------------------------------------------------+
//|                                             Equity_Indicator.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double Values[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Values,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,100);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   ArraySetAsSeries(Values,false);
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {


   Print("prev_calculated=",prev_calculated,"   rates_total=",rates_total);
   int limit=prev_calculated;
   if(limit>0) limit--;

//---Блок заполнения Индикатора и журнала сообщений значениями
   for(int i=limit; i<rates_total;++i)
     {
      Values[i]=AccountInfoDouble(ACCOUNT_EQUITY);
     }
   return rates_total;
  }
//+------------------------------------------------------------------+
 

Roche, I already asked you what my indicator is wrong, and I wrote you about how I checked your variant as well . And I tried to explain it to you in as much detail as possible, while you wrote only briefly about "the loop doesn't work" and "you'll see for yourself"...

...Renat, as I understand it, the indicator will be displayed on the chart after the test is completed, based on the calculations made during the test and the filling of the indicator array. But what does it mean that the results from the tester are not transferred to the custom indicator chart from the tester?

Then what for do they need and why does the indicator line disappear at once, when I remove the assignment of values to an array from the code (even if it's a constant horizontal line, it disappears)?

I thought that the correspondence between the array of indicator values that are filled in at OnCalculated and the indicator values on the chart is unambiguous, otherwise how can the indicator values be initialized?

It is difficult to understand... It seems to be a trivial task, but I have been struggling with it for several days, and it is difficult to find someone who can at least hint how it can be solved differently on the history and whether it is solved at all.

Once again, as I understand it (correct me if I'm wrong, if you don't mind).

1.I specify a testing period in the tester and select an Expert Advisor with my indicator attached to it.

2. thefirst call OnCalculated is called with parameters prev_calculated =0 and rates_total = number of tick (bar) corresponding to the beginning of testing. Within this period, the value of balance remains at the initial and constant level.

Theconsecutive calls of OnCalculated by bar within the testing period, occur for each individual bar, and here we can initialize an array of indicator values with those data that changes (for example, duplicate the price, that I received, but then why not initialize Equity with the changing prices ?)

And anyway, you're a pro. I hope this simple task is solved, or MetaTraderhas yet to reach such "heights"? :)))

I have offered my simple solution to this problem, but it refuses to work.

Then how can it be implemented - an Equity chart below the price chart based on the results of testing on the history?

 
I will tell you one thing, it will not be easy to solve your problem until the visualization mode is launched. There is one solution: write the equity data to a file during the test. Then write the data from the file to the indicator buffer and plot the equity graph.
 

Rosh, the variant for online has already been posted, but as someone who works primarily with History, I need a variant that works on historical data. And I still find it difficult to understand what the main difficulty may be.

The trader has an idea about the balance graph online due to a smaller number of deals (unless he is an extrascalper who hardly has time to press Buy and Sell).

Indeed, the Equity dynamics becomes critical on a long history with hundreds or even thousands of trades, but the graph in the tester does not provide a simple comparison of these dynamics with the price dynamics in principle (unless, of course, MetaQuote considers the main thing for programmers to be a quick elimination of already prepared experts without the analysis of separate series of weak and strong positions).

Reason: