
// zie ook comment http://docs.mql4.com/common/comment (comment alert print)
// ALLE INFO RECHTS VAN SCHERM PLOTTEN VIA Shift-chart button
// ALTIJD MEAN VALUE LAATSTE 5 METINGEN

// RefreshRates();
// veroorzaakt refresh van varaibelen en arrays !!! zeker weten wanneer en hoe te gebruiken
// Refreshing of data in pre-defined variables and series arrays.
// http://docs.mql4.com/series/refreshrates

// iVol[i] berekeningen - MOET DOT VOOR OF NA PLOT ??? ZIE TICK DEEL
// positionering vanuit corner & +iCornerShift refs
// meerdere SL & TP waarden
// slope van trendlines | aantal crossings
// pips tussen crossings 1-2, 2-3, 3-4,...
// sterkte valuta's (uit ForexProfitSupreme) 
// values huidige bar(s), pivots, fib's etcetera
// aantal bars & HH HL & LH LL dezelfde kant op
// aantal bars vanaf MA-crossings op M1

//********************************************************************
//********************************************************************
//********************************************************************

//+------------------------------------------------------------------+
//|                                    #-Spread-Ticks-more.mq4 V0.1  |
//|                            Copyright © 2015 davinci-ict cdeleeuw |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2015 davinci-ict cdeleeuw"
#property link      "http://www.davinci-ict.com"
#property indicator_chart_window

extern color  font_color            = Black;
extern int    font_size             = 9;
extern string font_face             = "Arial";
extern bool   normalize             = false; // If true then the spread is normalized to traditional pips ???????????????????????????
extern double AlertIfSpreadAbove    = 0;     // If > 0 alert will sound when spread above the value
extern int    corner                = 0;     // 0 - top-left corner, 1 - top-right, 2 - bottom-left, 3 - bottom-right
extern int    iCornerShift_x        = 0;     // x distance from corner
extern int    iCornerShift_y        = 0;     // y distance from corner

int    SrvTime_distance_x;            // x/y position right of Udine ForexProfitSupremeMeter
int    SrvTime_distance_y;      
int    spread_distance_x;             // x/y position right of Udine ForexProfitSupremeMeter
int    spread_distance_y;       
int    MeanSpread_distance_x = 450;   // x/y position right of Udine ForexProfitSupremeMeter
int    MeanSpread_distance_y = 40;
int    Volume_distance_x     = 300;   // x/y position right of Udine ForexProfitSupremeMeter
int    Volume_distance_y     = 55;
int    SBscore_distance_x    = 300;   // x/y position right of Udine ForexProfitSupremeMeter
int    SBscore_distance_y    = 70;
int    HiLo_distance_x       = 300;   // x/y position right of Udine ForexProfitSupremeMeter
int    HiLo_distance_y       = 85;
//extern int  tick_distance_x       = 300;  // x/y position right of Udine ForexProfitSupremeMeter
//extern int  tick_distance_y       = ??;

double Poin;
int    i;
int    n_digits   = 0;
double divider    = 1;
bool   alert_done = false;
// onderstaande oorspronkelijk in Start functie, veroorzaakte dit foutieve waarden tgv Refreshrates ???
int    iTicksSum, iTicks[4];          // Ticks for current and previous bars
int    iVolSum, iVolAvg, iVol[5];     // Volume for current and previous bars (starts with [0]
double dHiLoSum,  dHiLoAvg, dHiLo[8];
double spread,    spreadsum;
int    spreadcount;
int    volume,    volumecount;
double dSBscore;                      // Shaun Overton SB-Score email 10-11-2015

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   //Checking for unconvetional Point digits number
   if (Point == 0.00001) Poin = 0.0001;               //5 digits
   else if (Point == 0.001) Poin = 0.01;              //3 digits
   else Poin = Point; //Normal

    SrvTime_distance_x    = 300+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    SrvTime_distance_y    = 25 +iCornerShift_y;
    spread_distance_x     = 300+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    spread_distance_y     = 40 +iCornerShift_y;
    MeanSpread_distance_x = 450+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    MeanSpread_distance_y = 40 +iCornerShift_y;
    Volume_distance_x     = 300+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    Volume_distance_y     = 55 +iCornerShift_y;
    SBscore_distance_x    = 300+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    SBscore_distance_y    = 70 +iCornerShift_y;
    HiLo_distance_x       = 300+iCornerShift_x;   // x/y position right of Udine ForexProfitSupremeMeter
    HiLo_distance_y       = 85 +iCornerShift_y;
//   tick_distance_x       = 300+iCornerShift_x;  // x/y position right of Udine ForexProfitSupremeMeter
//   tick_distance_y       = ?? +iCornerShift_y;

   ObjectCreate ("SrvTime", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("SrvTime", OBJPROP_CORNER, corner);
   ObjectSet    ("SrvTime", OBJPROP_XDISTANCE, SrvTime_distance_x);
   ObjectSet    ("SrvTime", OBJPROP_YDISTANCE, SrvTime_distance_y);

   ObjectCreate ("Spread", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("Spread", OBJPROP_CORNER, corner);
   ObjectSet    ("Spread", OBJPROP_XDISTANCE, spread_distance_x);
   ObjectSet    ("Spread", OBJPROP_YDISTANCE, spread_distance_y);
// ????? or via double spread = MarketInfo(Symbol(), MODE_SPREAD);

   ObjectCreate ("MeanSpread", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("MeanSpread", OBJPROP_CORNER, corner);
   ObjectSet    ("MeanSpread", OBJPROP_XDISTANCE, MeanSpread_distance_x);
   ObjectSet    ("MeanSpread", OBJPROP_YDISTANCE, MeanSpread_distance_y);

   ObjectCreate ("Volume", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("Volume", OBJPROP_CORNER, corner);
   ObjectSet    ("Volume", OBJPROP_XDISTANCE, Volume_distance_x);
   ObjectSet    ("Volume", OBJPROP_YDISTANCE, Volume_distance_y);

   ObjectCreate ("SBscore", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("SBscore", OBJPROP_CORNER, corner);
   ObjectSet    ("SBscore", OBJPROP_XDISTANCE, SBscore_distance_x);
   ObjectSet    ("SBscore", OBJPROP_YDISTANCE, SBscore_distance_y);

   ObjectCreate ("HiLo", OBJ_LABEL, 0, 0, 0);
   ObjectSet    ("HiLo", OBJPROP_CORNER, corner);
   ObjectSet    ("HiLo", OBJPROP_XDISTANCE, HiLo_distance_x);
   ObjectSet    ("HiLo", OBJPROP_YDISTANCE, HiLo_distance_y);
/*
   ObjectCreate ("Ticks", OBJ_LABEL, 0, 0, 0);        // Ticks = Volume
   ObjectSet    ("Ticks", OBJPROP_CORNER, corner);
   ObjectSet    ("Ticks", OBJPROP_XDISTANCE, tick_distance_x);
   ObjectSet    ("Ticks", OBJPROP_YDISTANCE, tick_distance_y);
*/
   if ((Poin > Point) && (normalize))
   {
      divider = 10.0;
      n_digits = 1;
   }

   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete("SrvTime");
   ObjectDelete("Spread");
   ObjectDelete("MeanSpread");
   ObjectDelete("Volume");
   ObjectDelete("Ticks");
   ObjectDelete("SBscore");
   ObjectDelete("HiLo");

   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
///// Tick Part //////////////////////////////////////////////////////

///iTicks1++;                                         // Tick count for bar-1 after bIsNewBar
   spreadcount++;                                     // hetzelfde als iTicks1
   spread     = (Ask - Bid) / Point;
   spreadsum += spread;

   ObjectSetText("Spread", "Spread per tick: " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + 
                 " pipettes ", font_size, font_face, font_color);

/*********************************************************************
DECOMMENTED CODE PART

   if (AlertIfSpreadAbove > 0)
   {
      if (NormalizeDouble(spread / divider, 1) < AlertIfSpreadAbove) alert_done = false;
      else if (!alert_done)
      {
         PlaySound("alert.wav");
         alert_done = true;
      }
   }
*/ //*****************************************************************


   if (!bIsNewBar()) return(0);       // TICK NOT REACHED BAR-CLOSE YET


//// Bar Part ////////////////////////////////////////////////////////

   spreadsum   = spread;
   spreadcount = 1;                                   // is identiek aan iTicks1

//********************************************************************

   ObjectSetText("SrvTime", "SrvTime & O-C-V  " +
                 TimeToStr(TimeCurrent(),TIME_SECONDS) +
                 "   O=" + Open[1]+"   C="+Close[1]+"   V="+Volume[1],
                 font_size, font_face, font_color);

//********************************************************************

   ObjectSetText("MeanSpread", "MeanSpread last Bar: " + IntegerToString(spreadsum/spreadcount), 
                 font_size, font_face, font_color);

//********************************************************************

   for (i=4; i>1; i--)                                // shift last values
   {                                                  // MOET DOT VOOR OF NA PLOT ??? ZIE TICK DEEL
     iVol[i] = iVol[i-1];
   }
   iVol[1] = Volume[1];                               // new value for iVol[1]
   iVolSum = iVol[1] + iVol[2] + iVol[3] + iVol[4];
   iVolAvg = iVolSum / 4;
   ObjectSetText("Volume", "Volume=Ticks last 4 Bars: " + 
                 IntegerToString(iVol[4],5,' ')       +
                 IntegerToString(iVol[3],5,' ')       +
                 IntegerToString(iVol[2],5,' ')       +
                 IntegerToString(iVol[1],5,' ')       +
                 "   Sum: "                           +
                 IntegerToString(iVolSum,5,' ')       +
                 "   Avg: "                           +  // teveel argumenten ???
                 IntegerToString(iVolAvg,5,' '),
                 font_size, font_face, font_color);

//********************************************************************

/* // -- Ticks is same as Volume
   iTicksSum = iTicks[1]+ iTicks[2] + iTicks[3] + iTicks[4];
   ObjectSetText("Ticks", "Ticks=Volume per Bar[4...1]: "  + 
                 IntegerToString(iTicks[4],5,' ')     +
                 IntegerToString(iTicks[3],5,' ')     +
                 IntegerToString(iTicks[2],5,' ')     +
                 IntegerToString(iTicks[1],5,' ')     +  
                 "   Sum: "                           +
                 IntegerToString(iTicksSum,5,' ')     +
                 "   Avg: "                           +
                 IntegerToString(iTicksSum/4,5,' '),
                 font_size, font_face, font_color);
// -- save previous tick counts & resets
   iTicks[4]     = iTicks[3];                           // shift last values
   iTicks[3]     = iTicks[2];
   iTicks[2]     = iTicks[1];
   iTicks[1]     = 1;                                   // reset tick count for current bar
   iTicksSum   = 0;
*/
//********************************************************************

// --DBscore - strength of bar for next move, 0-25% - 25-50% - 50-75% - 75-100% :
   dSBscore = (Close[1]-Low[1]) / (High[1]-Low[1]);
   ObjectSetText("SBscore","Strength Last Bar ((C-L)/(H-L)): " + DoubleToString(dSBscore,5),
                 font_size, font_face, font_color);

//********************************************************************

// -- High-Low sizes:
   for (i=8; i>1; i--)                                  // shift last values
   {
     dHiLo[i] = dHiLo[i-1];
     dHiLoSum = dHiLoSum + dHiLo[i];
   }
   dHiLo[1] = MathAbs (High[1]-Low[1]);
   dHiLoSum = dHiLoSum + dHiLo[1];
   dHiLoAvg = dHiLoSum / 8;
   ObjectSetText("HiLo","8 Bars  HighLowSum : " + DoubleToString(dHiLoSum,5) +
                 "   HighLowAvg: " + DoubleToString(dHiLoAvg,5),
                 font_size, font_face, font_color);
   dHiLoSum = 0.0;

//********************************************************************

   return(0);
}

//********************************************************************
//********************************************************************
//********************************************************************

//-- New bar
bool bIsNewBar() 
{
   static int prevTime;
   bool newBar = false; 
   if(Time[0] != prevTime)
   {
      newBar   = true;
      prevTime = Time[0];
   }
   return(newBar);
}
//********************************************************************