Navigation:Home > Content >

pTradingRange.mq4

Time: 2012-04-04 | Download file:pTradingRange.mq4

//+------------------------------------------------------------------+
//|   pTradingRange.mq4
//|   Displays trading range for 1) previous day, 
//+------------------------------------------------------------------+
#property indicator_chart_window

extern bool    Show.All =        true;
extern string  Comment.0 =       "-------------------------------------";
extern string  Comment.1 =       "Time.Frame in minutes:";
extern string  Comment.2 =       "1, 5, 15, 30, 60(1H), 240(4H),";
extern string  Comment.3 =       "1440(Daily),10080(Weekly),";
extern string  Comment.4 =       "43200(Monthly), 0(Chart timeframe)";
extern string  Comment.5 =       "-------------------------------------";
extern int     Time.Frame =      0;

extern string  Comment.6 =       "-------------------------------------";
extern string  Comment.7 =       "0=Top Left, 1=Top Right";
extern string  Comment.8 =       "2=Bottom Left, 3=Bottom Right";
extern string  Comment.9 =       "-------------------------------------";
extern int     Corner.Of.Chart = 2;
extern color   Color.Bar.Label =    LightSteelBlue;

int   Adjust_Side_to_side=0,Shift_UP_DN=0,Multiplier=10000;
bool  Legal.Time=false;
//+------------------------------------------------------------------+
int init()
   {
   if(Time.Frame==0||Time.Frame==1||Time.Frame==5||Time.Frame==15||Time.Frame==30||Time.Frame==60||Time.Frame==240||Time.Frame==1440||Time.Frame==10080||Time.Frame==43200) Legal.Time=true;
   return(0);
   }
//+------------------------------------------------------------------+
int GetMultiplier(string tSymbol)
   {
   if(StringFind(tSymbol,"JP",0)>0) return(100);
      else return(10000);
   }
//+------------------------------------------------------------------+   
int deinit()
   {
   ObjectsDeleteAll(0,OBJ_LABEL);
   return(0);
   }
//+------------------------------------------------------------------+
int start()
   {
   string   tLine;
   if(!Legal.Time) tLine="Illegal Time.Frame.  No further processing.  Time.Frame="+Time.Frame;
   else
      {
      Multiplier=GetMultiplier(Symbol());
      int i;
      int Range.Current=0,Range.1=0,Range.5=0,Range.10=0,Range.20=0,Range.Avg=0;
      int Range.Day = (iHigh(NULL,PERIOD_D1,0)-iLow(NULL,PERIOD_D1,0))*Multiplier;
      int Range.Yesterday = (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))*Multiplier;
      Range.Current = (iHigh(NULL,Time.Frame,0)-iLow(NULL,Time.Frame,0))*Multiplier;
      Range.1 = (iHigh(NULL,Time.Frame,1)-iLow(NULL,Time.Frame,1))*Multiplier;
      for(i=1;i<=5;i++) Range.5 = Range.5 + (iHigh(NULL,Time.Frame,i)-iLow(NULL,Time.Frame,i))*Multiplier;
      for(i=1;i<=10;i++) Range.10 = Range.10 + (iHigh(NULL,Time.Frame,i)-iLow(NULL,Time.Frame,i))*Multiplier;
      for(i=1;i<=20;i++) Range.20 = Range.20 + (iHigh(NULL,Time.Frame,i)-iLow(NULL,Time.Frame,i))*Multiplier;
      //Comment("Range.Current="+Range.Current+" Range.1="+Range.1+" Range.5="+Range.5+" Range.10="+Range.10+" Range.20="+Range.20);
      Range.5 = Range.5/5;
      Range.10 = Range.10/10;
      Range.20 = Range.20/20;
      Range.Avg = (Range.1+Range.5+Range.10+Range.20)/4;    //Since Current bar is still ranging, just average previous ranges
      tLine="Range Today="+Range.Day+", Yesterday="+Range.Yesterday;
      string tLine2="Current="+Range.Current+", Prev="+Range.1+ ", Averages: 5-bar="+Range.5+", 10-bar="+Range.10+", 20-bar="+Range.20;
      //string tLine3="10-bar="+Range.10+     ", 20-bar="+Range.20+", Average="+Range.Avg;
      }
   ObjectCreate("TradingRange1",OBJ_LABEL,0,0,0);
   ObjectSetText("TradingRange1",tLine,8,"Courier",Color.Bar.Label);
   ObjectSet("TradingRange1",OBJPROP_CORNER,Corner.Of.Chart);
   ObjectSet("TradingRange1",OBJPROP_XDISTANCE,5);
   ObjectSet("TradingRange1",OBJPROP_YDISTANCE,75);
   if(Legal.Time)
      {
      ObjectCreate("TradingRange2",OBJ_LABEL,0,0,0);
      ObjectSetText("TradingRange2",tLine2,8,"Courier",Color.Bar.Label);
      ObjectSet("TradingRange2",OBJPROP_CORNER,Corner.Of.Chart);
      ObjectSet("TradingRange2",OBJPROP_XDISTANCE,5);
      ObjectSet("TradingRange2",OBJPROP_YDISTANCE,60);
      }
   if(Show.All)      //UC,GU,UJ,AU,UC,EG,EJ,GJ
      {
      string tLine3,tLine4;
      tLine3="EU "+DoubleToStr(((iHigh("EURUSD",PERIOD_D1,0)-iLow("EURUSD",PERIOD_D1,0))*GetMultiplier("EURUSD")),0)+"/"+DoubleToStr(((iHigh("EURUSD",PERIOD_D1,1)-iLow("EURUSD",PERIOD_D1,1))*GetMultiplier("EURUSD")),0)+
         " GU "+ DoubleToStr(((iHigh("GBPUSD",PERIOD_D1,0)-iLow("GBPUSD",PERIOD_D1,0))*GetMultiplier("GBPUSD")),0) + "/" + DoubleToStr(((iHigh("GBPUSD",PERIOD_D1,1)-iLow("GBPUSD",PERIOD_D1,1))*GetMultiplier("GBPUSD")),0)+
         " UC "+ DoubleToStr(((iHigh("USDCHF",PERIOD_D1,0)-iLow("USDCHF",PERIOD_D1,0))*GetMultiplier("USDCHF")),0) + "/" + DoubleToStr(((iHigh("USDCHF",PERIOD_D1,1)-iLow("USDCHF",PERIOD_D1,1))*GetMultiplier("USDCHF")),0)+
         " UJ "+ DoubleToStr(((iHigh("USDJPY",PERIOD_D1,0)-iLow("USDJPY",PERIOD_D1,0))*GetMultiplier("USDJPY")),0) + "/" + DoubleToStr(((iHigh("USDJPY",PERIOD_D1,1)-iLow("USDJPY",PERIOD_D1,1))*GetMultiplier("USDJPY")),0)+
         " AU "+ DoubleToStr(((iHigh("AUDUSD",PERIOD_D1,0)-iLow("AUDUSD",PERIOD_D1,0))*GetMultiplier("AUDUSD")),0) + "/" + DoubleToStr(((iHigh("AUDUSD",PERIOD_D1,1)-iLow("AUDUSD",PERIOD_D1,1))*GetMultiplier("AUDUSD")),0)+
         " UCd "+ DoubleToStr(((iHigh("USDCAD",PERIOD_D1,0)-iLow("USDCAD",PERIOD_D1,0))*GetMultiplier("USDCAD")),0) + "/" + DoubleToStr(((iHigh("USDCAD",PERIOD_D1,1)-iLow("USDCAD",PERIOD_D1,1))*GetMultiplier("USDCAD")),0);
      tLine4="EG "+ DoubleToStr(((iHigh("EURGBP",PERIOD_D1,0)-iLow("EURGBP",PERIOD_D1,0))*GetMultiplier("EURGBP")),0) + "/" + DoubleToStr(((iHigh("EURGBP",PERIOD_D1,1)-iLow("EURGBP",PERIOD_D1,1))*GetMultiplier("EURGBP")),0)+
         " EJ "+ DoubleToStr(((iHigh("EURJPY",PERIOD_D1,0)-iLow("EURJPY",PERIOD_D1,0))*GetMultiplier("EURJPY")),0) + "/" + DoubleToStr(((iHigh("EURJPY",PERIOD_D1,1)-iLow("EURJPY",PERIOD_D1,1))*GetMultiplier("EURJPY")),0)+
         " GJ "+ DoubleToStr(((iHigh("GBPJPY",PERIOD_D1,0)-iLow("GBPJPY",PERIOD_D1,0))*GetMultiplier("GBPJPY")),0) + "/" + DoubleToStr(((iHigh("GBPJPY",PERIOD_D1,1)-iLow("GBPJPY",PERIOD_D1,1))*GetMultiplier("GBPJPY")),0);
      ObjectCreate("TradingRange3",OBJ_LABEL,0,0,0);
      ObjectSetText("TradingRange3",tLine3,8,"Courier",Color.Bar.Label);
      ObjectSet("TradingRange3",OBJPROP_CORNER,Corner.Of.Chart);
      ObjectSet("TradingRange3",OBJPROP_XDISTANCE,5);
      ObjectSet("TradingRange3",OBJPROP_YDISTANCE,45);
      ObjectCreate("TradingRange4",OBJ_LABEL,0,0,0);
      ObjectSetText("TradingRange4",tLine4,8,"Courier",Color.Bar.Label);
      ObjectSet("TradingRange4",OBJPROP_CORNER,Corner.Of.Chart);
      ObjectSet("TradingRange4",OBJPROP_XDISTANCE,5);
      ObjectSet("TradingRange4",OBJPROP_YDISTANCE,30);    
      }
   return(0);
   }
//+------------------------------------------------------------------+

Recommend