Navigation´╝ÜHome > Content >

LSMA_nrp.mq4

Time: 2011-07-12 | Download file:LSMA_nrp.mq4

//+------------------------------------------------------------------+
//|                                                     LSMA nrp.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 5

//
//
//
//
//

extern string Readme1   = "#--- Periode Input",
				  Readme2   = "5M 15M 30M 1H 2H 4H 6H 8H 12H 16H",
				  Readme3   = "1D 3D 1W 2W 3W 1MH 4MH 6MH 1Y",
				  Readme4   = "R4H R8H RD RW RM R4M", 						 
				  Periode   = "1D";
												
extern int   LSMAPrice  = 0,
             Width      = 2;    
            
extern color Down_Color = Red; 
                     
//
//
//
//
//

int	 LSMAPeriod,CBar;

double lsma[],lsmaua[],lsmaub[],lsmada[],lsmadb[];

color	 Warna;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   if(GlobalVariableCheck("CBar"))
		CBar = GlobalVariableGet("CBar");
	else	
		GlobalVariableSet("CBar",0);
		
   if(Periode == "1Y")        { Warna	= BlueViolet;  	LSMAPeriod = MathCeil(345600/Period()); }
	else if(Periode == "6MH")	{ Warna	= YellowGreen;		LSMAPeriod = MathCeil(172800/Period()); }
	else if(Periode == "4MH")	{ Warna	= SandyBrown;  	LSMAPeriod = MathCeil(115200/Period()); }
	else if(Periode == "1MH")	{ Warna	= Aqua;	         LSMAPeriod = MathCeil(28800/Period()); }
	else if(Periode == "3W")	{ Warna	= Teal;  	      LSMAPeriod = MathCeil(21600/Period()); }
	else if(Periode == "2W")	{ Warna	= OrangeRed;		LSMAPeriod = MathCeil(14400/Period()); }
	else if(Periode == "1W")	{ Warna	= Magenta;	      LSMAPeriod = MathCeil(7200/Period()); }
	else if(Periode == "3D")	{ Warna	= DarkKhaki;  		LSMAPeriod = MathCeil(4320/Period()); }
	else if(Periode == "1D")	{ Warna	= Lime;     		LSMAPeriod = MathCeil(1440/Period()); }	
	else if(Periode == "16H")	{ Warna	= Coral;				LSMAPeriod = MathCeil(960/Period()); }
	else if(Periode == "12H")	{ Warna	= Olive;				LSMAPeriod = MathCeil(720/Period()); }
	else if(Periode == "8H")	{ Warna	= Yellow;	      LSMAPeriod = MathCeil(480/Period()); }
	else if(Periode == "6H")	{ Warna	= Chocolate;		LSMAPeriod = MathCeil(360/Period()); }
	else if(Periode == "4H")	{ Warna	= RoyalBlue;	   LSMAPeriod = MathCeil(240/Period()); }
	else if(Periode == "2H")	{ Warna	= White;				LSMAPeriod = MathCeil(120/Period()); }
	else if(Periode == "1H")	{ Warna	= Purple;   		LSMAPeriod = MathCeil(60/Period()); }
	else if(Periode == "30M")	{ Warna	= DarkViolet;		LSMAPeriod = MathCeil(30/Period()); }
	else if(Periode == "15M")	{ Warna	= White;				LSMAPeriod = MathCeil(15/Period()); }
	else if(Periode == "5M")	{ Warna	= Peru;				LSMAPeriod = MathCeil(5/Period()); }
	else if(Periode == "1M")	{ Warna	= DarkSlateGray;	LSMAPeriod = MathCeil(1/Period()); }		
	else if(Periode == "R4H")  { Warna  = Blue;           LSMAPeriod = MathCeil(getrenkodailyavg()/6); }
	else if(Periode == "R8H")	{ Warna	= DarkGoldenrod;	LSMAPeriod = MathCeil(getrenkodailyavg()/3); }
   else if(Periode == "RD")	{ Warna	= C'0,60,0';	   LSMAPeriod = MathCeil(getrenkodailyavg()); }
   else if(Periode == "RW")	{ Warna	= C'150,0,150';	LSMAPeriod = MathCeil(getrenkoweeklyavg()); }
   else if(Periode == "RM")	{ Warna	= C'0,150,150';	LSMAPeriod = MathCeil(getrenkomonthlyavg()); }
   else if(Periode == "R4M")  { Warna  = Brown;          LSMAPeriod = MathCeil(getrenkomonthlyavg()*4); }		
   
   SetIndexBuffer(0,lsma);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, Width, Warna);
   SetIndexLabel(0, "LSMA "+Periode+" ");
   
   SetIndexBuffer(1,lsmaua);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, Width, Warna);
   SetIndexLabel(1, "LSMA "+Periode+" ");
      
   SetIndexBuffer(2,lsmaub);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, Width, Warna);
   SetIndexLabel(2, "LSMA "+Periode+" ");
      
   SetIndexBuffer(3,lsmada);
   SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, Width, Down_Color);
   SetIndexLabel(3, "LSMA "+Periode+" ");
      
   SetIndexBuffer(4,lsmadb);
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, Width, Down_Color);
   SetIndexLabel(4, "LSMA "+Periode+" ");
   
   return(0);
   
}

//
//
//
//
//

int start()
{ 
   int counted_bars = IndicatorCounted();
   int limit,i;

   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);
   
   if((CBar!=0) && (limit>=CBar))
		limit=CBar;
		
   //
   //
   //
   //
   //
   
   if (lsma[limit] > lsma[limit+1]) CleanPoint(limit,lsmaua,lsmaub);
   if (lsma[limit] < lsma[limit+1]) CleanPoint(limit,lsmada,lsmadb);
   for(i = limit; i >= 0; i--)
   {
      lsma[i]   = 3.0*iMA(NULL,0,LSMAPeriod,0,MODE_LWMA,LSMAPrice,i)-2.0*iMA(NULL,0,LSMAPeriod,0,MODE_SMA,LSMAPrice,i);
      lsmaua[i] = EMPTY_VALUE;
      lsmaub[i] = EMPTY_VALUE;
      lsmada[i] = EMPTY_VALUE;
      lsmadb[i] = EMPTY_VALUE;
      
      if (lsma[i] > lsma[i+1]) PlotPoint(i,lsmaua,lsmaub,lsma);
      if (lsma[i] < lsma[i+1]) PlotPoint(i,lsmada,lsmadb,lsma);
   }   
   
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else   
   if ((first[i]  != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
        first[i+1] = EMPTY_VALUE;
}

//
//
//
//
//

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (first[i+1] == EMPTY_VALUE)
      {
         if (first[i+2] == EMPTY_VALUE) {
                first[i]   = from[i];
                first[i+1] = from[i+1];
                second[i]  = EMPTY_VALUE;
            }
         else {
                second[i]   =  from[i];
                second[i+1] =  from[i+1];
                first[i]    =  EMPTY_VALUE;
            }
      }
   else
      {
         first[i]   = from[i];
         second[i]  = EMPTY_VALUE;
      }
}

int getrenkodailyavg()
{
   int temp;
   int hasil=0;
   int hari=20;
   for(int i=0;i        

Recommend