Simple Coding Help - No Promise.

KelvinHand

Well-Known Member
Kindly check this error in MP afl ...
Your 1st script problem is here.

PHP:
//--  Solve Out of Range issue
  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) 
  {
    maxXj = 0;
    maxj = 1;  //was 0

   .....
  }

//--  Solve too much plot()/plotohlc
if(Period=="Hourly")
{
BarsInDay = BarsSince(Hour() != Ref(Hour(), -1));
Bot = TimeFrameGetPrice("L", inHourly, 0);
Top = TimeFrameGetPrice("H", inHourly, 0);
Vol = TimeFrameGetPrice("V", inHourly, 0);
}

Your 2nd script problem, TRACE the call to Plot()/PlotOHLC() is 506 times. you had to reduce the call.
 
Last edited:

cellclinic

Well-Known Member
Thanks Kelvin bro for your prompt help :)

But frankly speaking i found my self unable to get benefited with your help due to my excellent knowledge towards afl coding :)

I tried 1st solution by pasting it in the end of afl .... but still the same issues along with 2 new in the newly added code .

For 2nd solution i felt unable to find out plot OHLC or call 506 .

:)
Your 1st script problem is here.

PHP:
//--  Solve Out of Range issue
  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) 
  {
    maxXj = 0;
    maxj = 1;  //was 0

   .....
  }

//--  Solve too much plot()/plotohlc
if(Period=="Hourly")
{
BarsInDay = BarsSince(Hour() != Ref(Hour(), -1));
Bot = TimeFrameGetPrice("L", inHourly, 0);
Top = TimeFrameGetPrice("H", inHourly, 0);
Vol = TimeFrameGetPrice("V", inHourly, 0);
}

Your 2nd script problem, TRACE the call to Plot()/PlotOHLC() is 506 times. you had to reduce the call.
 

amitrandive

Well-Known Member
Does this look like this ?

Do not simply copy paste,you just pasted Yesterday Low in all the lines.So you are just getting only one line plotted.

Code:
_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Fibo");
FibCol= colorBlue ;
FibExt=colorRed;
YH=TimeFrameGetPrice("H", inDaily, -1);
YL=TimeFrameGetPrice("L", inDaily, -1);

Yo=TimeFrameGetPrice("O", inDaily, -1);
Yc=TimeFrameGetPrice("C", inDaily, -1);

DD=Prec(C-Yc,2);
xx=Prec((DD/Yc)*100,2);


numbars = LastValue(Cum(Status("barvisible")));
hts = -120;
Today = LastValue(Day());
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

Line0=YL;
Line100=YH;

Line1 = Line0 + abs(Line100-Line0)*0.236; 
Line2 = Line0 + abs(Line100-Line0)*0.382; 
Line3 = Line0 + abs(Line100-Line0)*0.5; 
Line4 = Line0 + abs(Line100-Line0)*0.618; 
Line5= Line0 + abs(Line100-Line0)*0.786; 
Line6= Line0 + abs(Line100-Line0)*1.236; 
Line7= Line0 + abs(Line100-Line0)*1.382; 
Line8= Line0 + abs(Line100-Line0)*1.5;
Line9= Line0 + abs(Line100-Line0)*1.618;
Line10= Line0 + abs(Line100-Line0)*1.786;
Line11= Line0 + abs(Line100-Line0)*2;
Plot(YL,"0%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line1,"23.6%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line2,"38.2%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line3,"50%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line4,"61.8%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line5,"78.6%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line6,"23.6 %",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line7,"38.2%",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line8,"50%",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line9,"61.8%",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line10,"78.6 %",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(Line11,"100%",FibExt,styleDashed |styleNoRescale|styleNoTitle);
Plot(YH,"100%",FibCol,styleDashed |styleNoRescale|styleNoTitle);

PlotText("0%= " + WriteVal(YL,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (YL,1) , FibCol);
PlotText("23.6%= " + WriteVal(Line1,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line1,1) , FibCol);
PlotText("38.2%=" + WriteVal(Line2,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line2,1) , FibCol);
PlotText("50%= " + WriteVal(Line3,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line3,1) , FibCol);
PlotText("61.8%= " + WriteVal(Line4,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line4,1) , FibCol);
PlotText("78.6%= " + WriteVal(Line5,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line5,1) , FibCol);
PlotText("100%= " + WriteVal(YH,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (YH,1) , FibCol);
PlotText("23.6%= " + WriteVal(Line6,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line6,1) , FibExt);
PlotText("38.2%= " + WriteVal(Line7,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line7,1) , FibExt);
PlotText("50%= " + WriteVal(Line8,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line8,1) , FibExt);
PlotText("61.8%= " + WriteVal(Line9,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line9,1) , FibExt);
PlotText("78.6%= " + WriteVal(Line10,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line10,1) , FibExt);
PlotText("100%= " + WriteVal(Line11,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line11,1) , FibExt);
_SECTION_END();
 
Last edited:

Nehal_s143

Well-Known Member
Nehal ji can u post this hourly suport and ressistance code
sure with pleasure, Happy sir, Pratap Sir, MasterMind Sir, Amit Sir and many more good person are helping here with open heart :thumb: :clapping: :clap:, no words to express Thanks to all of them, word thanks itself seems smaller for there kind help

Afl Code :


Code:
_SECTION_BEGIN("PriceCandle");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorPink ), styleNoTitle | styleCandle|styleNoLabel ); 
_SECTION_END();


_SECTION_BEGIN("Hourly Levels");
HH= TimeFrameGetPrice( "H", inHourly, -1) ;
HL= TimeFrameGetPrice( "L", inHourly, -1) ;
HC= TimeFrameGetPrice( "C", inHourly, -1) ;



PP = (HH + HL + HC)/3;
R1  =  (2*PP) - HL;
S1  =  (2*PP) - HH;
R2  =  PP + (HH - HL);
S2  =  PP - (HH - HL);
R3  =  R1 + (HH - HL);
S3  =  S1 - (HH - HL);

Plot (r3,"r3",colorGreen,1);
Plot (r2,"r2",colorGreen,1);
Plot (r1,"r1",colorGreen,1);
Plot (pp,"Pivot",colorYellow,1);
Plot (s1,"s1",colorRed,1);
Plot (s2,"s2",colorRed,1);
Plot (s3,"s3",colorRed,1);


_SECTION_END();
 

KelvinHand

Well-Known Member
Thanks Kelvin bro for your prompt help :)

But frankly speaking i found my self unable to get benefited with your help due to my excellent knowledge towards afl coding :)

I tried 1st solution by pasting it in the end of afl .... but still the same issues along with 2 new in the newly added code .

For 2nd solution i felt unable to find out plot OHLC or call 506 .

:)
1st code suppose required you to search to the location to modified it.
Due to your excellent knowledge towards afl coding, here is :

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

//Market Profile 9/12/2009
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

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);
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(Hour() != Ref(Hour(), -1));
	Bot = TimeFrameGetPrice("L", inHourly, 0);
	Top = TimeFrameGetPrice("H", inHourly, 0);
	Vol = TimeFrameGetPrice("V", inHourly, 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;

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

i0 = 0;
for (i=BarCount-1; i>0; i--) 
{
  x_s(i, 0); // should not need this
  if (BarsInDay[i] ==0 AND i<firstVisBar)
  { 
    i0 = i;
    break; 
  }  
}

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", 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[j]*(range_x/spread)), baseY+j*Den, 
		colorWhite,ColorHSB(10+((ceil(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
       x[j]++;

      }
    }
  }
  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+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 = 1;  //bug
    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);
	
	if(ViewVALVAH==1)
	{
		Plot(Vah,"",ParamColor("Color_VA",  colorLightBlue),styleLine|styleNoRescale);
		Plot(Val,"",ParamColor("Color_VA",  colorLightBlue),styleLine|styleNoRescale);}
		if(ViewPOC==1)
			Plot(poc,"",Colorpoc,styleLine|styleNoRescale);
			
		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-1],basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_VAL", colorLavender));
			PlotText(""+(total[relTodayRange]-total[maxj]),basex,Top[i],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();

2nd Code is to _TRACE("How many Plot()/PlotOHLC()") into the logwindow.
PHP:
_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);

nPlot=0;
nPlotOHLC=0;
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
//------------------------------------------------------------------------------

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

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


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",0);

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(Hour() != Ref(Hour(), -1));
	Bot = TimeFrameGetPrice("L", inHourly, 0);
	Top = TimeFrameGetPrice("H", inHourly, 0);
	Vol = TimeFrameGetPrice("V", inHourly, 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");


_TRACE("firstVisBar = " + NumToStr(firstVisBar, 1.0)+  ", lastVisBar = " + NumToStr(lastVisBar, 1.0) );
D=.0005;
//total=0;
totaldn=0;
totalup=0;
shiftup=0;
shiftdn=0;
startr=0;

i0 = 0;
i0 = 0;
for (i=BarCount-1; i>0; i--) 
{
  x_s(i, 0); // should not need this
  if (BarsInDay[i] ==0 AND i<firstVisBar)
  { 
    i0 = i;
    break; 
  }  
}

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) {
    LX=Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale); nPlot++;
    LY=Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
    Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale); nPlot++; 
    PlotOHLC(LX,LX,LY,LY,"",colorCustom13,styleCloud,styleNoLabel);     nPlotOHLC++;

  }

  // 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);


	clrVAH=ParamColor("Color_VA",  colorBlueGrey);
	clrVAL=ParamColor("Color_VA",  colorLightBlue);
	
	if(ViewVALVAH==1)
	{
		Plot(Vah,"",clrVah,styleLine|styleNoRescale);	nPlot++;
		Plot(Val,"",clrVal,styleLine|styleNoRescale);   nPlot++;
		Plot(poc,"",Colorpoc,styleLine|styleNoRescale); nPlot++;
		
		_TRACE("ViewVALVAH: nPlot = "+NumToStr(nPlot, 0)+ ", nPlotOHLC = " + NumToStr(nPlotOHLC, 0)+ ", So Total Plots = "+ NumToStr(nPlot+nPlotOHLC, 0));
	}
	if(ViewPREVIOUS==1)
	{
		Plot(Vah1,"",clrVah,styleDashed|styleNoRescale);  nPlot++;
		Plot(Val1,"",clrVal,styleDashed|styleNoRescale);  nPlot++;
		Plot(poc1,"",Colorpoc,styleDashed|styleNoRescale); nPlot++;
		_TRACE("ViewPREVIOUS: nPlot = "+NumToStr(nPlot, 0)+ "& nPlotOHLC = " + NumToStr(nPlotOHLC, 0)+ ", So Total Plots = "+ NumToStr(nPlot+nPlotOHLC, 0));
	}

    	

	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);   nPlotOHLC++;
		
	  
	  }
	  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); nPlot++;
     
     }
 	
   }
	 if(Viewfill==1)
	 {
	  PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);   nPlotOHLC++;
	  }

 } 
}


_SECTION_END();

_SECTION_BEGIN("VOLUME_Hight of Volume Bars Control");


PlotVOL = ParamToggle( "plot Volume?","No| Yes",0);

VolColor = (C>O OR (C==O AND
(H-C)<=(C-L) ))*ParamColor( "VUpColor" ,colorBlueGrey) +

(C<O OR (C==O AND
(H-C)>(C-L)) )*ParamColor( "VDnColor" ,colorPink) ;

VolScale = Param("1/Vol. Height (TimeBar chart)(fraction of window) 5=1/5=20%",10, 2, 100, 1.0) ; // Timebars

if (PlotVOL >0) 

{

Vheight = VolScale;

Plot(Prec(Volume ,0),"V",VolColor,
styleNoTitle| styleOwnScale| styleNoLabel| styleThick| ParamStyle( "VStyle", styleHistogram,maskHistogram| styleNoLabel) ,Vheight ); }
//Plot(MA(Volume,50),"",colorLightBlue,styleLine);
_SECTION_END();
 
Last edited:

toocool

Well-Known Member
And then people start to wonder why AB reacts slow. Exactly because of codes similar to your one or worse. Next time please also use arrays within loop. Thank you!


EDIT:

much better readable/maintainable and faster

Code:
_SECTION_BEGIN("Floor Pivots");
// modified, optimized, cleaned by trash

dd = Day();
Today = LastValue( dd );
lastday = Today == dd;
    
function lastdayarray( array )
{    
    return IIf( lastday, array, Null );
}

SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );

FibCol = ParamColor( "Fib Line Color", colorOrange );//

SetBarFillColor( IIf( C > O, colorWhite , IIf( C < O, colorCustom4 , colorYellow ) ) );
Plot( C, "Close", IIf( C > Ref( C, -1 ), colorWhite , IIf( C < Ref( C, -1 ), colorSkyblue , colorYellow ) ), 64 );


DayH = TimeFrameGetPrice( "H", inDaily, -1 );
DayL = TimeFrameGetPrice( "L", inDaily, -1 );

DayO = TimeFrameGetPrice( "O", inDaily, -1 );
DayC = TimeFrameGetPrice( "C", inDaily, -1 );

// some unknown leftovers, not used in this code
//DD = C - DayC;
//xx = Prec( ( DD / DayC ) * 100, 2 );

defaultcol = EncodeColor( 55 );
Title = StrFormat( defaultcol + Name() + "     " +
                   defaultcol + Date() + "      " + EncodeColor( 5 ) + "{{INTERVAL}}" +
                   defaultcol + " Open = " + EncodeColor( 52 ) + "%g" +
                   defaultcol + " High = " + EncodeColor( 5 ) + "%g" +
                   defaultcol + " Low = " + EncodeColor( 33 ) + "%g" +
                   defaultcol + " Close = " + EncodeColor( 52 ) + "%g", O, H, L, C );
                   

RANGE = ( DayH - DayL );
PP = ( DayL + DayH + DayC ) / 3;
//PPI = LastValue ( PP, 1 ); // Pivot, unused variable
R1 = ( 2 * PP ) - DayL  ;
S1 = ( 2 * PP ) - DayH;
R2 = PP + RANGE;
S2 = PP - RANGE;
R3 = R1 + RANGE;
S3 = S1 - RANGE;
R4 = R3 + ( R2 - R1 );
S4 = S3 - ( S1 - S2 );

BC = ( DayH + DayL ) / 2;
TC = ( PP - BC ) + PP;


style = styleDots | styleNoRescale | styleNoTitle;

Plot( lastdayarray( PP ), "PP", colorGold, style );
Plot( lastdayarray( R1 ), "R1", colorOrange, style );
Plot( lastdayarray( S1 ), "S1", colorPaleGreen, style );
Plot( lastdayarray( R2 ), "R2", colorOrange, style );
Plot( lastdayarray( S2 ), "S2", colorPaleGreen, style );
Plot( lastdayarray( R3 ), "R3", colorOrange, style );
Plot( lastdayarray( S3 ), "S3", colorPaleGreen, style );
Plot( lastdayarray( R4 ), "R4", colorOrange, style );
Plot( lastdayarray( S4 ), "S4", colorPaleGreen, style );

Plot( lastdayarray( TC ), "TC", colorWhite, style );
Plot( lastdayarray( BC ), "BC", colorWhite, style );


numbars = LastValue( Cum( Status( "barvisible" ) ) );
hts = -33.5;
xtext = LastValue( BarIndex() ) - ( numbars / hts );

PlotText( StrFormat( "Pivot = %g", pp ), xtext, LastValue ( pp, 1 ), colorGold );
PlotText( StrFormat( "R1 = %g", R1 ), xtext, LastValue ( R1, 1 ), colorOrange );
PlotText( StrFormat( "S1 = %g", S1 ), xtext, LastValue ( S1, 1 ), colorPaleGreen );
PlotText( StrFormat( "R2 = %g", R2 ), xtext, LastValue ( R2, 1 ), colorOrange );
PlotText( StrFormat( "S2 = %g", S2 ), xtext, LastValue ( S2, 1 ), colorPaleGreen );
PlotText( StrFormat( "R3 = %g", R3 ), xtext, LastValue ( R3, 1 ), colorOrange );
PlotText( StrFormat( "S3 = %g", S3 ), xtext, LastValue ( S3, 1 ), colorPaleGreen );
PlotText( StrFormat( "R4 = %g", R4 ), xtext, LastValue ( R4, 1 ), colorOrange );
PlotText( StrFormat( "S4 = %g", S4 ), xtext, LastValue ( S4, 1 ), colorPaleGreen );

PlotText( StrFormat( "TC = %g", TC ), xtext, LastValue ( TC, 1 ), colorWhite );
PlotText( StrFormat( "BC = %g", BC ), xtext, LastValue ( BC, 1 ), colorWhite );
_SECTION_END();
hey fxarun /amitrandive or any other experts

can you make this AFL atleast show 2 consecutive days of pivots? it would be even better if you could modify it in 2 AFL ............1 showing 2 days pivots and 1 showing continuous pivots for all time frames and add weekly monthly options in both of new AFL too :) :thumb:
 
Hello guys,

I need help for my buy-sell signals..

Code is so simple..

upper=HHV(C,n);
lower=LLV(C,n1);
EMA5=EMA(C,5);
Buy= C > Ref(upper,-1) ;
Sell= C < Ref( lower, -1);

but i want to add 2 more conditions for buy-sell signals..
for instance like that
Buy= C > Ref(upper,-1) OR ( If Close is higher than previous sell signal) ;
Sell = C < Ref( lower, -1); OR ( If Close is lower than previous buy signal) ;

How can i add these underlined conditions in buy/sell signals..?

thanks in advance..
 

Similar threads