How to grab values from this custom indicator???

 

G'day all

I had this custom indicator made and for what I want it is a little beauty. It basically draws a box around inside bars, double inside bars, triple inside and so on.

But I had it designed to work on smaller timeframes. A couple of things I don't like. But those are separate issues. 

This pattern forms over a number of bars and as long as the pattern stays true, the indicator draws this box. But once the pattern is broken the box is cleared

of the chart. 

Chart EURUSD, None, 2015.12.30 05:39 UTC, International Capital Markets Pty Ltd., MetaTrader 4, Real

My question is how do I grab the valves of the highest high and lowest low and their corresponding bar shift value that forms the box pattern to use within a bot.

Again in the simplest form, I'm using this indicator to enter into a position when the price breaks out. I use the range of the box to set risk and  a multiple of the

range to set SL and TP. The bar shifts I use for direction. 

Thanks for any help and enjoy the indicator.

 
//+------------------------------------------------------------------+
//|                                             BreakoutBox v1.0.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
int      StartPoint        =  7;

input int      RangeBars         =  3;
input int      MinInsideBars     =  4;

input double   MinRangeValue     =  0.0;
input double   MaxRangeValue     =  0.0500;

input color    BoxColor          =  clrDodgerBlue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int _sp;
datetime startPointDate;
int OnInit()
  {
//--- indicator buffers mapping
   if(StartPoint<(RangeBars+MinInsideBars+1))_sp = (RangeBars+MinInsideBars+1);
   else _sp = StartPoint;
   
   startPointDate = Time[_sp];
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
datetime initTime;
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[])
  {
//---
   if(Time[0]!=initTime)
   {
      _sp = iBarShift(NULL,0,startPointDate);
      if(_sp > RangeBars+MinInsideBars)
      { 
         for(int i = _sp;i>0;i--)
         {
            bool valid = true;
            int bc = 0;
            
            double outH = High[iHighest(NULL,0,MODE_HIGH,RangeBars,i)];
            double outL = Low [iLowest (NULL,0,MODE_LOW, RangeBars,i)];
            
            if(outH-outL<MinRangeValue || outH-outL>MaxRangeValue)
            {
               ObjectDelete("B1"); ObjectDelete("B2");
                
               startPointDate = Time[i];
               continue;
            }   
            Print("---");
            
            for(int x = i-1;x>0;x--)
            {
               if(High[x]>outH)
               {
                   
                  valid = false;
                  break;
               }
               else if(Low[x]<outL)
               {
                  
                  valid = false;
                  break;
               }
               bc++;   
            } 
            
             
            
            if(valid && bc >= MinInsideBars)
            {
               drawBox("B1",Time[i], outH, Time[i+RangeBars-1], outL);
               drawBox("B2",Time[i], outH, Time[1], outL);
               break;
            }
            else 
            {
                
                startPointDate = Time[i];
                ObjectDelete("B1"); 
                ObjectDelete("B2");
            }
           
         }  
      }
      initTime = Time[0];    
    }

   return(rates_total);
  }
//+------------------------------------------------------------------+

void drawLine(string name,datetime time1, double price1, color c)
{
   ObjectDelete(name);
   ObjectCreate(name,OBJ_HLINE,0,time1,price1);
   ObjectSet(name,OBJPROP_COLOR, c);
   ObjectSet(name,OBJPROP_WIDTH,2);
    
}

void drawBox(string name,datetime time1, double price1, datetime time2, double price2, bool background=false)
{
     
   ObjectDelete(name);
   ObjectCreate(name,OBJ_RECTANGLE,0,time1,price1,time2,price2);
   ObjectSet(name,OBJPROP_COLOR, BoxColor);
   ObjectSet(name,OBJPROP_WIDTH,2);
   ObjectSet(name,OBJPROP_BACK,0);
}
 
  1. Detailed explanation of iCustom - MQL4 forum
  2. But since the indicator doesn't have any buffers you can only get information from the two rectangles (B1 & B2.) https://docs.mql4.com/objects/objectget
 

Thanks my friend.

One now presumes this will do the trick

//---Global variables                                      
double upper_level; //--- upper valve of rectangle
double lower_level; //--- lower valve of rectangle
int    upper_shift; //--- returns bar index for candle forming highest high
int    lower_shift; //--- returns bar index for candle forming lowest low

bool   Box_Present; //--- return true if box present

//+------------------------------------------------------------------+
//|   the main function of the expert                                |
//+------------------------------------------------------------------+
int start()
{
  {
   upper_level = 0.0; //--- reset variable
   lower_level = 0.0; //--- reset variable
   upper_shift =   0; //--- reset variable
   lower_shift =   0, //--- reset variable 
   
   Box_Present = false; // set flag to false

   int Find_B1=ObjectFind("B1"); //--- returns "0" if indicator present on main chart

   if(Find_B1==0) //--- box pattern is present
     {
      Box_Present=true; // set flag to true

      upper_level = ObjectGet("B1",OBJPROP_PRICE1); //--- upper level price value
      lower_level = ObjectGet("B1",OBJPROP_PRICE2); //--- lower level price value
      upper_shift = ObjectGetShiftByValue("B1",upper_level); //--- bar shift index for highest high
      lower_shift = ObjectGetShiftByValue("B1",lower_level); //--- bar shift index for lowest low
     }
  }
  //+-------------------------------------------------------------------------+
  //| From this point control reverts to EA's logic with the variables values |
  //| recalculated and able to be called upon in subsequence functions.       | 
  //+-------------------------------------------------------------------------+
  
  if(Box_Present) RunSomeFunction();
  
  return(0);
}

//+----------------------------------------+
//  Run some function                      |
//+----------------------------------------+
   void RunSomeFunction()
//+----------------------------------------+
{
//--- insert trade logic here
}
  

 

Also, as I was reading through the links you provided and someone posted you are better off writing the indicator logic into the EA rather than calling for it's values returned. In this case, would you agree or disagree with this statement.

 
int OnCalculate(const int rates_total,
                const int prev_calculated,
Normally indicator can''t be placed into an EA since you wouldn't have prev_calculated and can't use IndicatorCounted(). The code doesn't use either so it can be put into a EA.
Reason: