//+------------------------------------------------------------------+
//| Day Trader Market In Profile v1.3.mq4 |
//| Copyright © 2010, Eng\Bassam El-Faramawi. |
//| bmaamoon@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Eng\Bassam El-Faramawi."
#property link "bmaamoon@yahoo.com"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
extern int NumberOfDays = 10;
extern int SessionHalfHours = 48;
extern bool View_Sessions = true;
extern int ServerTimeGMTplus = 3;
extern int StepFactor = 3;
extern bool ViewTPOs = true;
extern bool TPOs_as_Letters = true;
extern int TPOs_Shift = 0;
extern int Letter_Size = 6;
extern color TPO_Color =White;
extern bool Inside_VA_Color = true;
extern color VA_Color = MediumOrchid;
extern bool ViewOpenFlag = true;
extern color OpenColor=LightSteelBlue;
extern int OpenFlagShift = 0;
extern bool View_Pointer = false;
extern color PointerColor = Magenta;
extern int PointerShift = 2;
extern bool ViewrangeLine = false;
extern color RangeLineColor = LightSteelBlue;
extern int rangeLine_Shift = 1;
extern bool ViewInitialBalanceLine = True;
extern color IBLineColor = SteelBlue;
extern int IBLineWidth = 2;
extern int IBLine_Shift = 1;
extern bool ViewValueArea = true;
extern double Persent_Of_TPO_ValueArea = 0.7;
extern int ValueArea_Shift = 0;
extern color TopLine_Color = Red;
extern int TopLine_Width = 2;
extern int TopLine_Start = 1;
extern int TopLine_End = 1;
extern color BottomLine_Color = Red;
extern int BottomLine_Width = 2;
extern int BottomLine_Start = 1;
extern int BottomLine_End = 1;
extern bool ViewPocLine = true;
extern int PocLine_shift = 0;
extern color PocColor =Blue;
extern int PocLine_Start = 1;
extern int PocLine_Width = 2;
extern int PocLine_End = 2;
extern bool ShowSplit12_9 = false;
extern color Split12_9Color = Green;
extern int Split12_9Width = 1;
extern bool ViewInformationText = False;
extern int InformationTextSize = 7;
extern color InformationTextColor = DarkTurquoise;
extern int InformationTextShift = 12;
string Text[50];
bool IsStepCalculated=false, DrowInitSplit12_9 = false;
double STEP;
int init()
{
DeleteAllObjects(NumberOfDays);
//----------------
if (Period()!= 30){
Comment(" ","\n","Eng.Bassam Market Profile V1.0","\n"," ","\n","By : Eng\ Bassam El-Faramawi","\n"," ","\n","bmaamoon@yahoo.com","\n"," ","\n","Please Switch TimeFrame to M30");
return(0); }
Comment(" ","\n","Eng.Bassam Market Profile V1.0","\n"," ","\n","By : Eng\ Bassam El-Faramawi","\n"," ","\n","bmaamoon@yahoo.com");
//-----------------
ChartSetInteger(ChartID(),CHART_SHIFT,1);
ChartSetInteger(ChartID(),CHART_AUTOSCROLL,1);
ChartSetInteger(ChartID(),CHART_MODE,CHART_LINE);
ChartSetInteger(ChartID(),CHART_COLOR_CHART_LINE,CLR_NONE);
ChartSetInteger(ChartID(),CHART_COLOR_BACKGROUND,Black);
ChartSetInteger(ChartID(),CHART_COLOR_FOREGROUND,White);
ChartSetInteger(ChartID(),CHART_SHOW_OHLC,0);
ChartSetInteger(ChartID(),CHART_SHOW_GRID,0);
ChartSetInteger(ChartID(),CHART_COLOR_GRID,White);
//---- indicators
Text[1]="A"; Text[2]="B"; Text[3]="C"; Text[4]="D"; Text[5]="E";
Text[6]="F"; Text[7]="G"; Text[8]="H"; Text[9]="I"; Text[10]="J";
Text[11]="K"; Text[12]="L"; Text[13]="M"; Text[14]="N"; Text[15]="O";
Text[16]="P"; Text[17]="Q"; Text[18]="R"; Text[19]="S"; Text[20]="T";
Text[21]="U"; Text[22]="V"; Text[23]="W"; Text[24]="X"; Text[25]="a";
Text[26]="b"; Text[27]="c"; Text[28]="d"; Text[29]="e"; Text[30]="f";
Text[31]="g"; Text[32]="h"; Text[33]="i"; Text[34]="j"; Text[35]="k";
Text[36]="l"; Text[37]="m"; Text[38]="n"; Text[39]="o"; Text[40]="p";
Text[41]="q"; Text[42]="r"; Text[43]="s"; Text[44]="t"; Text[45]="u";
Text[46]="v"; Text[47]="w"; Text[48]="x";
//----
//------
Createobjects();
if (ShowSplit12_9) {DrawSplit12_9(NumberOfDays,DrowInitSplit12_9); DrowInitSplit12_9=true;}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
DeleteAllObjects(NumberOfDays);
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (Period()!= 30){
Comment(" ","\n","Eng.Bassam Market Profile V1.0","\n"," ","\n","By : Eng\ Bassam El-Faramawi","\n"," ","\n","bmaamoon@yahoo.com","\n"," ","\n","Please Switch TimeFrame to M30");
return(0); }
Comment(" ","\n","Eng.Bassam Market Profile V1.0","\n"," ","\n","By : Eng\ Bassam El-Faramawi","\n"," ","\n","bmaamoon@yahoo.com");
//-----------------------------
//----------------
Clock();
//----------------
if (ShowSplit12_9) {DrawSplit12_9(NumberOfDays,DrowInitSplit12_9); DrowInitSplit12_9=true;}
//----
int counted_bars=IndicatorCounted(),m,t,n,Ymax,Ymin;
double h;
datetime dt = TimeCurrent(),t0;
//-----
//----
t = 48/SessionHalfHours;
if (MathMod(48,SessionHalfHours)>0) t++;
if (MathMod(SessionHalfHours,2)>0) m=1;
//----
t0=StrToTime(TimeYear(dt)+"."+TimeMonth(dt)+"."+TimeDay(dt)+" "+"00"+":"+"00");
Ymax = iBarShift(NULL, 30, t0);
if(View_Sessions)
{
int y1,y2,y3,y4,y5,y6,h0,h1,h2,h3,h4,h5,h6;
datetime t1,t2,t3,t4,t5,t6;
h0 = TimeHour(TimeCurrent());
h1 = ServerTimeGMTplus -2;
if (h0
0) t++;
if (MathMod(SessionHalfHours,2)>0) m=1;
datetime dt = TimeCurrent(),t0;
t0=StrToTime(TimeYear(dt)+"."+TimeMonth(dt)+"."+TimeDay(dt)+" "+"00"+":"+"00");
y0=iBarShift(NULL,0,t0);
//----
for(i=1; i=Ymin; y--)
{
for( s=1; s<=(Max-Min)/STEP; s++)
{
ObjectDelete(TimeToStr(iTime(NULL,0,y+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES) +" "+ DoubleToStr(s,0));
}
}
for(x=Max; x>=Min; x=x-STEP)
{
Space = 0;
i=(Max-x)/STEP;
u++;
for( y=Ymax; y>=Ymin; y--)
{
double opentick = iOpen(Symbol(),30,Ymax),
Maximum= iHigh(Symbol(),30,y),
Minimum= iLow(Symbol(),30,y);
if (Maximum x)
continue;
Space++;
//-------------
string TPOName = TimeToStr(iTime(NULL,0,Ymax-Space+1+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES) +" "+ DoubleToStr(u,0);
if (ViewTPOs)
{
if(TPOs_as_Letters == true)
{
ObjectDelete(TPOName);
ObjectCreate(TPOName, OBJ_TEXT, 0, iTime(NULL,0,Yt-Space+1+(TPOs_Shift*(Ymax-Ymin+1))), x);
ObjectSetText(TPOName,Text[Ymax-y+1], Letter_Size, "Arial", TPO_Color);
}
else
{
ObjectDelete(TPOName);
ObjectCreate(TPOName, OBJ_ARROW, 0, iTime(NULL,0,Yt-Space+1+(TPOs_Shift*(Ymax-Ymin+1))), x);
ObjectSet(TPOName,OBJPROP_ARROWCODE,167);
ObjectSet(TPOName,OBJPROP_COLOR,TPO_Color);
ObjectSet(TPOName, OBJPROP_BACK, True);
}
}
if (Inside_VA_Color == true)
{
int v;
for (v=imax; v<=imin; v++)
ObjectSet(TimeToStr(iTime(NULL,0,y+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES) +" "+ DoubleToStr(v,0),OBJPROP_COLOR,VA_Color);
}
}
//--------------
string open = "open "+TimeToStr(iTime(NULL,0,Ymax+OpenFlagShift+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES);
if(ViewOpenFlag)
{
ObjectDelete(open);
ObjectCreate(open, OBJ_ARROW, 0, iTime(NULL,0,Yt+OpenFlagShift+(TPOs_Shift*(Ymax-Ymin+1))), opentick);
ObjectSet(open,OBJPROP_ARROWCODE,161);
ObjectSet(open,OBJPROP_COLOR,OpenColor);
ObjectSet(open, OBJPROP_BACK, True);
}
//--------------
double POCShift = MathAbs(PocTick-Mid),
SpaceShift=MathAbs(x-Mid);
if (Space > POC)
{
POC = Space;
PocTick = x;
}
if (Space == POC && SpaceShift < POCShift)
PocTick = x;
//--------------
string Poc = "POC "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES);
int Poc_start =Yt-(PocLine_shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1)) ,
Poc_end = Yt-POC-(PocLine_shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1));
if(ViewPocLine)
{
ObjectDelete(Poc);
ObjectCreate(Poc, OBJ_TREND, 0, iTime(NULL,0,Poc_start), PocTick ,iTime(NULL,0,Poc_end),PocTick );
ObjectSet(Poc,OBJPROP_COLOR,PocColor);
ObjectSet(Poc, OBJPROP_WIDTH,PocLine_Width);
ObjectSet(Poc, OBJPROP_RAY, false);
ObjectSet(Poc, OBJPROP_BACK, True);
}
//--------------
AllTicks=AllTicks+Space;
TPOs[i]=Space;
}
ValueArea=AllTicks*Persent_Of_TPO_ValueArea;
imax=(Max-PocTick)/STEP;
imin=imax;
ValueRange=TPOs[imax];
while(ValueRange < ValueArea)
{
if(TPOs[imax-1] == TPOs[imin+1])
{
ValueRange = ValueRange+(2*TPOs[imax-1]);
imax--;
imin++;
}
if(TPOs[imax-1] > TPOs[imin+1])
{
ValueRange = ValueRange+TPOs[imax-1];
imax--;
}
if(TPOs[imax-1] < TPOs[imin+1])
{
ValueRange = ValueRange+TPOs[imin+1];
imin++;
}
}
string Range = "Range "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES),
ValueAreaRange = "ValueAreaRange "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES),
ValueTop = "ValueTop "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES),
ValueBottom = "ValueBottom "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES),
RangeLine = "RangeLine "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES),
IBLine = "IBLine "+TimeToStr(iTime(NULL,0,Ymax+(TPOs_Shift*(Ymax-Ymin+1))),TIME_DATE|TIME_MINUTES);
int Yvt_start= Yt-(ValueArea_Shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1)),
Yvt_end= Yt-TPOs[imax]-(ValueArea_Shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1)),
Yvb_start= Yt-(ValueArea_Shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1)),
Yvb_end= Yt-TPOs[imin]-(ValueArea_Shift*(Ymax-Ymin+1))+(TPOs_Shift*(Ymax-Ymin+1));
if(ViewValueArea)
{
ObjectDelete(ValueTop);
ObjectCreate(ValueTop, OBJ_TREND,0,iTime(NULL,0,Yvt_start),Max-(imax*STEP), iTime(NULL,0,Yvt_end),Max-(imax*STEP));
ObjectSet(ValueTop, OBJPROP_COLOR, TopLine_Color);
ObjectSet(ValueTop, OBJPROP_WIDTH,TopLine_Width);
ObjectSet(ValueTop, OBJPROP_RAY, false);
ObjectSet(ValueTop, OBJPROP_BACK, True);
ObjectDelete(ValueBottom);
ObjectCreate(ValueBottom, OBJ_TREND,0,iTime(NULL,0,Yvb_start),Max-(imin*STEP),iTime(NULL,0,Yvb_end),Max-(imin*STEP));
ObjectSet(ValueBottom, OBJPROP_COLOR, BottomLine_Color);
ObjectSet(ValueBottom, OBJPROP_WIDTH,BottomLine_Width);
ObjectSet(ValueBottom, OBJPROP_RAY, false);
ObjectSet(ValueBottom, OBJPROP_BACK, True);
}
if(ViewInformationText)
{
ObjectDelete(Range);
ObjectCreate(Range, OBJ_TEXT, 0,iTime(NULL,0,Yt-(Ymax-Ymin+1)+InformationTextShift+(TPOs_Shift*(Ymax-Ymin+1))), PocTick);
ObjectSetText(Range, "Range= "+DoubleToStr((Max-Min),4)+" Pip", InformationTextSize, "Arial",InformationTextColor);
ObjectDelete(ValueAreaRange);
ObjectCreate(ValueAreaRange, OBJ_TEXT, 0,iTime(NULL,0,Yt-(Ymax-Ymin+1)+InformationTextShift+(TPOs_Shift*(Ymax-Ymin+1))), PocTick-(2*STEP));
ObjectSetText(ValueAreaRange, "TPO ValueArea= "+DoubleToStr((imin-imax)*STEP,4)+" Pip", InformationTextSize, "Arial",InformationTextColor);
}
if(ViewrangeLine)
{
ObjectDelete(RangeLine);
ObjectCreate(RangeLine, OBJ_TREND,0,iTime(NULL,0,Yt-(rangeLine_Shift*(Ymax-Ymin+1))+1+(TPOs_Shift*(Ymax-Ymin+1))),Max, iTime(NULL,0,Yt-(rangeLine_Shift*(Ymax-Ymin+1))+1+(TPOs_Shift*(Ymax-Ymin+1))),Min);
ObjectSet(RangeLine, OBJPROP_COLOR, RangeLineColor);
ObjectSet(RangeLine, OBJPROP_STYLE,STYLE_DOT);
ObjectSet(RangeLine, OBJPROP_RAY, false);
}
if (ViewInitialBalanceLine)
{
ObjectDelete(IBLine);
ObjectCreate(IBLine, OBJ_TREND,0,iTime(NULL,0,Yt+IBLine_Shift+(TPOs_Shift*(Ymax-Ymin+1))),IBmax, iTime(NULL,0,Yt+IBLine_Shift+(TPOs_Shift*(Ymax-Ymin+1))),IBmin);
ObjectSet(IBLine, OBJPROP_COLOR, IBLineColor);
ObjectSet(IBLine, OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(IBLine, OBJPROP_WIDTH,IBLineWidth);
ObjectSet(IBLine, OBJPROP_RAY, false);
}
if(View_Pointer)
{
int Pointer= (Max-Close[0])/STEP;
if ( Max-(Pointer*STEP)-Close[0] > Close[0]-Max+((Pointer+1)*STEP) )
Pointer++;
int Pointr =Yt-TPOs[Pointer]-PointerShift;
if (Pointr < 0)
Pointr =0;
ObjectDelete("Pointer");
if(ObjectFind("Pointer") != 0)
{
ObjectCreate("Pointer", OBJ_ARROW, 0, iTime(NULL,0,Pointr+(TPOs_Shift*(Ymax-Ymin+1))), Close[0]+STEP);
ObjectSet("Pointer", OBJPROP_ARROWCODE,239);
ObjectSet("Pointer",OBJPROP_COLOR,PointerColor);
ObjectSet("Pointer", OBJPROP_BACK, false);
}
else
{
ObjectMove("Pointer", 0, iTime(NULL,0,Pointr+(TPOs_Shift*(Ymax-Ymin+1))), Close[0]+STEP);
}
}
}
//+------------------------------------------------------------------+
void DeleteAllObjects(int NumberOfDays)
{
datetime dt,t0;
int y,u,Ymax;
string TPOName;
dt =iTime(NULL,0,0);
t0=StrToTime(TimeYear(dt)+"."+TimeMonth(dt)+"."+TimeDay(dt)+" "+"00"+":"+"00");
Ymax=iBarShift(NULL,0,t0);
for (y=0; y<=NumberOfDays+6; y++)
{
dt=iTime(NULL,0,Ymax+1);
t0=StrToTime(TimeYear(dt)+"."+TimeMonth(dt)+"."+TimeDay(dt)+" "+"00"+":"+"00");
Ymax=iBarShift(NULL,0,t0);
}
for (y=0; y<=Ymax; y++)
{
TPOName = TimeToStr(iTime(NULL,0,y),TIME_DATE|TIME_MINUTES);
if(ObjectFind("open "+TPOName)==0)
ObjectDelete("open "+TPOName);
if(ObjectFind("Pointer")==0)
ObjectDelete("Pointer");
if(ObjectFind("POC "+TPOName)==0)
ObjectDelete("POC "+TPOName);
if(ObjectFind("ValueTop "+TPOName)==0)
ObjectDelete("ValueTop "+TPOName);
if(ObjectFind("ValueBottom "+TPOName)==0)
ObjectDelete("ValueBottom "+TPOName);
if(ObjectFind("Range "+TPOName)==0)
ObjectDelete("Range "+TPOName);
if(ObjectFind("ValueAreaRange "+TPOName)==0)
ObjectDelete("ValueAreaRange "+TPOName);
if(ObjectFind("RangeLine "+TPOName)==0)
ObjectDelete("RangeLine "+TPOName);
if(ObjectFind("IBLine "+TPOName)==0)
ObjectDelete("IBLine "+TPOName);
if(ObjectFind("Split Max "+TPOName)==0)
ObjectDelete("Split Max "+TPOName);
if(ObjectFind("Split Min "+TPOName)==0)
ObjectDelete("Split Min "+TPOName);
for (u=0; u<=1000; u++)
{
if(ObjectFind(TPOName+" "+DoubleToStr(u,0))==0)
ObjectDelete(TPOName+" "+DoubleToStr(u,0));
}
}
}
//+------------------------------------------------------------------+
void Clock()
{
double i;
int m,s,k;
m=Time[0]+Period()*60-CurTime();
i=m/60.0;
s=m%60;
m=(m-m%60)/60;
Comment( m + " minutes " + s + " seconds left to bar end");
ObjectDelete("time");
if(ObjectFind("time") != 0)
{
ObjectCreate("time", OBJ_TEXT, 0, Time[0], Close[0]+ 0.0005);
ObjectSetText("time", " <"+m+":"+s, 12, "Arial", SlateGray);
}
else
{
ObjectMove("time", 0, Time[0], Close[0]+0.0005);
}
}
//--------------------
double Calculate_Step (bool IsStepCalculated, double STEP)
{
double H = High[iHighest(NULL,PERIOD_D1,MODE_HIGH,2,0)], L = Low[iLowest(NULL,PERIOD_D1,MODE_LOW,2,0)];
if(!IsStepCalculated)
STEP = (H-L)/(StepFactor);
return(STEP);
}
//----------------
void DrawSplit12_9(int NumberOfDays,bool DrowInitSplit12_9)
{
int y0 = iBarShift(NULL,0,StrToTime(TimeYear(TimeCurrent())+"."+TimeMonth(TimeCurrent())+"."+TimeDay(TimeCurrent())+" "+"01"+":"+"30"));
for (int i=0; i