LifeHack Balance Equity 2

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
LifeHack Balance Equity 2
ÿþ//+------------------------------------------------------------------+

//|                                    LifeHack Balance Equity 2.mq5 |

//|                         Copyright © 2016-2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "2.000"

#property description "Balance Equity Indicator only new bar"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   2

#property indicator_type1   DRAW_LINE

#property indicator_type2   DRAW_LINE

#property indicator_color1  clrBlue

#property indicator_color2  clrGreen

#property indicator_width1  2

#property indicator_width2  2

#property indicator_label1  "Balance"

#property indicator_label2  "Equity"

//--- indicator buffers

double   BalanceBuffer[];

double   EquityBuffer[];

//--- parameters

int      Visiblebars = 300;

bool     FirstStart  = true;

//---

datetime m_prev_bars = 0;     // "0" -> D'1970.01.01 00:00';

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                         |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---



  }

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BalanceBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,EquityBuffer,INDICATOR_DATA);

//--- name for DataWindow and indicator subwindow label

   IndicatorSetString(INDICATOR_SHORTNAME,"Balance Equity ");

   PlotIndexSetString(0,PLOT_LABEL,"Balance");

   PlotIndexSetString(1,PLOT_LABEL,"Equity");

//--- construct a short indicator name based on input parameters

   IndicatorSetInteger(INDICATOR_DIGITS,2);

//--- sets drawing line to empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   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[])

  {

//--- we work only at the time of the birth of new bar

   datetime time_0=time[rates_total-1];

   if(time_0==m_prev_bars)

      return(rates_total);

   m_prev_bars=time_0;

   if(prev_calculated==0 && FirstStart)

     {

      FirstStart=false;

      for(int i=0; i<rates_total; i++)

        {

         BalanceBuffer[i]=AccountInfoDouble(ACCOUNT_BALANCE);

         EquityBuffer[i]=AccountInfoDouble(ACCOUNT_EQUITY);

        }

      return(rates_total);

     }

//---

   BalanceBuffer[rates_total-1]=AccountInfoDouble(ACCOUNT_BALANCE);

   EquityBuffer[rates_total-1]=AccountInfoDouble(ACCOUNT_EQUITY);

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments