Simple Indicator Code Question

 

Hello

I've attached an image of a test indicator applied to a live chart and to a strategy test - The same indicator stored in a template EA


The image shows different results , this is the test code below

Can anyone help me understand what the issue is ?

#property copyright ""
#property link      ""
#property version   ""
#property strict
#property indicator_separate_window
#property indicator_buffers 1  
#property indicator_color1                      clrRed
#property indicator_style1                      STYLE_SOLID
#property indicator_type1                       DRAW_LINE

input    int   inpTestBars  =  5;

double      TestBuffer[];

#define Test1 0

int OnInit()
  {
   SetIndexBuffer(Test1, TestBuffer);
   SetIndexLabel(Test1,"Test");
   return(INIT_SUCCEEDED);
  }
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[])
    {            
 int limit=rates_total-prev_calculated;
   if (prev_calculated>0)
      limit++;
for (int i=limit-1; i>=0; i--)
   {
   // Get Highest & Lowest bar number for TestPreiod
   int MyHighestBar= iHighest(NULL,0,MODE_HIGH,inpTestBars,i+1);
   // Store Highest & Lowest price for TestPreiod
   double MyHighestPrice=iHigh(Symbol(),Period(),MyHighestBar);   
   // Perform a simple calulation
   double xStoredResult = 0;
   // Loop through test period and store result
   // Add the difference from High to Open for each bar to xStoredResult
      for (int x=inpTestBars-1; x>=0; x--) 
      {
        xStoredResult=xStoredResult+(MyHighestPrice-iOpen(Symbol(),Period(),x+1));
       }
       // Update the Buffer
       TestBuffer[i]=xStoredResult;
      }
     return(rates_total);
}
Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
  • www.metatrader5.com
The Strategy Tester allows you to test and optimize trading strategies ( Expert Advisors ) before using them for live trading. During testing, an...
Files:
sample.png  154 kb
 

Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
          Messages Editor

Reason: