CEquityHstBar – library MetaTrader 4

CEquityHstBar is the library for showing the equity of EA back-testing on an offline chart. The class is designed to write the equity data in back-testing into .hst file, and then show the equity on an offline chart.

The .hst file is in the \tester folder, call CopyFile() to copy it to the history folder, and then open it from “File” → “Open Offline”.

  • <Data folder>\tester\files\
  • <Data folder>\history\account server\

Usage

  1. Create an instance of CEquityHstBar.
  2. Call Update() in OnTick().
  3. Call SaveData() in OnDeinit().
  4. Call CopyFile() in OnDeinit().
  5. Open the .hst file from “File” → “Open Offline”.
//+------------------------------------------------------------------+
//|                                            test_EquityHstBar.mq4 |
//|                                          Copyright 2017,fxMeter. |
//|                             |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,fxMeter."
#property link      ""
#property version   "1.00"
#property strict
#include <EquityHstBar.mqh>

//--- create an instance 
CEquityHstBar ebar("EquityBar",PERIOD_M30);

//--- or create an instance 
// CEquityHstBar ebar;  

int pt=1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(Digits()==5 || Digits==3)pt=10;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---      
   ebar.SaveData();
   ebar.CopyFile();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ebar.Update();

   static double stoploss=20;   //Pips
   static double takeprofit=30; //Pips
   int tkt=-1;
   if(OrdersTotal()==0)
     {
      if(Hour()/2==0) tkt=OrderSend(Symbol(),0,0.1,Ask,10,Ask-stoploss*pt*Point,Ask+takeprofit*pt*Point);
      else tkt=OrderSend(Symbol(),1,0.1,Bid,10,Bid+stoploss*pt*Point,Bid-takeprofit*pt*Point);
     }
  }
//+------------------------------------------------------------------+

📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks