//+------------------------------------------------------------------+
//|                                               Chart_in_Chart.mq4 |
//|                                      Copyright 2017, fxanalysis. |
//|                          https://www.forexfactory.com/fxanalysis |
//+------------------------------------------------------------------+
#property copyright "fxanalysis"
#property link      "https://www.forexfactory.com/fxanalysis"
#property version   "1.00"
#property strict
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                               //
//       modified by: ............   date: .......                                                               //
//                                                                                                               //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#property indicator_separate_window
#property indicator_buffers 7
extern string pair                  = "EURUSD";//Symbol(case sensitive)
extern ENUM_TIMEFRAMES timeFrame    = PERIOD_CURRENT;
//extern color backgroundColor        = clrGreen;
extern color bullishCandle          = clrGreen;
extern color bearishCandle          = clrRed;
extern color wickColor              = clrBlack;
extern bool  invertpair             = False;//Invert Chart
color backgroundColor=clrWhite;
double   arr1[],
         arr2[],
         arr3[],
         arr4[],
         arr5[],
         arr6[],
         backgound[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   
   backgroundColor=ChartGetInteger(0,CHART_COLOR_BACKGROUND);
//--- indicator buffers mapping
   IndicatorShortName("Chart in Chart - "+pair+" - "+EnumToString(timeFrame));
   SetIndexBuffer(0,backgound);
   SetIndexBuffer(1,arr1);
   SetIndexBuffer(2,arr2);
   SetIndexBuffer(3,arr3);
   SetIndexBuffer(4,arr4);
   SetIndexBuffer(5,arr5);
   SetIndexBuffer(6,arr6);
   if(WindowBarsPerChart()<=200)
      {
      SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,7,backgroundColor);
      SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,1,wickColor);
      SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,3,bullishCandle);
      SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,3,bearishCandle);
      SetIndexStyle(4,DRAW_HISTOGRAM,EMPTY,5,backgroundColor);
      SetIndexStyle(5,DRAW_HISTOGRAM,EMPTY,1,wickColor);
      SetIndexStyle(6,DRAW_HISTOGRAM,EMPTY,5,backgroundColor);
      }
   else
      {
      SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,7,backgroundColor);
      SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,1,wickColor);
      SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,2,bullishCandle);
      SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,2,bearishCandle);
      SetIndexStyle(4,DRAW_HISTOGRAM,EMPTY,3,backgroundColor);
      SetIndexStyle(5,DRAW_HISTOGRAM,EMPTY,1,wickColor);
      SetIndexStyle(6,DRAW_HISTOGRAM,EMPTY,3,backgroundColor);
      }
   
//---
   return(INIT_SUCCEEDED);
  }
double minusGap()
   {
   return(1.0/multiply());
   }
int multiply()   // meant to get multiplyer so jpy data can be multipied and shown in pips
   {
   if((0<StringFind(pair, "JPY", 0))==True)
      {
      return(100);
      }
   else
      {
      return(10000);
      }
   }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int i,countedBars=IndicatorCounted();
   int limit=Bars-countedBars;
   for(i=0;i<limit;i++)
      {
    
      arr1[i]= (!invertpair)?iHigh(pair,timeFrame,i):-iHigh(pair,timeFrame,i);
      if(iOpen(pair,timeFrame,i)>iClose(pair,timeFrame,i))
         {
         arr3[i]=(!invertpair)?iOpen(pair,timeFrame,i):-iOpen(pair,timeFrame,i);
         arr4[i]=(!invertpair)?(iClose(pair,timeFrame,i)-minusGap()):-(iClose(pair,timeFrame,i)-minusGap());
         arr5[i]=(!invertpair)?iClose(pair,timeFrame,i):-iClose(pair,timeFrame,i);
         }
      else
         {
         arr2[i]=(!invertpair)?iClose(pair,timeFrame,i):-iClose(pair,timeFrame,i);
         arr4[i]=(!invertpair)?(iOpen(pair,timeFrame,i)-minusGap()):-(iOpen(pair,timeFrame,i)-minusGap());
         arr5[i]=(!invertpair)?iOpen(pair,timeFrame,i):-iOpen(pair,timeFrame,i);
         }
      
      arr6[i]=(!invertpair)?iLow(pair,timeFrame,i):-iLow(pair,timeFrame,i);
      
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
