//+------------------------------------------------------------------+
//|                                   Symphonie Set Candles V3.0.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
//+------------------------------------------------------------------+
#property indicator_buffers 8
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Yellow
#property indicator_color7 Yellow
#property indicator_color8 Yellow
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 3
#property indicator_width8 3
//+------------------------------------------------------------------+
double UpBody[];
double DownBody[];
double UpWick[];
double DownWick[];
double FlatOpen[];
double FlatClose[];
double FlatLow[];
double FlatHigh[];
//+------------------------------------------------------------------+
extern string    Cmt0 = "Sentiment Variables";
extern int       SentimentPeriod = 12;
extern string    Cmt1 = "Emotion Variables";
extern int       EmotionSSP = 7;
extern double    EmotionKmax = 50.6; //24 21.6 21.6 
extern int       EmotionCountBars = 500;
//+------------------------------------------------------------------+
int init()
   {
   IndicatorBuffers(8);
   //----
   SetIndexBuffer(0,UpWick);
   SetIndexBuffer(1,DownWick);
   SetIndexBuffer(2,UpBody);
   SetIndexBuffer(3,DownBody);
   SetIndexBuffer(4,FlatLow);
   SetIndexBuffer(5,FlatHigh);
   SetIndexBuffer(6,FlatOpen);
   SetIndexBuffer(7,FlatClose);
   //----
   for(int i = 7; i >= 0; i--) {SetIndexStyle(i, DRAW_HISTOGRAM); SetIndexDrawBegin(i, EmotionSSP);}
   //----
   IndicatorDigits(Digits);
   //----
   return(0);
   }
//+------------------------------------------------------------------+
int start()
   {
   if(Bars <= EmotionSSP) return(0);
   int CountedBars = IndicatorCounted();
   if (CountedBars < 0) return(-1);
   if (CountedBars > 0) CountedBars--;
   int i = MathMax(Bars - CountedBars - 1, EmotionSSP);
   //----
   while(i >= 0) 
      { 
      double SentimentValue0 = iCustom(NULL,0,"Symphonie_Sentiment_Indikator",SentimentPeriod,0,i);
      double EmotionValue0 = iCustom(NULL,0,"Symphonie_Emotion_Indikator_v3.0",EmotionSSP,EmotionKmax,EmotionCountBars,0,i);
      double EmotionValue1 = iCustom(NULL,0,"Symphonie_Emotion_Indikator_v3.0",EmotionSSP,EmotionKmax,EmotionCountBars,1,i);
      //----
      UpBody[i]      = EMPTY_VALUE;
      DownBody[i]    = EMPTY_VALUE;
      UpWick[i]      = EMPTY_VALUE;
      DownWick[i]    = EMPTY_VALUE;
      FlatOpen[i]    = EMPTY_VALUE;
      FlatClose[i]   = EMPTY_VALUE;
      FlatHigh[i]    = EMPTY_VALUE;
      FlatLow[i]     = EMPTY_VALUE;
      //----
      if ((SentimentValue0 > 0.0) && (EmotionValue0 == 1.0))
         {
         UpBody[i] = MathMax(Open[i], Close[i]);
         DownBody[i] = MathMin(Open[i], Close[i]);
         UpWick[i] = High[i];
         DownWick[i] = Low[i];
         if (UpBody[i] == DownBody[i]) UpBody[i] += Point;
         }
      else if ((SentimentValue0 < 0.0) && (EmotionValue1 == 1.0))
         {
         UpBody[i] = MathMin(Open[i], Close[i]);
         DownBody[i] = MathMax(Open[i], Close[i]);
         UpWick[i] = Low[i];
         DownWick[i] = High[i];
         if (UpBody[i] == DownBody[i]) DownBody[i] += Point;
         }
      else
         {
         FlatOpen[i] = Open[i];
         FlatClose[i] = Close[i];
         FlatLow[i] = Low[i];
         FlatHigh[i] = High[i];
         if (FlatOpen[i] == FlatClose[i]) FlatOpen[i] += Point;
         }
      //----
      i--;
      }      
      //----
      return(0);
   }
//+------------------------------------------------------------------+