Common and continous vwap

hi everyone
i am trying to make an exploration where i display last 30 days vwap

the purpose is to identify almost common (within half percent down and up of previous days vwap)
and continous days vwaps
lets say
day 1 atp is 100
day 2 atp is 100.40
day 3 atp is 102
day 4 atp is 100.60

in this example first 2 days is common within half percent of each other

so i shall color those cells in exploration

but the formula which i am writing does not color the first day , but
colors only next days

its difficult for me to put the logic in code
can someone help me here

  1. to color the first cell also
  2. to color different sets of common and continous vwap days in the last 30 days

need to analyse in this way because the more the common days , more is the stronger trend which emerges after that , in any direction

regards
nitin bagadia

image

code for afl is as below

//define bars till today
{

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
lk1 = 1 + BarsSince( Ref(Day(), -1) != Ref(Day(), -2)) - bars_so_far_today;
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
ATP = Sum (C * V, Bars_so_far_today ) / TodayVolume;
Plot (ATP,"ATP",colorblue, styleThick);

dn = DateNum();
LastBarOfDay = dn != Ref( dn, 1 );
}

//atp columns
{
for( i = 1; i < 15; i++ )
{
VarSet("ATP"+i, ValueWhen( LastBarOfDay,ATP,i));
colorATP1=IIf((VarGet("ATP"+i))>ValueWhen( LastBarOfDay,ATP,i+1),colorGreen,colorRed);

 }

ATP=ATP;

ATP1=VarGet("ATP"+1);
ATP2=VarGet("ATP"+2);
ATP3=VarGet("ATP"+3);
ATP4=VarGet("ATP"+4);
ATP5=VarGet("ATP"+5);
ATP6=VarGet("ATP"+6);
ATP7=VarGet("ATP"+7);
ATP8=VarGet("ATP"+8);
ATP9=VarGet("ATP"+9);
ATP10=VarGet("ATP"+10);
ATP11=VarGet("ATP"+11);
ATP12=VarGet("ATP"+12);
ATP13=VarGet("ATP"+13);
ATP14=VarGet("ATP"+14);
ATP15=VarGet("ATP"+15);

ATPbuyREVERSAL= ATP>ATP1 AND ATP1<ATP2 AND ATP2<ATP3;
ATPsellREVERSAL= ATPATP2 AND ATP2>ATP3;

ATPRISE1 = ATP>ATP1 AND ATP1<ATP2;
ATPRISE2 = ATP>ATP1 AND ATP1 > ATP2;
ATPRISE3 = ATPRISE2 AND ATP2 > ATP3;
ATPRISE4 = ATPRISE3 AND ATP3 > ATP4;
ATPRISE5 = ATPRISE4 AND ATP4 > ATP5;
ATPRISE6 = ATPRISE5 AND ATP5 > ATP6;
ATPRISE7 = ATPRISE6 AND ATP6 > ATP7;
ATPRISE8 = ATPRISE7 AND ATP7 > ATP8;
ATPRISE9 = ATPRISE8 AND ATP8 > ATP9;
ATPRISE10 = ATPRISE9 AND ATP9 > ATP10;
ATPRISE11 = ATPRISE10 AND ATP10 > ATP11;
ATPRISE12 = ATPRISE11 AND ATP11 > ATP12;
ATPRISE13 = ATPRISE12 AND ATP12 > ATP13;
ATPRISE14 = ATPRISE13 AND ATP13 > ATP14;
ATPRISE15 = ATPRISE14 AND ATP14 > ATP15;

ATPFALL1 = ATP ATP2;
ATPFALLL1= ATP<ATP1 AND ATP1< ATP2;
ATPFALL2 = ATPFALLL1 AND ATP2 < ATP3;
ATPFALL3 = ATPFALL2 AND ATP3 < ATP4;
ATPFALL4 = ATPFALL3 AND ATP4 < ATP5;
ATPFALL5 = ATPFALL4 AND ATP5 < ATP6;
ATPFALL6 = ATPFALL5 AND ATP6 < ATP7;
ATPFALL7 = ATPFALL6 AND ATP7 < ATP8;
ATPFALL8 = ATPFALL7 AND ATP8 < ATP9;
ATPFALL9 = ATPFALL8 AND ATP9 < ATP10;
ATPFALL10 = ATPFALL9 AND ATP10 < ATP11;
ATPFALL11 = ATPFALL10 AND ATP11 < ATP12;
ATPFALL12 = ATPFALL11 AND ATP12 < ATP13;
ATPFALL13 = ATPFALL12 AND ATP13 < ATP14;
ATPFALL14 = ATPFALL13 AND ATP14 < ATP15;

ATPreversaltext = WriteIf(ATPbuyreversal,"BUY_REV",WriteIf(ATPsellreversal,"SELL_REV",
writeif(ATPRISE12,"ATPRISE12",writeif(ATPRISE11,"ATPRISE11",
writeif(ATPRISE10,"ATPRISE10",writeif(ATPRISE9,"ATPRISE9",writeif(ATPRISE8,"ATPRISE8",
writeif(ATPRISE7,"ATPRISE7",writeif(ATPRISE6,"ATPRISE6",writeif(ATPRISE5,"ATPRISE5",
writeif(ATPRISE4,"ATPRISE4",writeif(ATPRISE3,"ATPRISE3",writeif(ATPRISE2,"ATPRISE2",
writeif(ATPRISE1,"ATPRISE1",writeif(ATPFALL12,"ATPFALL12",writeif(ATPFALL11,"ATPFALL11",
writeif(ATPFALL10,"ATPFALL10",writeif(ATPFALL9,"ATPFALL9",writeif(ATPFALL8,"ATPFALL8",
writeif(ATPFALL7,"ATPFALL7",writeif(ATPFALL6,"ATPFALL6",writeif(ATPFALL5,"ATPFALL5",
writeif(ATPFALL4,"ATPFALL4",writeif(ATPFALL3,"ATPFALL3",writeif(ATPFALLL1,"ATPFALL2",
writeif(ATPFALL1,"ATPFALL1",""))))))))))))))))))))))))));

//////////////////////////////
colorATPr=
IIf(ATPbuyreversal,colorPaleTurquoise,
IIf(ATPsellreversal,colorRose,
IIf(ATPRISE12,colorDarkGreen,
IIf(ATPRISE11,colorGreen,
IIf(ATPRISE10,colorLime,
IIf(ATPRISE9,colorSeaGreen,
IIf(ATPRISE8,colorBrightGreen,
IIf(ATPRISE7,colorPaleGreen,
IIf(ATPRISE6,colorTurquoise,
IIf(ATPRISE5,colorAqua,
IIf(ATPRISE4,colorPaleTurquoise,
IIf(ATPRISE3,colorSkyblue,
IIf(ATPRISE2,colorLightOrange,
IIf(ATPRISE1,colorLightYellow,
IIf(ATPfall12,colorRED,
IIf(ATPfall11,colorViolet,
IIf(ATPfall10,colorIndigo,
IIf(ATPfall9,colorBrown,
IIf(ATPfall8,colorOrange,
IIf(ATPfall7,colorGold,
IIf(ATPfall6,colorTan,
IIf(ATPfall5,colorPlum,
IIf(ATPfall4,colorPaleBlue,
IIf(ATPfall3,colorPink,
IIf(ATPFALLL1,colorOrange,
IIf(ATPfall1,colorLavender,colorWhite))))))))))))))))))))))))));

}

//set columns
{
SetOption("NoDefaultColumns", True);
AddTextColumn( name(), "NAME", 1, textColor=colorBlack,bkgndColor=colorWhite,120);
AddColumn( DateTime(), "DATE", formatDatetime, colorBlack, colorwhite);
AddTextColumn(ATPreversaltext,"ATP STATUS",1,colorDarkGrey,colorATPr,80);
///////////////////////////////
colorATP=IIf(ATP>ValueWhen( LastBarOfDay,ATP,1),colorGreen,colorRed);
AddColumn( c, "CLOSE",1.1,colorblack,colorwhite );
rocrate=ValueWhen(lastbarofday,C,-1);
roce = -(rocrate-c)*100/rocrate;
roccolor=IIf(roce>0,colorgreen,colorRed);
AddColumn( roce, "%CLOSE",1.2,roccolor,colorwhite );
ATPchange = -(ATP-c)*100/ATP;
ATPcolor=IIf(ATPchange>0,colorgreen,colorRed);
AddColumn( todayvolume, "VOLUME",1,colorblack,colorwhite,80 );
TV1=ValueWhen( LastBarOfDay,TODAYVOLUME,1);
TV=TODAYVOLUME;
TVCHNGP=-((TV1-TV)*100)/TV1;
TVcolor=IIf(TVCHNGP>0,colorgreen,colorRed);
AddColumn(TVCHNGP, "%VOLUME",1,TVCOLOR,colorwhite,80 );

}

{//atp columns

value = todayvolume*C ;

{for( i =0; i < 30; i++ )
{
VarSet("ATP"+i, ValueWhen( LastBarOfDay,ATP,i));
VarSet("value"+i, ValueWhen( LastBarOfDay,value,i));

 }
 }
 

VarSet("ATP0",ATP);
ATTP1=VarGet("ATP1");

{colorATP1=

IIf(
(((ATP<ATTP11.005) AND (ATP>ATTP10.995)))
OR((VarGet("ATP"+i))<(ValueWhen( LastBarOfDay,ATP,i+1)*1.005)AND (VarGet("ATP"+i))>(ValueWhen( LastBarOfDay,ATP,i+1)*0.995)),colorGreen,colorwhite);

AddColumn( ATP0, "ATP0",1.2,colorBlack,colorATP1,80 );
}

{for( i = 1; i < 30; i++ )
{

colorATP1=
   
IIf(
(VarGet("ATP"+i))<(ValueWhen( LastBarOfDay,ATP,i+1)*1.005)AND (VarGet("ATP"+i))>(ValueWhen( LastBarOfDay,ATP,i+1)*0.995)
OR
(((VarGet("ATP"+i))<(ValueWhen( LastBarOfDay,ATP,i-1)*1.005)AND (VarGet("ATP"+i))>(ValueWhen( LastBarOfDay,ATP,i-1)*0.995))
AND
(((ATP<ATTP1*1.005) AND (ATP>ATTP1*0.995))))
,colorGreen,colorWhite);


AddColumn( VarGet("ATP"+i), "ATP"+i  ,1.2,colorblack,coloratp1,80);

 }

}
}

Filter=1;

There are some errors check the code again.

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.