Exploration Output of Market Profile

Dear Team,

Whilst I feel that market profile is more of a visual art than mathematics, in order to shortlist stocks to consider for trade, I feel it would be worthwhile to consider an exploration for the same. I am attaching an afl on Market Profiles (Available on the net) and post that I will put up my requirement

_SECTION_BEGIN("TPO Profile of Market Auctions"); 

// Milind and KAKA created the core of the Market Profile code in 2009-10
// Tweaks, Additonal Functions & Visual Design by Twitter.com/Uptickr in June 2015


function Lastthursday()
{
 Daysinmonth=IIf(Month()==1 OR Month()==3 OR Month()==5 OR Month()==7 OR Month()==8 OR Month()==10 OR Month()==12,31,30);
 Daysinmonthfeb=IIf(Year()%4 == 0 AND Year()%100!=0,29,28);
 Daysinmonthfinal=IIf(Month()==2,Daysinmonthfeb,Daysinmonth);
 returnvalue=IIf(Daysinmonthfinal-Day()<7 AND DayOfWeek()==4,1,IIf(Daysinmonthfinal-Day()<8 AND DayOfWeek()==3 AND Ref(DayOfWeek(),1)!=4 AND Day()!=Daysinmonthfinal ,1,0));
 return returnvalue;
}


Plot( TimeFrameGetPrice("H", inDaily ), "Day's high", ColorGreen, styleNoLine);
Plot( TimeFrameGetPrice("L", inDaily ), "Day's Low", ColorRed, styleNoLine);

SetChartOptions(0,0,Null);
SetChartBkColor(colorBlack);


GraphXSpace = 10;

ProfileType = ParamList("Profile Type","TPOs|Volume|None", 0); 
Period= ParamList("Period","Daily|Weekly|Since Last Expiry",0);
DenType = ParamList("Density","Auto|Manual", 0); 
DenManual = Param("If Density Manual", 3, 0.25, 100, 0.25);
spread = Param("Horizontal Density", 160, 1, 200, 1);
teb=ParamToggle("Split Profile","No|Yes", 0); 
onesigma=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",0); 
ViewPOC = ParamToggle("Show POC", "No|Yes",1); 
Colorpoc=ParamColor("POC Color", colorViolet); 
EnIB = ParamToggle("Show IB", "Yes|No",1); 
ViewVALVAH = ParamToggle("Show VAL VAH", "No|Yes",1); 
Viewfill = ParamToggle("Show VA Fill", "No|Yes",1); 
Colorfill=ParamColor("Value Area Color", colorAqua);
ColorIB=ParamColor("InitialBalance Color", ColorRGB(13,185,242)); 
ColorOverlay = ParamColor("VOverlay Color", colorGrey40); 
IBBars = Param("Initial Bar", 1, 1, 375, 1); 
ColorA = ParamColor("A-Period Color", colorCustom16); 
ColorB = ParamColor("B-Period Color", ColorRGB(234,205,166));
ColorC = ParamColor("C-Period Color", colorLime); 
ColorD = ParamColor("D-Period Color", colorLightOrange); 
ColorE = ParamColor("E-Period Color", ColorRGB(128,255,172)); 
ColorF = ParamColor("F-Period Color", ColorRGB(255,28,255)); 
ColorG = ParamColor("G-Period Color", colorWhite); 
ColorH = ParamColor("H-Period Color", ColorRGB(255,85,85)); 
ColorI = ParamColor("I-Period Color", colorLightGrey); 
ColorJ = ParamColor("J-Period Color", ColorRGB(255,149,255)); 
ColorK = ParamColor("K-Period Color", colorYellow); 
ColorL = ParamColor("L-Period Color", colorCustom11);
ColorM = ParamColor("M-Period Color", colorCustom10);
ColorDef = ParamColor("Default Color", ColorRGB(13,185,242));  


if (Dentype == "Auto") 
{
	PrevClose = TimeFrameGetPrice("C", inDaily,-1 );
	DenPrec=Prec((0.1/100*PrevClose),1);
	DenPrec=Iif(Denprec<0.1,0.1,DenPrec);
	Den=LastValue(DenPrec);

}

if (Dentype == "Manual") 

{
	Den = DenManual;
}


if(Period=="Daily" )
{
BarsInDay = BarsSince(Day() != Ref(Day(), -1)); 
Bot = TimeFrameGetPrice("L", inDaily, 0); 
Top = TimeFrameGetPrice("H", inDaily, 0); 
Vol = TimeFrameGetPrice("V", inDaily, 0); 
}


if(Period=="Weekly" )
{
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
bot1=ValueWhen(BarsInDay==0,L,1);
Bot2 = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);
Bot=Min(bot1,bot2);
top1=ValueWhen(BarsInDay==0,H,1);Top2 =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);
Top=Max(top1,top2);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Since Last Expiry"  )
{
BarsInDay = BarsSince(Lastthursday()==0 AND Ref(Lastthursday(), -1)==1);
bot1=ValueWhen(BarsInDay==0,L,1);
Bot2 = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);
bot=Min(bot1,bot2);
top1=ValueWhen(BarsInDay==0,H,1);
Top2 =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);
top=Max(top1,top2);
Vol = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,Sum(V,BarsInDay),0);
}




CurTop = HHV(H,BarsInDay+1); 
Curbot = LLV(L,BarsInDay+1); 
Range = Highest(Top-Bot); 
TodayRange = Top - Bot; 

AveRange = Sum(Top-Bot,30)/30; 
LAveRange = AveRange[BarCount-1]; 

// Initialization 
baseX = 0; 
baseY = floor(Bot[0]/Den)*Den; 
relTodayRange = 0; 
firstVisBar = Status("firstvisiblebar"); 
lastVisBar = Status("lastvisiblebar"); 

D=.0005; 
total=0; 
totaldn=0; 
totalup=0; 
shiftup=0; 
shiftdn=0;
startr=0; 

for (j=0; j <= 100; j++) { 
  x[j] = 0; 
} 

BX=Volume;
AX=Avg;
ValueX=BX*AX;
BarsfromtodaybeginX = 1 + BarsSince( Day() != Ref(Day(), -1));
TotalvalueX=Sum(ValueX,BarsfromtodaybeginX);
TotalvolumeX=Sum(V,BarsfromtodaybeginX);
ATPX=(TotalvalueX/TotalvolumeX);


i0 = 0; 
i1 = 0; 
for (i=0; i<BarCount; i++) { //for (i=0; i<BarCount; i++) { 
  if (BarsInDay[i] == 0 AND i < firstVisBar) { 
    i0 = i; 
  } 
  if (BarsInDay[i] == 0 AND i >= lastVisBar) { 
    i1 = i; 
  } 
} 

i1 = BarCount-1; 
for (i=i0; i<=i1; i++) { 
  if (BarsInDay[i] == 0) { 
    baseX = i; 
    baseY = floor(Bot[i]/Den)*Den; 
    maxY = floor(Top[i]/Den)*Den; 
    relTodayRange = (maxY-baseY)/Den; 
	

    for (j=0; j <= relTodayRange; j++) { 
      x[j] = 0; 
    } 
  } 
    
    range_x=lastVisBar-firstVisBar;  
    tpl = 30; 
    Intervalmin=Interval()/60; 
    flt = 1; 
    Color=20; 
    stopg=0; 
    stopr=0; 
    new=0;

     for (j=0; j<= relTodayRange; j++) {  
      if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) { 
		if (ProfileType == "TPOs" ) {
        PlotText(StrExtract("A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M,A,B,C,D,E,F,G,H,I,J,K,L,M", 
        IIf(BarsInDay[i]<flt,0,ceil(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x[j]*(range_x/spread)), baseY+j*Den, 
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==0,ColorA,
        IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==1,ColorB,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==2,ColorC,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==3,ColorD,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==4,ColorE,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==5,ColorF,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==6,ColorG,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==7,ColorH,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==8,ColorI,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==9,ColorJ,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==10,ColorK,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==11,ColorL,
		 IIf(ceil(BarsInDay[i]/(tpl/Intervalmin))==12,ColorM,
		 ColorDef))))))))))))));


		  //ParamColor("TPO Color", colorWhite)); 
		}
       x[j]++; // Increment number of rows

      } 
    } 


     

  //Draw Initial Balance after 10:15am bar is complete 
  if (BarsInDay[i] == IBBars AND EnIB == 0) { 
    LX=Line1 = LineArray(i-2, curtop[i-1],i+9, curtop[i-1],0,True); 
    Plot(Line1,"",colorIB,styleLine+styleDashed|styleNoRescale); 
    LY=Line1 = LineArray(i-2, curbot[i-1],i+9, curbot[i-1],0,True); 
    Plot(Line1,"",colorIB,styleLine+styleDashed|styleNoRescale); 
    //PlotOHLC(LX,LX,LY,LY,"",colorIB,styleCloud,styleNoLabel,Null,Null,Null,-2); 

  } 

  //Value Area

  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) { 
    maxXj = 0; 
    maxj = 0; 
    midrange = int( relTodayRange / 2 ) + 1;

	//Find POC | PROBLEM: How to choose when multiple rows with same number of TPOs? On DD day?
	//x[j] stores number of TPOs

    for (j=0; j<= relTodayRange; j++) { 
      if (maxXj < x[j]) {maxXj = x[j]; maxj = j; //StaticVarSet("Maxj",j); new=j; 	
      } 
				else if ( Maxxj == x[j]) 
                {
                    if ( abs( midrange - j ) < abs( midrange - maxj ) )
                    {
                        MaxXj = x[j];
                        Maxj = j;
                    }
                }

    } 


	// Find Total TPOs
    for ( n = 1; n <= relTodayRange; n++ ) { 			
       total[n]=x[n]+total[n-1]; 
        } 

	// 70% of Total TPOs
    Value_area=ceil((total[relTodayRange]*onesigma)/100); 	

	

    for ( a = 1; a <= relTodayRange; a++ ) 
     { 
        if(Maxj-a>0 AND Maxj+a<relTodayRange) 
        { 
            if(MaxXj+total[Maxj+a]-total[Maxj]+total[Maxj-1]-total[Maxj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;} 
         }     
        else if(Maxj-a<1 )  
        { 
            if(MaxXj+total[Maxj+a]-total[Maxj]+total[Maxj-IIf(Maxj>0,-1,0)]>=Value_area){shiftup=a; shiftdn=maxj-1; break;}         
           } 
        else if(Maxj+a>relTodayRange )  
        { 
            if(MaxXj+total[relTodayRange]-total[Maxj]+total[Maxj-1]-total[Maxj-(a+1)] >=Value_area){shiftup=relTodayRange-maxj; shiftdn=a; break;}         
           } 
     }  

 
    Vah = LineArray(i-2, baseY+(maxj+shiftup)*Den, i-1, baseY+(maxj+shiftup)*Den,0,True);  
    Val = LineArray(i-2, baseY+(maxj-shiftdn)*Den, i-1, baseY+(maxj-shiftdn)*Den,0,True); 
    VahX = LineArray(BaseX, baseY+(maxj+shiftup)*Den, i-1, baseY+(maxj+shiftup)*Den,0,True);  
    ValX = LineArray(BaseX, baseY+(maxj-shiftdn)*Den, i-1, baseY+(maxj-shiftdn)*Den,0,True); 


    poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);  
    if(ViewVALVAH==1){Plot(VahX,"",colorfill,styleLine|styleNoRescale); 
    Plot(ValX,"",colorfill,styleLine|styleNoRescale);} 
    if(ViewPOC==1){Plot(poc,"",Colorpoc,styleLine|styleNoRescale);} 
    if(ViewVALVAH==1){PlotText("  "+(baseY+(maxj+shiftup)*Den),i-4.5,baseY+(maxj+shiftup)*Den+Den,colorWhite);} 
    if(ViewVALVAH==1){PlotText("  "+(baseY+(maxj-shiftdn)*Den),i-4.5,baseY+(maxj-shiftdn)*Den-Den-Den,colorWhite);}     
    if(ViewTPOCount==1){PlotText(""+total[maxj],basex,baseY-Den-Den,ColorRGB(168,168,168)); 
    PlotText(""+(total[relTodayRange]-total[maxj]),basex,Top[i]+Den+Den,ColorRGB(168,168,168));} 

    if(ViewPOC==1){PlotText("  "+(baseY+maxj*Den),i-5,baseY+maxj*Den,Colorpoc);}  
  } 
     
    if (i < BarCount - 1 AND BarsInDay[i+1] == 0 OR i == BarCount-1) { 
     
      for  (p = 1; p < relTodayRange+1; p++){ 
      line = LineArray(baseX, baseY+p*Den, baseX+x[p], baseY+p*Den);  
      line2 = LineArray(baseX, baseY+(p-1)*Den, baseX+x[p-1], baseY+(p-1)*Den); 
   } 
     if(Viewfill==1 AND ProfileType != "Volume"){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel, Null,Null, Null,-9);} 

 }  
} 


//Volume Profile

if (ProfileType == "Volume") 

{
	segments = IIf( Interval() < inDaily, Day(), Month() ); 
	segments = segments != Ref( segments , -1 ); 

	PlotVAPOverlayA( segments , 800, 80, colorOverlay, 4); 

}

//Composite Volume Profile

if (ProfileType == "TPOs" OR ProfileType == "None") 

{
	PlotVAPOverlay( lines = 400, width = 10, color = ColorOverlay, vapstyle = 1 );
}




_SECTION_END(); 


The graph looks like below:

RELIANCE

I wish to have the following values in exploration

  1. Today's POC, VAh, VAl e.g 2241.8, 2250.6, 2233
  2. Current week's highest VAh, VAl individual day on day - Because it was Monday it will be 2250.6, 2233
  3. Last week's (Oct 5-Oct 9) highest Vah (2316.6) & lowest Val (2213.2)

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.