//+------------------------------------------------------------------+ 
//|   TRO_Multi_Meter_Pipology                                       | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFT AND DONATIONS ACCEPTED                                    | 
//|                                                                  |
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 
//|                                                                  |
//| go to www.kreslik.com for the latest indicator updates           |  
//+------------------------------------------------------------------+ 
//|                                                                  |
//| Use mbtrading as your forex broker...                            |  
//| http://therumpledone.mbtrading.com/fx/demo.asp                   |  
//+------------------------------------------------------------------+ 

#property indicator_chart_window

extern bool Show_Heading = true;

 
extern string IndName = "Pipology" ; // change

extern bool Corner_of_Chart_RIGHT_TOP = true;

extern int Shift_UP_DN = 300; 
extern int Adjust_Side_to_side  = 20; // 20

extern color BarLabel_color = LightBlue;
extern color CommentLabel_color = LightBlue;



 

extern double Level5 =  95 ;
extern double Level4 =  80 ;
extern double Level3 =  50 ;
extern double Level2 =  20 ;
extern double Level1 =  5 ;
extern double Level0 =  0 ;


extern color Buy1_color  = Lime;
extern color Buy2_color  = Green;
extern color Buy3_color  = SeaGreen;
extern color Wait_color  = Yellow;
extern color Sell1_color = Red;
extern color Sell2_color = Crimson;
extern color Sell3_color = OrangeRed;

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

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

string ObjHead01,ObjHead02,ObjHead03,ObjHead04,ObjHead05,ObjHead06,ObjHead07,ObjHead08,ObjHead09,ObjHead10,ObjHead11;  

string Obj0001,Obj0002,Obj0003,Obj0004,Obj0005,Obj0006,Obj0007,Obj0008,Obj0009,Obj0010,Obj0011;  

int    MAMode;
string strMAType;
 
double Stoch ;
double Open0, Open1, Open2, Close0, Close1, Close2, High0, High1, High2, Low0,  Low1, Low2, Range0, Range1, Range2, AvgRng3 ;
		
 
color MA_color;
double  LR.price.2, LR.price.1  ; 

double SMI_Buffer[];
double Signal_Buffer[];
double SM_Buffer[];
double EMA_SM[];
double EMA2_SM[];
double EMA_HQ[];
double EMA2_HQ[];
double HQ_Buffer[];
  
//+------------------------------------------------------------------+
int init()
  {
   

   return(0);
  }
 
//+------------------------------------------------------------------+
int start()
  {    

ArrayResize(SMI_Buffer , Bars ) ;
ArrayResize(Signal_Buffer , Bars ) ;
ArrayResize(SM_Buffer , Bars ) ;
ArrayResize(EMA_SM , Bars ) ;
ArrayResize(EMA2_SM , Bars ) ;
ArrayResize(EMA_HQ , Bars ) ;
ArrayResize(EMA2_HQ , Bars ) ;
ArrayResize(HQ_Buffer , Bars ) ;

string LabelTime="";

if (LabelTime=="") {LabelTime=TimeToStr(TimeLocal(),TIME_SECONDS); }

   int    counted_bars=IndicatorCounted();
   
   
   ObjHead01 = "PintoColHead01" + LabelTime  ;  
   ObjHead02 = "PintoColHead02" + LabelTime  ;  
   ObjHead03 = "PintoColHead03" + LabelTime  ; 
   ObjHead04 = "PintoColHead04" + LabelTime  ;  
   ObjHead05 = "PintoColHead05" + LabelTime  ;  
   ObjHead06 = "PintoColHead06" + LabelTime  ; 
   ObjHead07 = "PintoColHead07" + LabelTime  ;  
   ObjHead08 = "PintoColHead08" + LabelTime  ;  
   ObjHead09 = "PintoColHead09" + LabelTime  ; 
         
   string Pinto_ObjHead01 ="M1 " ;
   string Pinto_ObjHead02 ="M5  " ;     
   string Pinto_ObjHead03 ="M15 " ;
   
//   Comment("Stoch= ", DoubleToStr(Stoch,2), "\n","");
   
   string Pinto_ObjHead04 =" M30 " ;
   string Pinto_ObjHead05 ="H1  " ;     
   string Pinto_ObjHead06 ="H4  " ;
   string Pinto_ObjHead07 ="D1  " ;
   string Pinto_ObjHead08 ="W1  " ;
   string Pinto_ObjHead09 ="MN1" ;   
   
   
        
    if (Corner_of_Chart_RIGHT_TOP == true)
    { int Col01x = 170+Adjust_Side_to_side ;                 
      int Col01y = 28+Shift_UP_DN ;
    }
    if (Corner_of_Chart_RIGHT_TOP == false)
   { Col01x = 159+Adjust_Side_to_side ;       
     Col01y = 24+Shift_UP_DN ;
    } 
    
   int ColAdj = -20 ; 
   int Col02x = Col01x + ColAdj ;   
   int Col03x = Col01x + ColAdj*2 ; 
   int Col04x = Col01x + ColAdj*3 ; 
   int Col05x = Col01x + ColAdj*4 ; 
   int Col06x = Col01x + ColAdj*5 ; 
   int Col07x = Col01x + ColAdj*6 ;    
   int Col08x = Col01x + ColAdj*7 ; 
   int Col09x = Col01x + ColAdj*8 ;     
   
   if ( Show_Heading) {        
   ObjectCreate(ObjHead01, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead01,Pinto_ObjHead01 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead01, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead01, OBJPROP_XDISTANCE, Col01x);
   ObjectSet(ObjHead01, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead02, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead02,Pinto_ObjHead02 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead02, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead02, OBJPROP_XDISTANCE, Col02x);
   ObjectSet(ObjHead02, OBJPROP_YDISTANCE, Col01y);   
       
   ObjectCreate(ObjHead03, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead03,Pinto_ObjHead03 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead03, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead03, OBJPROP_XDISTANCE, Col03x);
   ObjectSet(ObjHead03, OBJPROP_YDISTANCE, Col01y); 
 
   ObjectCreate(ObjHead04, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead04,Pinto_ObjHead04 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead04, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead04, OBJPROP_XDISTANCE, Col04x);
   ObjectSet(ObjHead04, OBJPROP_YDISTANCE, Col01y); 
   
   ObjectCreate(ObjHead05, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead05,Pinto_ObjHead05 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead05, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead05, OBJPROP_XDISTANCE, Col05x);
   ObjectSet(ObjHead05, OBJPROP_YDISTANCE, Col01y); 
            
   ObjectCreate(ObjHead06, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead06,Pinto_ObjHead06 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead06, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead06, OBJPROP_XDISTANCE, Col06x);
   ObjectSet(ObjHead06, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead07, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead07,Pinto_ObjHead07 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead07, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead07, OBJPROP_XDISTANCE, Col07x);
   ObjectSet(ObjHead07, OBJPROP_YDISTANCE, Col01y); 
         
   ObjectCreate(ObjHead08, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead08,Pinto_ObjHead08 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead08, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead08, OBJPROP_XDISTANCE, Col08x);
   ObjectSet(ObjHead08, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead09, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead09,Pinto_ObjHead09 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead09, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead09, OBJPROP_XDISTANCE, Col09x);
   ObjectSet(ObjHead09, OBJPROP_YDISTANCE, Col01y); 
       
} // Show_Heading

 //*******************   change for  your indicator ********************
 
    
    string M1_Pinto= "-",M5_Pinto= "-", M15_Pinto= "-", M30_Pinto= "-", H1_Pinto= "-", H4_Pinto= "-", D1_Pinto= "-",PRC1, W1_Pinto= "-", MN1_Pinto= "-";

    color  color_Pintom1,color_Pintom5,color_Pintom15,color_Pintom30,color_PintoH1,color_PintoH4,color_PintoD1,color_PintoW1,color_PintoMN1;     
         

   //Pinto Signals

string symbol = Symbol() ;

 color_Pintom1  = ColorPinto( symbol, PERIOD_M1  ) ;
 color_Pintom5  = ColorPinto( symbol, PERIOD_M5  ) ;   
  
 color_Pintom15 = ColorPinto( symbol, PERIOD_M15  ) ;

 color_Pintom30 = ColorPinto( symbol, PERIOD_M30  ) ;
 color_PintoH1  = ColorPinto( symbol, PERIOD_H1  ) ;
 color_PintoH4  = ColorPinto( symbol, PERIOD_H4  ) ;
 color_PintoD1  = ColorPinto( symbol, PERIOD_D1  ) ;
 color_PintoW1  = ColorPinto( symbol, PERIOD_W1  ) ;
 color_PintoMN1 = ColorPinto( symbol, PERIOD_MN1  ) ;

               
    
 //*******************          
    
    int Col00x = Col01x + 20 ;
    int Col00y = 50+Shift_UP_DN ;
    
    Col01y = 20+Shift_UP_DN ;
    
   Obj0002 = IndName+"SignalM1t" + LabelTime ; 
           
           ObjectCreate(Obj0002, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0002,IndName, 7, "Tahoma Narrow",  BarLabel_color);  
   ObjectSet(Obj0002, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0002, OBJPROP_XDISTANCE, Col00x);
   ObjectSet(Obj0002, OBJPROP_YDISTANCE, Col00y);  // 50+Shift_UP_DN

   Obj0003 = IndName+"SignalM1" + LabelTime ;        
           ObjectCreate(Obj0003, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0003, M1_Pinto, 40, "Tahoma Narrow",  color_Pintom1);
   ObjectSet(Obj0003, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0003, OBJPROP_XDISTANCE, Col01x);
   ObjectSet(Obj0003, OBJPROP_YDISTANCE, Col01y); 

   Obj0004 = IndName+"SignalM5" + LabelTime ;         
           ObjectCreate(Obj0004, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0004, M5_Pinto, 40, "Tahoma Narrow",  color_Pintom5);
   ObjectSet(Obj0004, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0004, OBJPROP_XDISTANCE, Col02x);
   ObjectSet(Obj0004, OBJPROP_YDISTANCE, Col01y); 
      
   Obj0005 = IndName+"SignalM15" + LabelTime ; 
   ObjectCreate(Obj0005, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0005, M15_Pinto, 40, "Tahoma Narrow",  color_Pintom15);
   ObjectSet(Obj0005, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0005, OBJPROP_XDISTANCE, Col03x);
   ObjectSet(Obj0005, OBJPROP_YDISTANCE, Col01y); 
      
   Obj0006 = IndName+"SignalM30" + LabelTime ;
   ObjectCreate(Obj0006, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0006, M30_Pinto, 40, "Tahoma Narrow",  color_Pintom30);
   ObjectSet(Obj0006, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0006, OBJPROP_XDISTANCE, Col04x);
   ObjectSet(Obj0006, OBJPROP_YDISTANCE, Col01y); 

   Obj0007 = IndName+"SignalM60" + LabelTime ;      
           ObjectCreate(Obj0007, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0007, H1_Pinto, 40, "Tahoma Narrow",  color_PintoH1);
   ObjectSet(Obj0007, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0007, OBJPROP_XDISTANCE, Col05x);
   ObjectSet(Obj0007, OBJPROP_YDISTANCE, Col01y); 

   Obj0008 = IndName+"SignalM240" + LabelTime ;          
           ObjectCreate(Obj0008, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0008, H4_Pinto, 40, "Tahoma Narrow",  color_PintoH4);
   ObjectSet(Obj0008, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0008, OBJPROP_XDISTANCE, Col06x);
   ObjectSet(Obj0008, OBJPROP_YDISTANCE, Col01y);

   Obj0009 = IndName+"SignalM1440" + LabelTime ;    
           ObjectCreate(Obj0009, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0009, D1_Pinto, 40, "Tahoma Narrow",  color_PintoD1);
   ObjectSet(Obj0009, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0009, OBJPROP_XDISTANCE, Col07x);
   ObjectSet(Obj0009, OBJPROP_YDISTANCE, Col01y);
   
   Obj0010 = IndName+"SignalW1" + LabelTime ;    
           ObjectCreate(Obj0010, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0010, W1_Pinto, 40, "Tahoma Narrow",  color_PintoW1);
   ObjectSet(Obj0010, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0010, OBJPROP_XDISTANCE, Col08x);
   ObjectSet(Obj0010, OBJPROP_YDISTANCE, Col01y);   
   
   Obj0011 = IndName+"SignalMN1" + LabelTime ;    
           ObjectCreate(Obj0011, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0011, MN1_Pinto, 40, "Tahoma Narrow",  color_PintoMN1);
   ObjectSet(Obj0011, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0011, OBJPROP_XDISTANCE, Col09x);
   ObjectSet(Obj0011, OBJPROP_YDISTANCE, Col01y); 
     
 //----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
deleteObject(); 
ObjectsDeleteAll(0,OBJ_HLINE);
ObjectsDeleteAll(0,OBJ_TEXT);
ObjectsDeleteAll(0,OBJ_LABEL);


//----
   return(0);
  }
  
void deleteObject()
  { 
//ObjectDelete(Obj0001);  
ObjectDelete(Obj0002); 
ObjectDelete(Obj0003); 
ObjectDelete(Obj0004); 
ObjectDelete(Obj0005); 
ObjectDelete(Obj0006); 
ObjectDelete(Obj0007); 
ObjectDelete(Obj0008); 
ObjectDelete(Obj0009); 
ObjectDelete(Obj0010); 
ObjectDelete(Obj0011); 

ObjectDelete(ObjHead01);  
ObjectDelete(ObjHead02); 
ObjectDelete(ObjHead03); 
ObjectDelete(ObjHead04); 
ObjectDelete(ObjHead05); 
ObjectDelete(ObjHead06); 
ObjectDelete(ObjHead07); 
ObjectDelete(ObjHead08); 
ObjectDelete(ObjHead09); 
 
  }
//+------------------------------------------------------------------+

color ColorPinto( string symbol, int period )  
{
bool      short1, long1, short2, long2, short3, long3, maxup = false , maxdn = false, macdup = false , macddn = false ;

int macdupcnt, macddncnt ;

double cEMA8    = iMA(symbol,period, 8, 0, 1, PRICE_CLOSE,0); 
double pEMA8    = iMA(symbol,period, 8, 0, 1, PRICE_CLOSE,1); 
    
double cEMA13    = iMA(symbol,period, 13, 0, 1, PRICE_OPEN,0);     
double pEMA13    = iMA(symbol,period, 13, 0, 1, PRICE_OPEN,1); 
 


double cMacd      = iMACD(NULL,0,13, 21, 8,PRICE_CLOSE,MODE_MAIN,0) ; 
double cMacdSig   = iMACD(NULL,0,13, 21, 8,PRICE_CLOSE,MODE_SIGNAL,0) ; 

double cMacdDiff  = cMacd - cMacdSig ;

double pMacd      = iMACD(NULL,0,13, 21, 8,PRICE_CLOSE,MODE_MAIN,1) ;
double pMacdSig   = iMACD(NULL,0,13, 21, 8,PRICE_CLOSE,MODE_SIGNAL,1) ; 

double pMacdDiff  = pMacd - pMacdSig ;


double    RSI13  = iRSI(NULL,0,13,PRICE_OPEN,0) ;
double    WPR8    = iWPR(NULL,0,8,0) ;
 

   Close0 = iClose(symbol,period,0) ; 
   Close1 = iClose(symbol,period,1) ;    
   Close2 = iClose(symbol,period,2) ;  
     
   Open0 = iOpen(symbol,period,0) ; 
   Open1 = iOpen(symbol,period,1) ;    
   Open2 = iOpen(symbol,period,2) ;  

   High0 = iHigh(symbol,period,0) ; 
   High1 = iHigh(symbol,period,1) ;    
   High2 = iHigh(symbol,period,2) ; 

   Low0 = iLow(symbol,period,0) ; 
   Low1 = iLow(symbol,period,1) ;    
   Low2 = iLow(symbol,period,2) ; 
     
if( cEMA8 > pEMA13 && cEMA8 < pEMA13 ) { maxup = true  ; maxdn = false ;} 
if( cEMA8 < pEMA13 && cEMA8 > pEMA13 ) { maxup = false ; maxdn = true ;}  
 
if( cMacd > pMacd && cMacd < pMacd ) { macdupcnt = 0 ; macdup = true  ; macddn = false ;} 
if( cMacd < pMacd && cMacd > pMacd ) { macddncnt = 0 ; macdup = false ; macddn = true ;}


if( macdup ) { macdupcnt = macdupcnt + 1 ; }
if( macddn ) { macddncnt = macddncnt + 1 ; }
    
long1  = ( maxup &&  
           Low0      > cEMA8 &&    
           WPR8      < -20 &&               
           macdupcnt <= 4  &&
           cMacdDiff >  0  &&
           pMacdDiff <  0             
) ;

short1 = ( maxdn &&  
           High0     < cEMA8 &&    
           WPR8      > -80 &&               
           macddncnt <= 4  && 
           cMacdDiff <  0  &&
           pMacdDiff >  0               
) ;  
   
while(true)
{

if( short1 ) { MA_color = Sell1_color  ; break ; }
if( short2 ) { MA_color = Sell2_color  ; break ; }
if( short3 ) { MA_color = Sell3_color  ; break ; }  
if( long1 )  { MA_color = Buy1_color  ; break ; }
if( long2 )  { MA_color = Buy2_color  ; break ; } 
if( long3 )  { MA_color = Buy3_color  ; break ; } 
               MA_color = Wait_color ;   
  

break;

} // while
   
    
return( MA_color ) ;   
                                    
} //  

//+------------------------------------------------------------------+
/*

Comment(

"LR.price.1= ", DoubleToStr(LR.price.1 , Digits), "\n", 
"LR.price.2= ", DoubleToStr(LR.price.2 , Digits), "\n", 

"") ;

System is very simple, filtered by other indicators, as follows:

- Timeframe: 30M
- 8 EMA (applied to Close) & 13 EMA (applied to Open)
- Trend lines & Regression channels to help spotting intraday breakouts
Filters:
- 8 %R (levels -80 and -20 visible) over 13 RSI (applied to Open)
- MACD (13, 21, 8)

Signal:
1. EMAs cross
2. MACD goes above or bellow 0 level
3. Spot a break of a trendline or regression chan

Rules of entry:
- Always at the close of the candle.
- For long: candles must be above the 2 EMAs (for short: bellow)
- Entry candle must break or be above/bellow the trendline or regression channel.
- %R must be bellow -20 for long and above -80 for short
- Entry must be placed at maximum 4 MACD bars since MACD turned up or down.

*/