Libraries: BestInterval - page 14

 
gspencer:
I know nothing about coding or working with EA's in Meta Editor, but I really like your concept with the BestInterval. Would it be too much trouble for you to instruct me on how to add it to the EA's I have that I would like to test?

Try to understand this thread discussion.

Библиотеки: BestInterval
Библиотеки: BestInterval
  • 2018.10.12
  • www.mql5.com
Статьи и техническая библиотека по автоматическому трейдингу: Библиотеки: BestInterval
 
// Display the BestInterval balance chart on the chart

#property strict
#property script_show_inputs

input int inAmountIntervals = 3; // How many worst-case trade intervals to throw away

#include <Graphics\Graphic.mqh> // https://www.mql5.com/en/articles/2866

void ToChart( const double &Y[] )
{
   CGraphic graphic;
   graphic.Create(0, __FUNCTION__, 0, 30, 30, 780, 380);
   graphic.CurveAdd(Y, CURVE_LINES);
   graphic.CurvePlotAll();
   graphic.Update();   
}

#include <MT4Orders.mqh> // Not required if MT4.
#include <fxsaber\BestInterval\BestInterval.mqh> // Calculation of the best trading interval

void OnStart()
{
  BESTINTERVAL BestInterval; // Created an object to calculate the best trading interval
  
  BestInterval.Set(); // Posted a history of bidding
          
  for (int i = 0; i < inAmountIntervals; i++)
    if (BestInterval.DeleteWorseInterval()) // If something was thrown away
      Print(BestInterval.ToString());       // Let's print out the obtained trade data
    else
      break;                                // Otherwise, we're out
      
  double Profits[];
  double Balance[];
  
  const int Size = ArrayResize(Balance, BestInterval.GetProfits(Profits) + 1); // We got the BestInterval-transaction profits
  Balance[0] = 0;  
  
  // Calculate the balance curve
  for (int i = 1; i < Size; i++)
    Balance[i] = Balance[i - 1] + Profits[i - 1];
    
  ToChart(Balance); // Visualised.
}
 
If you insert this at the end of any EA from the standard delivery
// Transmit quotes of each pass of the Optimiser to the Terminal. Apply BestInterval to them and visualise them.

#include <MT4Orders.mqh>                         // https://www.mql5.com/en/code/16006
#include <fxsaber\BestInterval\BestInterval.mqh> // https://www.mql5.com/en/code/22710
#include <TypeToBytes.mqh>                       // https://www.mql5.com/en/code/16280
#include <Graphics\Graphic.mqh>                  // https://www.mql5.com/en/articles/2866

input int inAmountIntervals = 1; // How many worst-case trade intervals to throw away

// Outputs the graph
void ToChart( const double &Y[] )
{
   CGraphic graphic;
   graphic.Create(0, __FUNCTION__, 0, 30, 30, 780, 380);
   graphic.CurveAdd(Y, CURVE_LINES);
   graphic.CurvePlotAll();
   graphic.Update();   
}

// Collects trade history
int GetDeals( DEAL_BASE &Deals[] )
{  
  const int Total = ArrayResize(Deals, OrdersHistoryTotal());
  int Amount = 0; 
  
  for (int i = 0; i < Total; i++)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL))
    {
      Deals[Amount].OpenTime = OrderOpenTime();
      Deals[Amount++].Profit = OrderProfit() + OrderCommission() + OrderSwap();
    }
      
  return(ArrayResize(Deals, Amount));    
}

// From here (Agent) we will send data to the Terminal
double OnTester()
{
  DEAL_BASE Deals[];
  
  if (MQLInfoInteger(MQL_OPTIMIZATION) && GetDeals(Deals)) // If Optimisation, collected trade history
  {    
    CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205
    
    Container[0] = Deals; // Put the bidding history into a container
  
    FrameAdd(NULL, 0, 0, Container.Data); // Sent data from the Agent to the Terminal
  }
  
  return(0);
}

// Here (Terminal) receive data from Agents
void OnTesterPass()
{    
  ulong Pass;
  string Name;
  long ID;
  double Value;

  CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205

  while (FrameNext(Pass, Name, ID, Value, Container.Data))
  {
    Print("Pass = " + (string)Pass); // Pass number
    
    DEAL_BASE Deals[];
   
    // Received data from the Agent
    Container[0].Get(Deals);
          
    BESTINTERVAL BestInterval; // Created an object to calculate the best trading interval
    
    BestInterval.Set(Deals);   // Posted the transmitted bidding history

    Print(BestInterval.ToString() + "\n");           // Let's print out the obtained trade data
            
    for (int i = 0; i < inAmountIntervals; i++)
      if (BestInterval.DeleteWorseInterval())        // If something has been thrown away
        Print(BestInterval.ToString() + "\n");       // Let's print out the obtained trade data
      else
        break;                                       // Otherwise, we're out
        
    double Profits[];
    double Balance[];
    
    const int Size = ArrayResize(Balance, BestInterval.GetProfits(Profits) + 1); // We got the BestInterval-transaction profits
    Balance[0] = 0;  
    
    // Calculate the balance curve
    for (int i = 1; i < Size; i++)
      Balance[i] = Balance[i - 1] + Profits[i - 1];
      
    ToChart(Balance); // Visualised.    
  }
}


you will see something like this in the Terminal log (by the example of the standard Moving Averages)

Pass = 0
Amount of Delete Intervals = 0 (2018.10.01 - 2019.02.05)
00:00:00 - 23:59:59 : Profit = -8498.94 (100.00%), Total = 6394 (26.07%), PF = 0.52, Mean = -1.33, DD = 8660.23, RF = -0.98
SUMMARY: 00:00:00 - 23:59:59 : Profit = -8498.94 (100.00%), Total = 6394 (26.07%), PF = 0.52, Mean = -1.33, DD = 8660.23, RF = -0.98

Amount of Delete Intervals = 1 (2018.10.01 - 2019.02.05), 18:00 - 18:00, CountHours = -1
17:40:01 - 17:42:59 : Profit = 364.25 (100.00%), Total = 9 (100.00%), PF = Max, Mean = 40.47, DD = 4.63, RF = 78.67
SUMMARY: 00:00:00 - 23:59:59 : Profit = 364.25 (100.00%), Total = 9 (100.00%), PF = Max, Mean = 40.47, DD = 4.63, RF = 78.67

Pass = 1
Amount of Delete Intervals = 0 (2018.10.01 - 2019.02.05)
00:00:00 - 23:59:59 : Profit = -9757.53 (100.00%), Total = 6394 (24.70%), PF = 0.55, Mean = -1.53, DD = 10076.19, RF = -0.97
SUMMARY: 00:00:00 - 23:59:59 : Profit = -9757.53 (100.00%), Total = 6394 (24.70%), PF = 0.55, Mean = -1.53, DD = 10076.19, RF = -0.97

Amount of Delete Intervals = 1 (2018.10.01 - 2019.02.05), 09:00 - 10:00, CountHours = 0
08:27:01 - 10:14:59 : Profit = 628.59 (100.00%), Total = 472 (39.41%), PF = 1.39, Mean = 1.33, DD = 550.93, RF = 1.14
SUMMARY: 00:00:00 - 23:59:59 : Profit = 628.59 (100.00%), Total = 472 (39.41%), PF = 1.39, Mean = 1.33, DD = 550.93, RF = 1.14


And the chart shows the BestInterval-profit chart of the corresponding pass


 

I was passing by. I read it.

The description says, "

  • The idea is the author's. There may be analogues.

"

Something more generalised I described in a blog in English(part 1, part 2). Doing cross sections only on time intervals is a highly specialised approach. In idea, cross sections on other parameters could be equally interesting.

 
Stanislav Korotky:

I was passing by. I read it.

The description says, "

  • The idea is the author's. There may be analogues.

"

Something more generalised I described in the English blogposition opening. Accordingly, all positions in the trading history can be compared to these MA values.

And then we apply BestInterval to these MAs. And at the output we get the ranges of МАшки in which positions should be opened, and in which ones - not.


Of course, you can use any numeric function instead of a MA. As a result, you can find cool filters that outperform time.

 
fxsaber:

Unfortunately, the language barrier prevents me from getting into your work. About the interest in other filters, of course, I agree

Since when did such a barrier arise? ;-) It was clear before. Or did I mess up my English?

 
Stanislav Korotky:

Since when did such a barrier arise? ;-) It used to be clear. Or did I mess up my English?

There was always a barrier. Sometimes I went straight ahead - reading the source code.

 
fxsaber:

Unfortunately, the language barrier prevents me from getting into your work. About the interest in other filters, of course, I agree

God is your judge.

 
Memo
#include <fxsaber\BestInterval\BestInterval.mqh>

void OnStart()
{
  BESTINTERVAL BestInterval;

  // Corresponding values for the whole BestInterval
  Print(BestInterval.GetTotal());          // Number of closed positions.
  Print(BestInterval.GetTotalPlus());      // Number of profitable closed positions.
  Print(BestInterval.GetTotalMinus());     // Number of unprofitable closed positions.
  Print(BestInterval.GetMean());           // Math. expectation
  Print(BestInterval.GetProfit());         // Profit
  Print(BestInterval.GetProfitFactor());   // Profit Factor
  Print(BestInterval.GetProfitPlus());     // Profit of positive transactions
  Print(BestInterval.GetProfitMinus());    // Loss of negative transactions
  Print(BestInterval.GetRecoveryFactor()); // Recovery Factor
  Print(BestInterval.GetMaxDrawDown());    // Maximum absolute balance drawdown

  Print(BestInterval.GetAmountDeleteIntervals()); // Number of bad intervals removed

  INTERVAL Intervals[];

  const int Size = BestInterval.GetIntervals(Intervals); // Get the intervals that make up the BestInterval

  // For each interval we printed its indices
  for (int i = 0; i < Size; i++)
  {
    Print(Intervals[i].Total);          // Number of closed positions.
    Print(Intervals[i].TotalPlus);      // Number of profitable closed positions.
    Print(Intervals[i].TotalMinus);     // Number of unprofitable closed positions.
    Print(Intervals[i].Mean);           // Math. expectation
    Print(Intervals[i].Profit);         // Profit
    Print(Intervals[i].ProfitFactor);   // Profit Factor
    Print(Intervals[i].ProfitPlus);     // Profit of positive transactions
    Print(Intervals[i].ProfitMinus);    // Loss of negative transactions
    Print(Intervals[i].RecoveryFactor); // Recovery Factor
    Print(Intervals[i].MaxDrawDown);    // Maximum absolute balance drawdown

    Print(Intervals[i].OpenTime);       // Interval open time.
    Print(Intervals[i].CloseTime);      // Interval closing time.
  }
}
 
Stanislav Korotky:

Making cross sections only by time intervals is a highly specialised approach. In fact, cross-sections by other parameters can be no less interesting.

I've been thinking and thinking, but I haven't come up with something that can be filtered as effectively as time.

This something should not be part of the strategy and should directly influence the market behaviour.

stack? other datafeeds?

and another question - is there any sense in making hypercubes? in theory, individually it should be filtered well too.