/*

*/
#property copyright "Copyright 2017, "
#property link      "My first indicator"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_width1 2
#property indicator_width2 2

// colors of indicators 

#property indicator_color1 LightSkyBlue
#property indicator_color2 Red

//---- input parameters
//
extern string    PriceData  = "---";
extern int       MAPer      =  20; // Periods of MA 
extern int       ApPrice    =  0; // Price mode : 0-Close,1-Open,2-High,3-Low,4-Median,5-Typical,6-Weighted

extern string    StochasticData="---";
extern int       KPeriods   =  5; // K periods
extern int       DPeriods   =  3; // D periods
extern int       Slowing    =  3; // Period of smoothing
extern int       StModeMA   =  0; // Mode of Moving Average
extern int       StPrice    =  0; // Stoch PriceField 0=HighLow  1=Close/Close

extern string    ArrowDistance="---";
extern double    AShift     =  0.00010; // Arrow Shift
/*
extern string    MACDData    ="---";
extern int       MPeriodsF   =  8; // K periods
extern int       MPeriodsS   =  25; // D periods
extern int       MPeriodsSi  =  2; // Signal periods

extern string    MomentumData="---";
extern int       MoPeriods   =  3; // K periods
extern int       Mom1        =  30; // D periods
extern int       Mom2        =  60; // Signal periods
*/


double AUp[];
double ADn[];


bool LAbove, HBelow;
double Sto[], MAC[], M90[];
double Mom[], Mom30[], Mom60[];
 double m90, sto;

int init()
 {

   IndicatorBuffers(2);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 71);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 72);
/*   SetIndexStyle(5, DRAW_ARROW);

*/   
   SetIndexBuffer(0, AUp);
   SetIndexBuffer(1, ADn);
   
   SetIndexLabel(0,"Buy");
   SetIndexLabel(1,"Sell");

   //---- name for DataWindow and indicator subwindow label
   string short_name="GP-AM-StavrouSystem";
   IndicatorShortName(short_name);
    
   return (0);
}

int start() 
  {
    int limit;
    int counted_bars = IndicatorCounted();

    if(counted_bars < 0) 
        return(-1);

    if(counted_bars > 0) 
        counted_bars--;
    limit = Bars - counted_bars;

    for(int i = 0; i < limit; i++)
      {

      AUp[i+1]=EMPTY_VALUE;  ADn[i+1]=EMPTY_VALUE;

    m90 =  iMA(NULL,0,MAPer, 0, 1,PRICE_CLOSE,i+1);
    Sto[i+1]=iStochastic(NULL,0,KPeriods,DPeriods,Slowing,StModeMA,StPrice,0,i+1);

//    M90[i+1]=iMA(NULL,0,MAPer, 0, 1,PRICE_CLOSE,i+1);

  if (Low[i+1]>m90   &&  Sto[i+1]>50 ) AUp[i+1]=Low[i+1]-2*AShift ;
  if (High[i+1]<m90] &&  Sto[i+1]<50)  ADn[i+1]=High[i+1]+2*AShift;

 /*
    MAC[i+1]=iMACD(NULL,0,MPeriodsF,MPeriodsS,MPeriodsSi,PRICE_CLOSE,1,i+1);
    Mom[i+1]=iMomentum(NULL,0,MoPeriods,PRICE_CLOSE,i+1);
    Mom30[i+1]=iMAOnArray(Mom, 0, Mom1, 0, 0,i+1);
    Mom60[i+1]=iMAOnArray(Mom30, 0, Mom2, 0, 0,i+1);
    sto =  Sto[i+1];
   if (High[i+1]<M90[i+1] ) ADn[i+1]=High[i+1]+2*AShift;
   
Comment("s3 i= " ,i," m90 1= ",M90[i+1], "   m90=", m90,"   " , AUp[i+1],"  Low1 = ", Low[1]," sto= " ,sto," m90= ", m90); 
// ," m2 := ",M2," m3 = ",M3," Stoch = ", K1);// Long," SSignals := ", Short," TotalSig : ",Long+Short); //," AUp i+1 = " , AUp[i+1] , " ThreeAdvSol = ",ThreeAdvSolR,"  FUp+1=",FUp[i+1])  ;     //        
//        Comment(InU1,"  ",InU2,"  ",InU3,"  ",InD1,"  ",InD2,"  ",InD3,"  ",PRU," ", MRD," ",PCU, "  ",MCD, "  ",PRD," ",MRU);

// 
            
/*      
  if (Low[1]>M90[i+1] ) // && Sto>50) // && MAC>0 && Mom[i+1]>100 && Mom30[i+1]>Mom60[i+1]  && Mom30[i+2]<Mom60[i+2])
         {
         AUp[i+1]=Low[i+1]-2*AShift;

         }
  if (High[1]<M90[i+1] )// && Sto<50) // && MAC<0 && Mom[i+1]<100 && Mom30[i+1]<Mom60[i+1]  && Mom30[i+2]>Mom60[i+2] )
         {
         ADn[i+1]=High[i+1]+2*AShift; 
         }   
*/
      }

    return(0);
  }
