Volume Profile and Market Profile a new wave of market picture

Status
Not open for further replies.
Just look /search above posts from where afl posted. ..just need some lines editing to enable it to below 5.8 version. ..just adding // this in some lines. ...I have no a cess to ami now. ..If not found let me know on weekends or use afl which posted by happy bro
Thanks Vijay and Xray27 for the prompt reply
i have that afl and i did edit that afl but still the error is showing, maybe i am missing something.

Screenshot

Code:
SECTION_BEGIN("MarketProfile");
SetChartOptions(0,chartShowArrows|chartShowDates);
//------------------------------------------------------------------------------
//
//  Formula Name:    Market Profile 
//
// Use with 5/15min chart
// Originial - From AFL library
// Edited by - Milind / KAKA
// AFL Modified by Rajandran- code works good in 5min, 15min, 30min timeframe
// Code is Compatible with Amibroker 5.8 and above
// Letter A now repeats for first 30 min, Letter B next 30 min so on
// Multiple Repeating Alphabets Horizontally to be fixed in 5min and 15min

//Market Profile 9/12/2009

PlotOHLC(Ref(O,-1),Ref(H,-1),Ref(L,-1),Ref(C,-1),"Price",colorBlack,styleNoLine);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g", Ref(O,-1), Ref(H,-1), Ref(L,-1), Ref(C,-1) ));


EnMP2= ParamList("MarketProfile","Letters|Solid|Lines");
styleLines = ParamStyle("Style", styleLine, maskAll);

Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly",1);


Den = Param("Density", 3, 0.25, 100, 0.25); // Resolution in terms of $
percent=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",1);
ViewPOC = ParamToggle("Show POC", "No|Yes",1);
ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);
Viewfill = ParamToggle("Show VA Fill", "No|Yes",1);
Colorpoc=ParamColor("Color POC", colorYellow);
Colorfill=ParamColor("Color Fill", ColorRGB(20,40,60));


EnIB = ParamToggle("Show Initial Balance", "Yes|No");
IBBars = Param("Initial Balance Bars", 2, 0, 10, 1);

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=="Hourly"){
BarsInDay = BarsSince(Minute() != Ref(Minute(), -1));
Bot = TimeFrameGetPrice("L", in5Minute, 0);
Top = TimeFrameGetPrice("H", in5Minute, 0);
Vol = TimeFrameGetPrice("V", in5Minute, 0);
}

if(Period=="Weekly"){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));
Bot = TimeFrameGetPrice("L", inMonthly, 0);
Top = TimeFrameGetPrice("H", inMonthly, 0);
Vol = TimeFrameGetPrice("V", inMonthly, 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;
}

i0 = 0;
i1 = 0;
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;
	spread = Param("X Space", 112, 1, 200, 1);
	tpl = Param("Time Per Letter (mins)", 30, 1, 360, 1);
	Intervalmin=Interval()/60;
	flt =Param("First Letter (Bars)", 1, 1, 60, 1);
	teb=ParamToggle("To Each Bar","No|Yes");
	Color=Param("Color Threshold",20,1,50,1);
	stopg=0;
	stopr=0;
	new=0;
	
	Voloumeunit=Vol[i]/LastValue(BarsInDay);


  if (EnMP2 == "Letters") {
    for (j=0; j<= relTodayRange; j++) {
      if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
        //PlotTextSetFont("", "Arial", 6, BarCount-1, Close[ BarCount - 3 ], colorGreen, colorDefault, -20 ); 
       // PlotTextSetFont("C", "Arial", 40, 100, 100, colorGreen, colorDefault, -20 ); 
		PlotText(StrExtract(" A , B , C , D , E , F , G , H ,  I  , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z, a , b , c , d , e , f , g , h , i , j , k , L , m , n ,o , p , q , r , s , t , u , v , w , x , y , z ",
		IIf(BarsInDay[i]<flt,0,floor(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x[j]*(range_x/spread)), baseY+j*Den, 
		colorWhite,ColorHSB(10+((floor(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
       x[j]++;
	//PlotTextSetFont("", "Arial", 10, BarCount-1, Close[ BarCount - 3 ], colorGreen, colorDefault, -20 ); 
      }
    }
  }
	
  else if (EnMP2 == "Lines" OR EnMP2 == "Solid") {
    for (j=0; j<= relTodayRange; j++) {
     if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
		if(Type=="Price Profile"){x[j]=x[j]+1;}
		else if(Type=="Volume Profile"){x[j]=x[j]+round(V[i]/Voloumeunit);}
 	
	   }
    }
  }  

  // Draw Initial Balance after 11am bar is complete
  if (BarsInDay[i] == IBBars AND EnIB == 0) {
    Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
    Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
  }

  // Examine x[j]
  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
    maxXj = 0;
	maxj = 0;
    for (j=0; j<= relTodayRange; j++) {
      if (maxXj < x[j]) {maxXj = x[j]; maxj = j; StaticVarSet("Maxj",j); new=j;
	  }
    }
	for ( n = 1; n <= relTodayRange; n++ ) {
       total[n]=x[n]+total[n-1];
        }
	Value_area=(total[relTodayRange]*percent)/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-1]>=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(baseX, baseY+(maxj+shiftup)*Den, i, baseY+(maxj+shiftup)*Den,0,True);
	Val = LineArray(baseX, baseY+(maxj-shiftdn)*Den, i, baseY+(maxj-shiftdn)*Den,0,True);
	poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);
	//Shift for Yesterday's Values
	nobs = ceil(375/(Interval()/60));
	if(ViewVALVAH==1){
		Plot(Vah,"",ParamColor("Color_VA",  colorLightBlue),styleLine|styleNoRescale);
		Plot(Val,"",ParamColor("Color_VA",  colorLightBlue),styleLine|styleNoRescale);
		Plot(Val,"",colorLightGrey,styleDashed|styleNoRescale,0,0,nobs);
		Plot(Vah,"",colorLightGrey,styleDashed|styleNoRescale,0,0,nobs);
	}
	if(ViewPOC==1){
		Plot(poc,"",Colorpoc,styleLine|styleNoRescale);
		Plot(poc,"",colorYellow,styleDashed|styleNoRescale,0,0,nobs);
	}
	PlotText(""+(baseY+(maxj+shiftup)*Den),i-5,baseY+(maxj+shiftup)*Den,colorWhite);
	PlotText(""+(baseY+(maxj-shiftdn)*Den),i-5,baseY+(maxj-shiftdn)*Den,colorWhite);
	if(ViewTPOCount==1){PlotText(""+total[maxj],basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_VAL", colorLavender));
	PlotText(""+(total[relTodayRange]-total[maxj]),basex,Top[i]+(Top[i]*0.0005),ParamColor("Color_VAH", colorLavender));}



	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 (EnMP2 == "Solid")
	  {
	  PlotOHLC( Line,  Line,  Line2, Line2, "",IIf(p>(maxj+shiftup),ParamColor("Color_VAH",  colorLavender),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorLightBlue),ParamColor("Color_VAL", colorLavender))) ,styleCloud|styleNoRescale|styleNoLabel);
	  }
	  if (EnMP2 == "Lines") 
	  {
     Plot(line,"",IIf(p>(maxj+shiftup),ParamColor("Color_VAH", colorLavender),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorLightBlue),ParamColor("Color_VAL",  colorLavender))) , styleLines|styleNoLabel);
     }
 	
   }
	 if(Viewfill==1){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);}

 } 
}


_SECTION_END();

_SECTION_BEGIN("Gradient Backfill");
SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 0,0,0 )),

ParamColor("BgBottom", ColorRGB( 0,0,0 )),ParamColor("titleblock",ColorRGB( 192,192,192 ))); 
_SECTION_END();
 
Last edited by a moderator:

XRAY27

Well-Known Member
Thanks Vijay and Xray27 for the prompt reply
i have that afl and i did edit that afl but still the error is showing, maybe i am missing something.

@RNS .rajendran AFL modified for getting letters and it is for 5.8 and above

try this

Just put 3 under density in parameters

Code:
_SECTION_BEGIN("MarketProfile");
//------------------------------------------------------------------------------
//
//  Formula Name:    Market Profile 
//
// Use with 5/15min chart
// Originial - From AFL library
// Edited by - Milind / KAKA

//Market Profile 10/12/2009


//------------------------------------------------------------------------------
// This is a modified version of afl date 09/19/2009 as listed above
// Contains a couple changes:
// 1) a more correct (but not complete) calculation of POC.
// 2) attempt to avoid the out of bound runtime error that
//    sometimes occurs. See below:
//
// Here are changes to emulate the arrays x[] and total[] so
// that the array size are not limited by Barcount.
// Now one probably should not get the out of bound error even
// if the density or ticksize is smaller. Of course, there will
// be more overhead in calculation.
// johncw 20091010
// Wrapper start
_N(VarKey = NumToStr(GetChartID(), 1.0, False) + "_");
_N(VarTotal = "V_T" + VarKey);
_N(VarX = "V_x" + VarKey);

function L_StaticVarSet(L_name, L_value)
{
	local L_name, L_value;
	StaticVarSet(L_name + VarKey, L_value); 
}

function L_StaticVarGet(L_name)
{
	local L_name;
	return(StaticVarGet(L_name + VarKey));
}

function x_g(L_idx)
{
	local L_idx;
	return VarGet(VarX + L_idx);
}

function x_s(L_idx, L_value)
{
	local L_idx, L_value;
	VarSet(VarX + L_idx, L_value);
}

function total_g(L_idx)
{
	local L_idx;
	return VarGet(VarTotal+L_idx);
}

function total_s(L_idx, L_value)
{
	local L_idx, L_value, L_name;
	VarSet(VarTotal+L_idx, L_value);
}
// Wrapper end
//------------------------------------------------------------------------------


PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);


EnMP2= ParamList("MarketProfile","Solid|Lines|Letters");
styleLines = ParamStyle("Style", styleLine, maskAll);

Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly",1);

Den = Param("Density", 1, 0.25, 100, 0.25); // Resolution in terms of $
percent=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",1);

ViewPREVIOUS = ParamToggle("Previous Values", "No|Yes",1);

ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);
Viewfill = ParamToggle("Show VA Fill", "No|Yes",0);
Colorpoc=ParamColor("Color POC", colorYellow);
Colorfill=ParamColor("Color Fill", ColorRGB(20,40,60));


EnIB = ParamToggle("Show Initial Balance", "Yes|No");
IBBars = Param("Initial Balance Bars", 2, 0, 10, 1);

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=="Hourly"){
BarsInDay = BarsSince(Minute() != Ref(Minute(), -1));
Bot = TimeFrameGetPrice("L", in5Minute, 0);
Top = TimeFrameGetPrice("H", in5Minute, 0);
Vol = TimeFrameGetPrice("V", in5Minute, 0);
}

if(Period=="Weekly"){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));
Bot = TimeFrameGetPrice("L", inMonthly, 0);
Top = TimeFrameGetPrice("H", inMonthly, 0);
Vol = TimeFrameGetPrice("V", inMonthly, 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;

i0 = 0;
i1 = 0;
for (i=0; i<BarCount; i++) {
  x_s(i, 0); // should not need this
  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_s(j, 0);
		
    }
  }
	
	range_x=lastVisBar-firstVisBar;
	spread = Param("X Space", 80, 1, 200, 1);
	tpl = Param("Time Per Letter (mins)", 30, 1, 360, 1);
	Intervalmin=Interval()/60;
	flt =Param("First Letter (Bars)", 1, 1, 60, 1);
	teb=ParamToggle("To Each Bar","No|Yes");
	Color=Param("Color Threshold",20,1,50,1);
	stopg=0;
	stopr=0;
	new=0;
	
	Voloumeunit=Vol[i]/LastValue(BarsInDay);


  if (EnMP2 == "Letters") {
    for (j=0; j<= relTodayRange; j++) {
      if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
		PlotText(StrExtract(" A , B , C , D , E , F , G , H ,  I  , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z, a , b , c , d , e , f , g , h , i , j , k , L , m , n ,o , p , q , r , s , t , u , v , w , x , y , z ",
		IIf(BarsInDay[i]<flt,0,ceil(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x_g(j)*(range_x/spread)), baseY+j*Den, 
		colorWhite,ColorHSB(10+((ceil(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
		x_s(j, x_g(j)+1);

      }
    }
  }
	
  else if (EnMP2 == "Lines" OR EnMP2 == "Solid") {
    for (j=0; j<= relTodayRange; j++) {
     if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
		if(Type=="Price Profile"){x_s(j, x_g(j)+1);}
		else if(Type=="Volume Profile"){x_s(j, x_g(j)+round(V[i]/Voloumeunit));}
 	
	   }
    }
  }  

  // Draw Initial Balance after 11am bar is complete
  if (BarsInDay[i] == IBBars+1 AND EnIB == 0) {
    Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
    Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
  }

  // Examine x[j]
  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
    maxXj = 0;
	maxj = 0;
	midrange = int(relTodayRange/2)+1;
    for (j=0; j<= relTodayRange; j++) {
      if (maxXj < x_g(j)) {
			maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
	  } else if ( MaxXj == x_g(j)) {
			if (abs(midrange-j)  < abs(midrange-L_StaticVarGet("Maxj"))) {
				maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
			}
	  }
    }
	total_s(0, 0);
	for ( n = 1; n <= relTodayRange; n++ ) {
		total_s(n, x_g(n) + total_g(n-1));
        }

	Value_area=(total_g(relTodayRange)*percent)/100;

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

	Vah = LineArray(baseX, baseY+(maxj+shiftup)*Den, i, baseY+(maxj+shiftup)*Den,0,True);
	Val = LineArray(baseX, baseY+(maxj-shiftdn)*Den, i, baseY+(maxj-shiftdn)*Den,0,True);
	Vah1 = LineArray(i, baseY+(maxj+shiftup)*Den, i+BarsInDay[i], baseY+(maxj+shiftup)*Den,0,True);
	Val1 = LineArray(i, baseY+(maxj-shiftdn)*Den, i+BarsInDay[i], baseY+(maxj-shiftdn)*Den,0,True);
	poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);
	poc1 = LineArray(i, baseY+maxj*Den, i+BarsInDay[i], baseY+maxj*Den,0,True);

	if(ViewVALVAH==1)
	{
		Plot(Vah,"",ParamColor("Color_VA",  colorBlueGrey),styleLine|styleNoRescale);
		Plot(Val,"",ParamColor("Color_VA",  colorLightBlue),styleLine|styleNoRescale);
		Plot(poc,"",Colorpoc,styleLine|styleNoRescale);
	}
	if(ViewPREVIOUS==1)
	{
		Plot(Vah1,"",ParamColor("Color_VA",  colorBlueGrey),styleDashed|styleNoRescale);
		Plot(Val1,"",ParamColor("Color_VA",  colorLightBlue),styleDashed|styleNoRescale);
		Plot(poc1,"",Colorpoc,styleDashed|styleNoRescale);
	}


	if(Viewvalues==1)
	{
	PlotText(""+(baseY+maxj*Den),i-5,baseY+maxj*Den,Colorpoc);
	PlotText(""+(baseY+(maxj+shiftup)*Den),i-5,baseY+(maxj+shiftup)*Den,colorWhite);
	PlotText(""+(baseY+(maxj-shiftdn)*Den),i-5,baseY+(maxj-shiftdn)*Den,colorWhite);
	if(ViewTPOCount==1){PlotText(""+(total_g(maxj)-MaxXj)+" / "+(total_g(maxj-shiftdn-1)),basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_Below_VA",  colorGrey40));
	PlotText(""+(total_g(relTodayRange)-total_g(maxj))+" / "+(total_g(relTodayRange)-total_g(maxj+shiftup)),basex,Top[i],ParamColor("Color_Above_VA", colorGrey40));
	}



	}
	
  }
	
	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_g(p), baseY+p*Den);
	  line2 = LineArray(baseX, baseY+(p-1)*Den, baseX+x_g(p-1), baseY+(p-1)*Den);

      if (EnMP2 == "Solid")
	  {
	  PlotOHLC( Line,  Line,  Line2, Line2, "",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA",   colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA",  colorGrey40))) ,styleCloud|styleNoRescale|styleNoLabel);
	  }
	  if (EnMP2 == "Lines") 
	  {
     Plot(line,"",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA",  colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA",   colorGrey40))) , styleLines|styleNoLabel);
     }
 	
   }
	 if(Viewfill==1){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);}

 } 
}


_SECTION_END();
 
Last edited by a moderator:
@RNS .rajendran AFL modified for getting letters and it is for 5.8 and above

try this

Just put 3 under density in parameters
thanks
i am not able to do it properly i guess i am missing something silly :( could you or anyone please modify and post it back here if possible...

Thanks
 

monkeybusiness

Well-Known Member
Code:
_SECTION_BEGIN("MarketProfile");
//------------------------------------------------------------------------------
//
// Formula Name: Market Profile
//
// Use with 5/15min chart
// Originial - From AFL library
// Edited by - Milind / KAKA

//Market Profile 10/12/2009


//------------------------------------------------------------------------------
// This is a modified version of afl date 09/19/2009 as listed above
// Contains a couple changes:
// 1) a more correct (but not complete) calculation of POC.
// 2) attempt to avoid the out of bound runtime error that
// sometimes occurs. See below:
//
// Here are changes to emulate the arrays x[] and total[] so
// that the array size are not limited by Barcount.
// Now one probably should not get the out of bound error even
// if the density or ticksize is smaller. Of course, there will
// be more overhead in calculation.
// johncw 20091010
// Wrapper start
_N(VarKey = NumToStr(GetChartID(), 1.0, False) + "_");
_N(VarTotal = "V_T" + VarKey);
_N(VarX = "V_x" + VarKey);

function L_StaticVarSet(L_name, L_value)
{
local L_name, L_value;
StaticVarSet(L_name + VarKey, L_value);
}

function L_StaticVarGet(L_name)
{
local L_name;
return(StaticVarGet(L_name + VarKey));
}

function x_g(L_idx)
{
local L_idx;
return VarGet(VarX + L_idx);
}

function x_s(L_idx, L_value)
{
local L_idx, L_value;
VarSet(VarX + L_idx, L_value);
}

function total_g(L_idx)
{
local L_idx;
return VarGet(VarTotal+L_idx);
}

function total_s(L_idx, L_value)
{
local L_idx, L_value, L_name;
VarSet(VarTotal+L_idx, L_value);
}
// Wrapper end
//------------------------------------------------------------------------------


PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);


EnMP2= ParamList("MarketProfile","Solid|Lines|Letters");
styleLines = ParamStyle("Style", styleLine, maskAll);

Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly",1);

Den = Param("Density", 1, 0.25, 100, 0.25); // Resolution in terms of $
percent=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",1);

ViewPREVIOUS = ParamToggle("Previous Values", "No|Yes",1);

ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);
Viewfill = ParamToggle("Show VA Fill", "No|Yes",0);
Colorpoc=ParamColor("Color POC", colorYellow);
Colorfill=ParamColor("Color Fill", ColorRGB(20,40,60));


EnIB = ParamToggle("Show Initial Balance", "Yes|No");
IBBars = Param("Initial Balance Bars", 2, 0, 10, 1);

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=="Hourly"){
BarsInDay = BarsSince(Minute() != Ref(Minute(), -1));
Bot = TimeFrameGetPrice("L", in5Minute, 0);
Top = TimeFrameGetPrice("H", in5Minute, 0);
Vol = TimeFrameGetPrice("V", in5Minute, 0);
}

if(Period=="Weekly"){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));
Bot = TimeFrameGetPrice("L", inMonthly, 0);
Top = TimeFrameGetPrice("H", inMonthly, 0);
Vol = TimeFrameGetPrice("V", inMonthly, 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;

i0 = 0;
i1 = 0;
for (i=0; i<BarCount; i++) {
x_s(i, 0); // should not need this
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_s(j, 0);

}
}

range_x=lastVisBar-firstVisBar;
spread = Param("X Space", 80, 1, 200, 1);
tpl = Param("Time Per Letter (mins)", 30, 1, 360, 1);
Intervalmin=Interval()/60;
flt =Param("First Letter (Bars)", 1, 1, 60, 1);
teb=ParamToggle("To Each Bar","No|Yes");
Color=Param("Color Threshold",20,1,50,1);
stopg=0;
stopr=0;
new=0;

Voloumeunit=Vol[i]/LastValue(BarsInDay);


if (EnMP2 == "Letters") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
PlotText(StrExtract(" A , B , C , D , E , F , G , H , I , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z, a , b , c , d , e , f , g , h , i , j , k , L , m , n ,o , p , q , r , s , t , u , v , w , x , y , z ",
IIf(BarsInDay[i]<flt,0,ceil(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x_g(j)*(range_x/spread)), baseY+j*Den,
colorWhite,ColorHSB(10+((ceil(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
x_s(j, x_g(j)+1);

}
}
}

else if (EnMP2 == "Lines" OR EnMP2 == "Solid") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
if(Type=="Price Profile"){x_s(j, x_g(j)+1);}
else if(Type=="Volume Profile"){x_s(j, x_g(j)+round(V[i]/Voloumeunit));}

}
}
}

// Draw Initial Balance after 11am bar is complete
if (BarsInDay[i] == IBBars+1 AND EnIB == 0) {
Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed |styleNoRescale);
Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed |styleNoRescale);
}

// Examine x[j]
if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
maxXj = 0;
maxj = 0;
midrange = int(relTodayRange/2)+1;
for (j=0; j<= relTodayRange; j++) {
if (maxXj < x_g(j)) {
maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
} else if ( MaxXj == x_g(j)) {
if (abs(midrange-j) < abs(midrange-L_StaticVarGet("Maxj"))) {
maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
}
}
}
total_s(0, 0);
for ( n = 1; n <= relTodayRange; n++ ) {
total_s(n, x_g(n) + total_g(n-1));
}

Value_area=(total_g(relTodayRange)*percent)/100;

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

Vah = LineArray(baseX, baseY+(maxj+shiftup)*Den, i, baseY+(maxj+shiftup)*Den,0,True);
Val = LineArray(baseX, baseY+(maxj-shiftdn)*Den, i, baseY+(maxj-shiftdn)*Den,0,True);
Vah1 = LineArray(i, baseY+(maxj+shiftup)*Den, i+BarsInDay[i], baseY+(maxj+shiftup)*Den,0,True);
Val1 = LineArray(i, baseY+(maxj-shiftdn)*Den, i+BarsInDay[i], baseY+(maxj-shiftdn)*Den,0,True);
poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);
poc1 = LineArray(i, baseY+maxj*Den, i+BarsInDay[i], baseY+maxj*Den,0,True);

if(ViewVALVAH==1)
{
Plot(Vah,"",ParamColor("Color_VA", colorBlueGrey),styleLine|styleNoRescale);
Plot(Val,"",ParamColor("Color_VA", colorLightBlue),styleLine|styleNoRescale);
Plot(poc,"",Colorpoc,styleLine|styleNoRescale);
}
if(ViewPREVIOUS==1)
{
Plot(Vah1,"",ParamColor("Color_VA", colorBlueGrey),styleDashed|styleNoRescale);
Plot(Val1,"",ParamColor("Color_VA", colorLightBlue),styleDashed|styleNoRescale);
Plot(poc1,"",Colorpoc,styleDashed|styleNoRescale);
}


if(Viewvalues==1)
{
PlotText(""+(baseY+maxj*Den),i-5,baseY+maxj*Den,Colorpoc);
PlotText(""+(baseY+(maxj+shiftup)*Den),i-5,baseY+(maxj+shiftup)*Den,colorWhite);
PlotText(""+(baseY+(maxj-shiftdn)*Den),i-5,baseY+(maxj-shiftdn)*Den,colorWhite);
if(ViewTPOCount==1){PlotText(""+(total_g(maxj)-MaxXj)+" / "+(total_g(maxj-shiftdn-1)),basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_Below_VA", colorGrey40));
PlotText(""+(total_g(relTodayRange)-total_g(maxj))+" / "+(total_g(relTodayRange)-total_g(maxj+shiftup)),basex,Top[i],ParamColor("Color_Above_VA", colorGrey40));
}



}

}

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_g(p), baseY+p*Den);
line2 = LineArray(baseX, baseY+(p-1)*Den, baseX+x_g(p-1), baseY+(p-1)*Den);

if (EnMP2 == "Solid")
{
PlotOHLC( Line, Line, Line2, Line2, "",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA ", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) ,styleCloud|styleNoRescale|styleNoLabel);
}
if (EnMP2 == "Lines")
{
Plot(line,"",IIf(p>(maxj+shiftup),ParamColor("Colo r_Above_VA", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) , styleLines|styleNoLabel);
}

}
if(Viewfill==1){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);}

}
}


_SECTION_END();
thanks
i am not able to do it properly i guess i am missing something silly :( could you or anyone please modify and post it back here if possible...

Thanks
 
Code:
_SECTION_BEGIN("MarketProfile");
//------------------------------------------------------------------------------
//
// Formula Name: Market Profile
//
// Use with 5/15min chart
// Originial - From AFL library
// Edited by - Milind / KAKA

//Market Profile 10/12/2009


//------------------------------------------------------------------------------
// This is a modified version of afl date 09/19/2009 as listed above
// Contains a couple changes:
// 1) a more correct (but not complete) calculation of POC.
// 2) attempt to avoid the out of bound runtime error that
// sometimes occurs. See below:
//
// Here are changes to emulate the arrays x[] and total[] so
// that the array size are not limited by Barcount.
// Now one probably should not get the out of bound error even
// if the density or ticksize is smaller. Of course, there will
// be more overhead in calculation.
// johncw 20091010
// Wrapper start
_N(VarKey = NumToStr(GetChartID(), 1.0, False) + "_");
_N(VarTotal = "V_T" + VarKey);
_N(VarX = "V_x" + VarKey);

function L_StaticVarSet(L_name, L_value)
{
local L_name, L_value;
StaticVarSet(L_name + VarKey, L_value);
}

function L_StaticVarGet(L_name)
{
local L_name;
return(StaticVarGet(L_name + VarKey));
}

function x_g(L_idx)
{
local L_idx;
return VarGet(VarX + L_idx);
}

function x_s(L_idx, L_value)
{
local L_idx, L_value;
VarSet(VarX + L_idx, L_value);
}

function total_g(L_idx)
{
local L_idx;
return VarGet(VarTotal+L_idx);
}

function total_s(L_idx, L_value)
{
local L_idx, L_value, L_name;
VarSet(VarTotal+L_idx, L_value);
}
// Wrapper end
//------------------------------------------------------------------------------


PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);


EnMP2= ParamList("MarketProfile","Solid|Lines|Letters");
styleLines = ParamStyle("Style", styleLine, maskAll);

Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly",1);

Den = Param("Density", 1, 0.25, 100, 0.25); // Resolution in terms of $
percent=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",1);

ViewPREVIOUS = ParamToggle("Previous Values", "No|Yes",1);

ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);
Viewfill = ParamToggle("Show VA Fill", "No|Yes",0);
Colorpoc=ParamColor("Color POC", colorYellow);
Colorfill=ParamColor("Color Fill", ColorRGB(20,40,60));


EnIB = ParamToggle("Show Initial Balance", "Yes|No");
IBBars = Param("Initial Balance Bars", 2, 0, 10, 1);

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=="Hourly"){
BarsInDay = BarsSince(Minute() != Ref(Minute(), -1));
Bot = TimeFrameGetPrice("L", in5Minute, 0);
Top = TimeFrameGetPrice("H", in5Minute, 0);
Vol = TimeFrameGetPrice("V", in5Minute, 0);
}

if(Period=="Weekly"){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));
Bot = TimeFrameGetPrice("L", inMonthly, 0);
Top = TimeFrameGetPrice("H", inMonthly, 0);
Vol = TimeFrameGetPrice("V", inMonthly, 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;

i0 = 0;
i1 = 0;
for (i=0; i<BarCount; i++) {
x_s(i, 0); // should not need this
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_s(j, 0);

}
}

range_x=lastVisBar-firstVisBar;
spread = Param("X Space", 80, 1, 200, 1);
tpl = Param("Time Per Letter (mins)", 30, 1, 360, 1);
Intervalmin=Interval()/60;
flt =Param("First Letter (Bars)", 1, 1, 60, 1);
teb=ParamToggle("To Each Bar","No|Yes");
Color=Param("Color Threshold",20,1,50,1);
stopg=0;
stopr=0;
new=0;

Voloumeunit=Vol[i]/LastValue(BarsInDay);


if (EnMP2 == "Letters") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
PlotText(StrExtract(" A , B , C , D , E , F , G , H , I , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z, a , b , c , d , e , f , g , h , i , j , k , L , m , n ,o , p , q , r , s , t , u , v , w , x , y , z ",
IIf(BarsInDay[i]<flt,0,ceil(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x_g(j)*(range_x/spread)), baseY+j*Den,
colorWhite,ColorHSB(10+((ceil(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
x_s(j, x_g(j)+1);

}
}
}

else if (EnMP2 == "Lines" OR EnMP2 == "Solid") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
if(Type=="Price Profile"){x_s(j, x_g(j)+1);}
else if(Type=="Volume Profile"){x_s(j, x_g(j)+round(V[i]/Voloumeunit));}

}
}
}

// Draw Initial Balance after 11am bar is complete
if (BarsInDay[i] == IBBars+1 AND EnIB == 0) {
Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed |styleNoRescale);
Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed |styleNoRescale);
}

// Examine x[j]
if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
maxXj = 0;
maxj = 0;
midrange = int(relTodayRange/2)+1;
for (j=0; j<= relTodayRange; j++) {
if (maxXj < x_g(j)) {
maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
} else if ( MaxXj == x_g(j)) {
if (abs(midrange-j) < abs(midrange-L_StaticVarGet("Maxj"))) {
maxXj = x_g(j); maxj = j; L_StaticVarSet("Maxj",j); new=j;
}
}
}
total_s(0, 0);
for ( n = 1; n <= relTodayRange; n++ ) {
total_s(n, x_g(n) + total_g(n-1));
}

Value_area=(total_g(relTodayRange)*percent)/100;

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

Vah = LineArray(baseX, baseY+(maxj+shiftup)*Den, i, baseY+(maxj+shiftup)*Den,0,True);
Val = LineArray(baseX, baseY+(maxj-shiftdn)*Den, i, baseY+(maxj-shiftdn)*Den,0,True);
Vah1 = LineArray(i, baseY+(maxj+shiftup)*Den, i+BarsInDay[i], baseY+(maxj+shiftup)*Den,0,True);
Val1 = LineArray(i, baseY+(maxj-shiftdn)*Den, i+BarsInDay[i], baseY+(maxj-shiftdn)*Den,0,True);
poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);
poc1 = LineArray(i, baseY+maxj*Den, i+BarsInDay[i], baseY+maxj*Den,0,True);

if(ViewVALVAH==1)
{
Plot(Vah,"",ParamColor("Color_VA", colorBlueGrey),styleLine|styleNoRescale);
Plot(Val,"",ParamColor("Color_VA", colorLightBlue),styleLine|styleNoRescale);
Plot(poc,"",Colorpoc,styleLine|styleNoRescale);
}
if(ViewPREVIOUS==1)
{
Plot(Vah1,"",ParamColor("Color_VA", colorBlueGrey),styleDashed|styleNoRescale);
Plot(Val1,"",ParamColor("Color_VA", colorLightBlue),styleDashed|styleNoRescale);
Plot(poc1,"",Colorpoc,styleDashed|styleNoRescale);
}


if(Viewvalues==1)
{
PlotText(""+(baseY+maxj*Den),i-5,baseY+maxj*Den,Colorpoc);
PlotText(""+(baseY+(maxj+shiftup)*Den),i-5,baseY+(maxj+shiftup)*Den,colorWhite);
PlotText(""+(baseY+(maxj-shiftdn)*Den),i-5,baseY+(maxj-shiftdn)*Den,colorWhite);
if(ViewTPOCount==1){PlotText(""+(total_g(maxj)-MaxXj)+" / "+(total_g(maxj-shiftdn-1)),basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_Below_VA", colorGrey40));
PlotText(""+(total_g(relTodayRange)-total_g(maxj))+" / "+(total_g(relTodayRange)-total_g(maxj+shiftup)),basex,Top[i],ParamColor("Color_Above_VA", colorGrey40));
}



}

}

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_g(p), baseY+p*Den);
line2 = LineArray(baseX, baseY+(p-1)*Den, baseX+x_g(p-1), baseY+(p-1)*Den);

if (EnMP2 == "Solid")
{
PlotOHLC( Line, Line, Line2, Line2, "",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA ", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) ,styleCloud|styleNoRescale|styleNoLabel);
}
if (EnMP2 == "Lines")
{
Plot(line,"",IIf(p>(maxj+shiftup),ParamColor("Colo r_Above_VA", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) , styleLines|styleNoLabel);
}

}
if(Viewfill==1){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);}

}
}


_SECTION_END();
thanks now its working...:thumb:
 

manish9300

Well-Known Member
Xrayji,
I have a question regarding 80% rule.Rule is applicable when,
1.When open is inside VA (This is based on open).
2.When two consecutive 30 min candle close inside VA (This is applicable at all time).

My question is regarding 1.Can we apply the rule with first candle close itself or should we wait for 2 candle close (2 IB candles closing inside VA)?(second case would mean
1 is irrelavant)
 
Last edited:

XRAY27

Well-Known Member
Xrayji,
I have a question regarding 80% rule.Rule is applicable when,
1.When open is inside VA (This is based on open).
2.When two consecutive 30 min candle close inside VA (This is applicable at all time).

My question is regarding 1.Can we apply the rule with first candle close itself or should we wait for 2 candle close (2 IB candles closing inside VA)?(second case would mean
1 is irrelavant)
First of all 80 % rule is based on IB or first hour !!! if you want it to 30 mins then just back test it and form your own conclusion !!!

i'm just following only on 30 mins as per theory !!!
 
Status
Not open for further replies.

Similar threads