Navigation´╝ÜHome > Content >

KG_Monthly_Range_level.mq4

Time: 2011-10-24 | Download file:KG_Monthly_Range_level.mq4

//MAAP OM KG INDINYA SAYA OPREK, CODINGNYA MASIH KELIATAN BANGET :(
// MOHON KEIKHLASANNYA :)
#property  copyright "KG"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Red
#property indicator_color5 Red
#property indicator_color6 Red
#property indicator_color7 Red
//-----------------------------------
int bars_back = 120;

int i = 0;

int sName = 1102;


//-----------------------
double fx[], sqh[], sql[], stdh[], stdl[], stdkgh[], stdkgl[];

int    ip, p, n, f;

//*******************************************
int init()
{
  
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, fx);
   SetIndexLabel(0," DAILY OPEN");
   SetIndexStyle(1, DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1, sqh);
   SetIndexLabel(1," SD 1");
   SetIndexStyle(2, DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(2, sql);
   SetIndexLabel(2," SD -1");
   SetIndexStyle(3, DRAW_LINE,STYLE_DASHDOTDOT);
   SetIndexBuffer(3, stdh);
   SetIndexLabel(3," SD 2");
   SetIndexStyle(4, DRAW_LINE,STYLE_DASHDOTDOT);
   SetIndexBuffer(4, stdl);
   SetIndexLabel(4," SD -2");
   SetIndexStyle(5, DRAW_LINE);
   SetIndexBuffer(5, stdkgh);
   SetIndexLabel(5," SD 3");
   SetIndexStyle(6, DRAW_LINE);
   SetIndexBuffer(6, stdkgl);
   SetIndexLabel(6," SD -3");
   p = MathRound(bars_back);
   
  
   return(0);
}
//----------------------------------------------------------
int deinit()
{
   ObjectDelete("pr" + sName);
}
//**********************************************************************************************
int start()
{
  
   datetime kjh=iTime(NULL,PERIOD_MN1,0);
   ip = iBarShift(Symbol(),Period(),kjh,false);
   
   
   SetIndexDrawBegin(0, Bars-ip-1);
   SetIndexDrawBegin(1, Bars-ip-1);
   SetIndexDrawBegin(2, Bars-ip-1);
   SetIndexDrawBegin(3, Bars-ip-1);
   SetIndexDrawBegin(4, Bars-ip-1); 
   SetIndexDrawBegin(5, Bars-ip-1);
   SetIndexDrawBegin(6, Bars-ip-1); 

     double mR1,mR2,mR3,mR4,mR5,mR6,mR7,mR8,mR9,mR10,mR11,mR12;

   //Monthly range data
   mR1  = (iHigh(NULL,PERIOD_MN1,1)-iLow(NULL,PERIOD_MN1,1))/Point;
   mR2  = (iHigh(NULL,PERIOD_MN1,2)-iLow(NULL,PERIOD_MN1,2))/Point;
   mR3  = (iHigh(NULL,PERIOD_MN1,3)-iLow(NULL,PERIOD_MN1,3))/Point;
   mR4  = (iHigh(NULL,PERIOD_MN1,4)-iLow(NULL,PERIOD_MN1,4))/Point;
   mR5  = (iHigh(NULL,PERIOD_MN1,5)-iLow(NULL,PERIOD_MN1,5))/Point;         
   mR6  = (iHigh(NULL,PERIOD_MN1,6)-iLow(NULL,PERIOD_MN1,6))/Point;
   mR7  = (iHigh(NULL,PERIOD_MN1,7)-iLow(NULL,PERIOD_MN1,7))/Point;
   mR8  = (iHigh(NULL,PERIOD_MN1,8)-iLow(NULL,PERIOD_MN1,8))/Point;
   mR9  = (iHigh(NULL,PERIOD_MN1,9)-iLow(NULL,PERIOD_MN1,9))/Point;
   mR10 = (iHigh(NULL,PERIOD_MN1,10)-iLow(NULL,PERIOD_MN1,10))/Point;         
   mR11 = (iHigh(NULL,PERIOD_MN1,11)-iLow(NULL,PERIOD_MN1,11))/Point;
   mR12 = (iHigh(NULL,PERIOD_MN1,12)-iLow(NULL,PERIOD_MN1,12))/Point;
   
   double RAvgm=(mR1+mR2+mR3+mR4+mR5+mR6+mR7+mR8+mR9+mR10+mR11+mR12)/12;
   
   double mrangesq=MathPow(mR1-RAvgm,2)+MathPow(mR2-RAvgm,2)+MathPow(mR3-RAvgm,2)+MathPow(mR4-RAvgm,2)+MathPow(mR5-RAvgm,2)+
                   MathPow(mR6-RAvgm,2)+MathPow(mR7-RAvgm,2)+MathPow(mR8-RAvgm,2)+MathPow(mR9-RAvgm,2)+MathPow(mR10-RAvgm,2)+
                   MathPow(mR11-RAvgm,2)+MathPow(mR12-RAvgm,2);
   double mSDRangemin=MathSqrt(mrangesq/12);
    if (mSDRangemin<0) mSDRangemin=0;
//===========================================================================================================================
  
//-----------------------------------Std-----------------------------------------------------------------------------------
   
   for(n = i; n <= i + p; n++)
   {
      fx[n] = iOpen(Symbol(),PERIOD_MN1,0);
      sqh[n] = fx[n] + 1*(mSDRangemin*Point);
      sql[n] = fx[n] - 1*(mSDRangemin*Point);
      stdh[n] = fx[n] + 2*(mSDRangemin*Point);
      stdl[n] = fx[n] - 2*(mSDRangemin*Point);
      stdkgh[n] = fx[n] + 3*(mSDRangemin*Point);
      stdkgl[n] = fx[n] - 3*(mSDRangemin*Point);
   } 
//-------------------------------------------------------------------------------
   ObjectMove("pr" + sName, 0, Time[p], fx[p]);
//----------------------------------------------------------------------------------------------------------------------------
   return(0);
}
//==========================================================================================================================   

Recommend