//+------------------------------------------------------------------+
//|                                         Sedona Sessions Hilo.mq4 |
//|                                               Ver 1.  2007-04-30 |
//|                                  Script author/hacker: pips4life |
//|                                  Sedona method by sahamdarjoz    |
//|  First draft by a hacker = BUGGY!                                |
//+------------------------------------------------------------------+
//Some code ideas came from i-Sessions.mq4 by: "Êèì Èãîðü Â. aka KimIV" //"http://www.kimiv.ru"
//Also, other code ideas came from metto of www.forexfactory.com, from Sessions Hilo.mq4
//I got a lot of syntax help from http://docs.mql4.com 
//
//For newbies -- a group I'm still a member of -- put this file into directory:
//  C:\Program Files\{your broker_metatrader folder}\experts\indicators
//  (Some platforms reportedly have a different path)
//  From Metatrader4 (MT4), click on the MetaEditor icon. Open this script and
//  click the "Compile" button.  That should create a binary .ex4 file.
//  Then in MT4, from the Indicators button, find "Custom" and then this
//  script name.
//
// General notes:
// * Built for sahamdarjoz's Sedona method: http://www.forexfactory.com/showthread.php?t=26575
// * This first draft is buggy.  See Enhancement/Bug_Fix ideas below.  I welcome any help!!
// * There are 4 sessions: Tokyo, Europe, London, NewYork.   The times are in GMT.  Change
//     each session property to "true" or "false" as desired. Tokyo/London (GBPJPY) is default.
// * The DST_GMT_Hours_Offset variable is very useful to tailor to YOUR MT4 platform/broker timezone.
//     I recommend to compile, display Tokyo and London sessions, then 
//     look at GBPJPY 15min chart on April 18th and compare to the chart in the 1st thread above.
//     Vary the Offset until it lines up, then hard-code that value below and recompile.
//     E.g. MT4 from NorthFinance needs offset "2", whereas InterbankFX is "-1".
//     FYI, the first Tokyo session candle for that day, is like a little "shooting star".
//     On InterbankFX, the numbers were:
//     2007.04.17 23:00, Open: 238.74, Close .92(up), High .74, Low .76.
// * Session GMT times are somewhat arbitrary in a 24-hour market. I followed the thread
//     session hours, but other sources have different ideas.  Fine tune as you see fit.
// * If you track two common pairs, e.g. GBPJPY and GBPUSD, I suggest to save this indicator 
//     as two separate names, and edit the variable defaults so you can trivially use this.
//
// Enhancement/Bug_Fix Ideas:
// * REAL TIME updates of the lines!!! They don't paint during live action!
//     So, this is good for reviewing price history but not as good live.
// * Suggestions for better colors are welcome.
// * FYI, my code is just a hack.  I took two very different styles of programs
//     and put them together, and expanded on each.  I have no idea if the approach
//     is valid or good or bad.  I don't understand Bar(0) vs. other things.  Code improvements
//     are welcome; even a complete rewrite by somebody who knows programming, or an EA!
// * A cyclic with currency pairs would be nice, rather than booleans for each session.
//     However, it is sometimes nice to see all the sessions, or just one, so the cyclic
//     should list many combinations. Example, where T[okyo], E[urope], L[ondon], N[ewYork]:
//     TELN, TE, TEL, TL (this is for GBPJPY!), EL, EN (EURUSD), LN (GBPUSD), NT, T, E, L, N.
//     The cyclic would control visability for the sessions.  I couldn't find another script
//     example which used cyclics as described, else I would have done it.
// * Right now, the individual session rectangles are displayed but lines are based on
//     the total combined sessions.  One can toggle to display the Cycle (full) session,
//     but it's too cluttered with the other individual sessions.  Would be nice if the Cycle
//     could give the option to turn OFF the individuals, so you see only the main Cycle.
//     One can do it now by changing colors to "None" (or NULL, or your background color).
// * It would make sense to add either RSI(9,Open), or at least to detect whether RSI > 70 occurs
//     when the session high occurs, and if RSI < 30 occurs when the session low occurs.
//     Perhaps one could then suspend drawing either the High lines, and/or Low lines
//     when there is no RSI trigger-signal
// * Perhaps adding EMA62(Open) indicator to this code would be good, although it can always
//     be displayed separately, just like RSI9.
// * Would like to have the high/low/SL/10/20 lines display on the 
//     last bar of active trading session(s) ASAP rather than 1 bar later. Possible???
//     I did some things to try to do this but it's not working.
// * Sometimes when scrolling backwards/forwards, the hi/lo/etc. lines get 
//     screwed up.  I have to delete the indicator and add it back.  I *may* have
//     fixed this just now by putting the DrawLines outside of the daily "for" loop. Duh.
// * The HiLo lines ignore the NumberOfDays variable, as they go back in time all the way. 
//     Not sure this causes any performance problems or not.
// * Consider changing width of Hi/Lo/SL/10/20 line(s). A little bolder might look better.
// * Changing indicator properies (as opposed to setting them the FIRST time) might cause
//     the HiLo lines to persist in the wrong session area.  Can old DRAW_LINES be erased/cleared??
// * Turn this, or other create from scratch, an EA for this Sedona method.


#property copyright "pips4life"
#property link      ""


#property indicator_chart_window
#property indicator_buffers 8    // Is the maximum 8??  I think so...
#property indicator_color1 White // SesHigh
#property indicator_color2 White // SesLow
#property indicator_color3 Red   // SesHighSL
#property indicator_color4 Red   // SesLowSL
#property indicator_color5 Aqua  // SesHigh10
#property indicator_color6 Aqua  // SesLow10
#property indicator_color7 Aqua  // SesHigh20
#property indicator_color8 Aqua  // SesLow20
// FYI, it 8's the limit, consider deleting the two Ses*10 indicators in favor of EMA62 and RSI9.
// Consider mfodifying indicator_width# as desired
#property indicator_width1 3 // SesHigh
#property indicator_width2 3 // SesLow

// Customizable properties
extern int    NumberOfDays = 60;              //
// MT4 from NorthFinance uses "2", InterbankFX uses "-1".
extern int    DST_GMT_Hours_Offset = -1;      // CUSTOMIZE for DST and/or for GMT offset in your MT4 platform!!!
//extern int    DST_GMT_Hours_Offset = 2;     // CUSTOMIZE for DST and/or for GMT offset in your MT4 platform!!!
extern bool   TokyoIncluded  = true ;         // Use true for JPY pairs
extern bool   EurIncluded    = false;         // Use true for EUR pairs
extern bool   LondonIncluded = true ;         // Use true for GBP pairs
extern bool   NYIncluded     = false;         // Use true for USD pairs
extern string TokyoBeginGMT    = "00:00";     // 00:00 = 9AM Tokyo. Some use 01:00 10AM Tokyo
extern string TokyoEndGMT      = "09:00";     // 09:00 = 6PM Tokyo. Some use 08:00  5PM Tokyo
extern color  TokyoColor       = Maroon;      // Use NULL to turn this off, esp. if using the Cyclic
extern string EurBeginGMT     = "07:00";      // 07:00 = 8AM Paris
extern string EurEndGMT       = "15:00";      // 15:00 = 4PM Paris. Some use 16:00  5PM Paris
extern color  EurColor       = DarkSlateGray; // Use NULL to turn this off, esp. if using the Cyclic
extern string LondonBeginGMT     = "08:00";   // 08:00 = 8AM London.
extern string LondonEndGMT       = "16:00";   // 16:00 = 4PM London. Some use 17:00 = 5PM London
extern color  LondonColor     = Navy;         // Use NULL to turn this off, esp. if using the Cyclic
extern string NYBeginGMT     = "13:00";       // 13:00 = 8AM ET.
extern string NYEndGMT       = "22:00";       // 22:00 = 5PM ET. Some use 20:00 = 3PM ET
extern color  NYColor        = Olive;         // Use NULL to turn this off, esp. if using the Cyclic
extern color  CycleColor     = Purple;        // Cycle is a single hilo box around 2-3 sessions.
extern bool   DrawCycleRectangle = false;     // Use true for to draw rectangle around all selected sessions
//                                            // FYI, turn session colors to NULL to ONLY see the full Cycle box.
extern bool   DrawSundayLines = true;         // Use true for weekly Sunday verticle line
extern bool   DrawHiLoLines   = true;         // These horizontal lines are Hi/Lo/SL/10/20 lines.

double SesHigh[];
double SesLow[];
double SesHighSL[];
double SesLowSL[];
double SesHigh10[];
double SesLow10[];
double SesHigh20[];
double SesLow20[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {

  DeleteObjects();

  for (int i=0; i<NumberOfDays; i++) {
    CreateRectangles("TY"+i, TokyoColor);
    CreateRectangles("LD"+i, LondonColor);
    CreateRectangles("EU"+i, EurColor);
    CreateRectangles("NY"+i, NYColor);
    CreateRectangles("CY"+i, CycleColor);
    CreateSundayLines("WK"+i, Salmon); // Ignoring the fact it reates daily object instead of weekly.
  }
  
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,SesHigh);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,SesLow);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,SesHighSL);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,SesLowSL);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,SesHigh10);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,SesLow10);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,SesHigh20);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,SesLow20);
   
   // To limit the start of the Hi/Lo lines, add this property for each of 0-7:
   //SetIndexDrawBegin(0, calculate_bars_within_NumberOfDays);
  
  Comment("");
  return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
  DeleteObjects();
  Comment("");
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CreateRectangles(string name, color cl) {
  ObjectCreate(name, OBJ_RECTANGLE, 0, 0,0, 0,0);
  ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet(name, OBJPROP_COLOR, cl);
  ObjectSet(name, OBJPROP_BACK, True);
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CreateSundayLines(string name, color cl) {
  ObjectCreate(name, OBJ_VLINE, 0, 0,0, 0,0);
  ObjectSet(name, OBJPROP_STYLE, STYLE_DASH);
  ObjectSet(name, OBJPROP_COLOR, cl);
  ObjectSet(name, OBJPROP_WIDTH, 3);
  ObjectSet(name, OBJPROP_BACK, True);
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int DeleteObjects() {
  for (int i=0; i<NumberOfDays; i++) {
    ObjectDelete("TY"+i);
    ObjectDelete("LD"+i);
    ObjectDelete("EU"+i);
    ObjectDelete("NY"+i);
    ObjectDelete("CY"+i);
    ObjectDelete("WK"+i);
  }
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  datetime date=StrToTime(TimeToStr(CurTime(),TIME_DATE));
  datetime dttoday=date;
  datetime TokyoBeginSec, TokyoEnd;
  datetime LondonBeginSec, LondonEnd;
  datetime EurBeginSec, EurEnd;
  datetime NYBeginSec, NYEnd;
  datetime CycleBeginSec, CycleEnd;

  // Illegal value "24:00" is replaced by "00:00". No other error checking of values is performed. Must be 00:00-24:00.
  if (TokyoBeginGMT=="24:00") TokyoBeginGMT="00:00";
  if (TokyoEndGMT=="24:00") TokyoEndGMT="00:00";
  if (EurBeginGMT=="24:00") EurBeginGMT="00:00";
  if (EurEndGMT=="24:00") EurEndGMT="00:00";
  if (LondonBeginGMT=="24:00") LondonBeginGMT="00:00";
  if (LondonEndGMT=="24:00") LondonEndGMT="00:00";
  if (NYBeginGMT=="24:00") NYBeginGMT="00:00";
  if (NYEndGMT=="24:00") NYEndGMT="00:00";
  
  // A negative offset like -1 (hour) works if you do this adjustment:
  while( DST_GMT_Hours_Offset < 0) DST_GMT_Hours_Offset=DST_GMT_Hours_Offset+24;
  
  // NOTICE: These SUBTRACT "date". The Begin and End times are more like
  //    the hour of the day (in seconds), and either negative seconds 
  //    or more than a day (86400 sec) are OK.  (Not completely sure though).
  TokyoBeginSec=StrToTime(TokyoBeginGMT)-date+DST_GMT_Hours_Offset*3600;
  TokyoEnd=StrToTime(TokyoEndGMT)-date+DST_GMT_Hours_Offset*3600;
  LondonBeginSec=StrToTime(LondonBeginGMT)-date+DST_GMT_Hours_Offset*3600;
  LondonEnd=StrToTime(LondonEndGMT)-date+DST_GMT_Hours_Offset*3600;
  EurBeginSec=StrToTime(EurBeginGMT)-date+DST_GMT_Hours_Offset*3600;
  EurEnd=StrToTime(EurEndGMT)-date+DST_GMT_Hours_Offset*3600;
  NYBeginSec=StrToTime(NYBeginGMT)-date+DST_GMT_Hours_Offset*3600;
  NYEnd=StrToTime(NYEndGMT)-date+DST_GMT_Hours_Offset*3600;
  
  
  // A start time for Tokyo of 23:00GMT (8AM local) is quite reasonable, but that would make it
  // AFTER the TokyoEnd time.  Similarly, NYEnd (USA) could be 24:00 or 01:00(5P PT).  Therefore,
  // the following adjusts the times by +/- one day so Begin is always before End.
  // FYI, 1 Day in seconds = 24*60*60=86400
  if (TokyoBeginSec>TokyoEnd) TokyoBeginSec=TokyoBeginSec-86400;
  if (EurBeginSec>EurEnd) EurBeginSec=EurBeginSec-86400;
  if (LondonBeginSec>LondonEnd) LondonEnd=LondonEnd+86400;
  if (NYBeginSec>NYEnd) NYEnd=NYEnd+86400;
  
  
  // The following section determines what is a "Cycle".  Depending on which
  // sessions are turned on, the CycleBeginSec and CycleEnd times are set here.      
  if (TokyoIncluded && LondonIncluded && NYIncluded) 
    {
     //Eur is ignored
     CycleBeginSec=TokyoBeginSec;
     CycleEnd=NYEnd;
     if (CycleEnd-CycleBeginSec>86400) CycleEnd=CycleBeginSec+86400;
    }
  else if (TokyoIncluded && LondonIncluded) 
    {
     //Eur is ignored, and NY assumed NOT to be used
     CycleBeginSec=TokyoBeginSec;
     CycleEnd=LondonEnd;
    }
  else if (TokyoIncluded && EurIncluded)
    {
     //NY assumed NOT to be used
     CycleBeginSec=TokyoBeginSec;
     CycleEnd=EurEnd;
    }
  else if (TokyoIncluded && NYIncluded)
    {
     //EUR+LON assumed NOT to be used. The time GAP is ignored.
     CycleBeginSec=NYBeginSec;
     CycleEnd=TokyoEnd;
    }
  else if (EurIncluded && NYIncluded)
    {
     //London is ignored
     CycleBeginSec=EurBeginSec;
     CycleEnd=NYEnd;
    }
  else if (LondonIncluded && NYIncluded)
    {
     //
     CycleBeginSec=LondonBeginSec;
     CycleEnd=NYEnd;
    }
  else if (TokyoIncluded)
    {
     //
     CycleBeginSec=TokyoBeginSec;
     CycleEnd=TokyoEnd;
    }  
  else if (EurIncluded)
    {
     //
     CycleBeginSec=EurBeginSec;
     CycleEnd=EurEnd;
    }  
  else if (LondonIncluded)
    {
     //
     CycleBeginSec=LondonBeginSec;
     CycleEnd=LondonEnd;
    }  
  else if (NYIncluded)
    {
     //
     CycleBeginSec=NYBeginSec;
     CycleEnd=NYEnd;
    }  
  else
    {
    // At least one cycle should be select, but if not, then Begin=End, 
    //   and then Cycle will be a null rectangle.
    CycleBeginSec=date;
    CycleEnd=date;
    }
    
  
  // Begin calculations for each day.  
  for (int i=0; i<NumberOfDays; i++) {
    //TokyoHigh=238.00;
    //TokyoLow=238.20;
    //LondonHigh=238.00;
    //LondonLow=238.20;
    //EurHigh=238.00;
    //EurLow=238.20;
    //NYHigh=238.00;
    //NYLow=238.20;
    
    if (TokyoIncluded) DrawRectangles(date, "TY"+i, TokyoBeginSec, TokyoEnd);
    if (LondonIncluded) DrawRectangles(date, "LD"+i, LondonBeginSec, LondonEnd);
    if (EurIncluded) DrawRectangles(date, "EU"+i, EurBeginSec, EurEnd);
    if (NYIncluded) DrawRectangles(date, "NY"+i, NYBeginSec, NYEnd);
    
    // Previously attempted to pass all p1/p2 values up through DrawRectangles 
    //   and then to find the min/max but it didn't work. P.S. I didn't understand C pointers then...
    //MaxHigh=MathMax(TokyoHigh, MathMax(LondonHigh, MathMax(EurHigh, NYHigh)));
    //MinLow=MathMin(TokyoLow, MathMin(LondonLow, MathMin(EurLow, NYLow)));
    //Print("MaxHigh", MaxHigh);
    
    if (DrawCycleRectangle) DrawRectangles(date, "CY"+i, CycleBeginSec, CycleEnd);
    
    if (DrawSundayLines && TimeDayOfWeek(date)==0) DrawSundayLine(date, "WK"+i);
    
    //BUG???  The following while loop may skip some trading days, depending on GMT offsets for your platform.
    //  I'm just going to skip it and do calculations for the weekend because it doesn't seem to matter.
    //while (TimeDayOfWeek(date)<=1) date=date-86400; // Sun=0, Fri=5, Sat=6. On Mon/Sun, decrement a day, each.
    //if (DrawSundayLines && TimeDayOfWeek(date)==6) DrawSundayLine(date, "WK"+i);  // Note "6" since we skipped "0"
    
    date=date-86400;
  }
  
  // Add High/Low/SL/10/20 lines here.
  // I guess this should be here, outside of above "for" loop:
  if (DrawHiLoLines) DrawLines(dttoday, CycleBeginSec, CycleEnd);
  
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

// DrawRectangles (below) creates rectangles around each session and calculates
//   min/max prices for those session rectangles.
//
// In the function definition below, I attempted to pass p1/p2 UPWARDS but it didn't work:
//    int DrawRectangles(datetime date, string name, string tb, string te, double p1, double p2) {...}
// I wanted to draw/calc the Tokyo/Eur/London/NY sessions, pass the p1/p2 upwards, 
// and then do a min/max calculation.  I would then just draw a Cycle rectangle.
//
// I'm told by a C-programmer that if pointers work, use them.  A simple example is like:
// int x; int n=3;
// add(&x, n, 2);
// int add(int *c, int a, int b) {
//   *c = a + b ;
// }
// I did not test the above at all, since I had another alternative.
// Instead of doing the above, I just use DrawRectangles again, which
// has to recalculate the cycle p1/p2 min/max prices all over.  Seems inefficient,
// as compared to calculating the 4 p1/p2 prices then doing MathMin/MathMax
// functions to find the range, and then just drawing a simple rectangle.


int DrawRectangles(datetime date, string name, datetime tb, datetime te) {
  datetime t1, t2;
  double p1, p2;
  int      b1, b2;

  t1=date+tb;
  t2=date+te;
  b1=iBarShift(NULL, 0, t1)+1; // The +1 shifts the min/max calculation 1 bar back in time
  b2=iBarShift(NULL, 0, t2)+1;
  //b1=iBarShift(NULL, 0, t1);
  //b2=iBarShift(NULL, 0, t2);
  p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
  p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
  ObjectSet(name, OBJPROP_TIME1 , t1);
  ObjectSet(name, OBJPROP_PRICE1, p1);
  ObjectSet(name, OBJPROP_TIME2 , t2);
  ObjectSet(name, OBJPROP_PRICE2, p2);
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int DrawSundayLine(datetime date, string name) {
  ObjectSet(name, OBJPROP_TIME1 , date);
  ObjectSet(name, OBJPROP_PRICE1, 0.0);
  return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int DrawLines(datetime dttoday, datetime CycleBeginSec, datetime CycleEnd) {

   datetime dtCycleBegin, dtCycleEnd;
   int i, limit;
   double h=0,  l=99999, r=0;
   
   if (CycleBeginSec == CycleEnd) return(-1); // Null cycle. Do nothing.
   int HourCycleBegin = TimeHour(CycleBeginSec);
   int MinuteCycleBegin = TimeMinute(CycleBeginSec);
   int CycleEndTH = TimeHour(CycleEnd);
   int CycleEndTM = TimeMinute(CycleEnd);
     
   dtCycleBegin = dttoday+CycleBeginSec;
   dtCycleEnd   = dttoday+CycleEnd;

   bool docompare=false;
   bool aftersession=false;
      
   int counted_bars=IndicatorCounted();
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit=Bars-1; // Why is this done??
   if(counted_bars>=1) limit=Bars-counted_bars-1;
   if (limit<0) limit=0;
   
   // This was another way to count them from another program:
   //limit = Bars-counted_bars;
   //if(counted_bars>0) limit++;
   //for(i=0; i<limit; i++) {     \\ Is there a difference??
   for(i=limit; i>0; i--) {

        if ( TimeHour(Time[i])*60 + TimeMinute(Time[i]) == HourCycleBegin*60 + MinuteCycleBegin ) {
            docompare = true;
            aftersession = false;
            h=0; l=99999;
            //Print("docompare=True ",TimeHour(Time[i-1]));
        }
        
        if (aftersession){
            DrawLinesSub1(i,h,l);
        }
        
        if (docompare){
            if (High[i]>h) h = High[i];
            if (Low[i]<l)  l = Low[i];
            //j++;                        
        }
        
        if ( TimeHour(Time[i-1])*60 + TimeMinute(Time[i-1]) == HourCycleBegin*60 + MinuteCycleBegin ) {
            docompare = true;
            aftersession = false;
            h=0; l=99999;
            //Print("docompare=True ",TimeHour(Time[i-1]));
        }
        
        if ( ( TimeHour(Time[i-2])*60 + TimeMinute(Time[i-2]) == CycleEndTH*60 + CycleEndTM )  
        || (CycleEndTH*60 + CycleEndTM > HourCycleBegin*60 + MinuteCycleBegin &&
        TimeHour(Time[i-2])*60 + TimeMinute(Time[i-2])  < HourCycleBegin*60 + MinuteCycleBegin) ) {
            // This loop is just an attempt to draw the maximum just BEFORE the cycle ends, to see it.
            // However, until real time updates of lines are working, this is almost useless, and
            // if the last candle sets the session max or min, then you'll see a sharp angle.
            DrawLinesSub1(i-1,h,l);
        } 
        
        if ( ( TimeHour(Time[i-1])*60 + TimeMinute(Time[i-1]) == CycleEndTH*60 + CycleEndTM )  
        || (CycleEndTH*60 + CycleEndTM > HourCycleBegin*60 + MinuteCycleBegin &&
        TimeHour(Time[i-1])*60 + TimeMinute(Time[i-1])  < HourCycleBegin*60 + MinuteCycleBegin) ) {
            docompare = false;
            aftersession = true;
        }
   } 
   return(0);                                      
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int DrawLinesSub1 (int i, double h, double l ) {
            double r = h-l;
            
            //SesHigh[i-1] = h; // FYI, "i-1" is more recent in time
            //SesHigh[i+1] = h; // FYI, "i+1" is older in time
            
            SesHigh[i] = h;
            SesLow[i] = l;
            
            SesHighSL[i] = h+0.20*r;
            SesLowSL[i] = l-0.20*r;
            
            SesHigh10[i] = h-0.10*r;
            SesLow10[i] = l+0.10*r;
            
            SesHigh20[i] = h-0.20*r;
            SesLow20[i] = l+0.20*r;
            
            return(0);
}


//+------------------------------------------------------------------+
//+------------------------------------------------------------------+