Simple Coding Help - No Promise.

josh1

Well-Known Member
Dear Josh, I tried ur afl as per ur modified demand/supply point, but error with warning.
so pls post working afl

thanks & regards
It works. Change bar period to 1, 3, 5, 15,60, daily. Once chart appears, you can change to which ever period you want.
 

MSN1979

Well-Known Member
Need AFL for comparing 2 subsequent candles on 5 min chart

If 2nd Candle High is > then opening candle high
then plot a circle on top of 2nd candle high


If 2nd candle Low < opening candle Low
then plot a circle on LOW of 2nd Candle ( Bottom)

If both conditions given above fail
Do nothing and Wait

Thanx in advance
 
Need AFL for comparing 2 subsequent candles on 5 min chart

If 2nd Candle High is > then opening candle high
then plot a circle on top of 2nd candle high


If 2nd candle Low < opening candle Low
then plot a circle on LOW of 2nd Candle ( Bottom)

If both conditions given above fail
Do nothing and Wait

Thanx in advance
Code:
PlotShapes(IIf(H>Ref(H,-1), shapeHollowSmallCircle,shapeNone),colorBlueGrey,0,H,12);
Seems you are learning to code, so you should be able to do the other one on your own

Best

Happy :)
 

MSN1979

Well-Known Member
Code:
PlotShapes(IIf(H>Ref(H,-1), shapeHollowSmallCircle,shapeNone),colorBlueGrey,0,H,12);
Seems you are learning to code, so you should be able to do the other one on your own

Best

Happy :)
Yes Bro learning to code. thanx will try and let you know.
 

john302928

Well-Known Member
Could anyone please help me solve the error in the below code? Thanks in advance

Code is for Market profile and it is taken from the below link

https://www.stockmaniacs.net/downloads/afl/market-profile.afl

I didnt make any changes to the code in the above link.Below is the error
1543567588881.png



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

//Market Profile 9/19/2009

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

SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartBkGradientFill(ParamColor("Upper Chart",1),ParamColor("Lower Chart",23));



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

ViewPOC = ParamToggle("Show POC", "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;

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

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

i1 = BarCount-1;
for (i=i0; i<=i1; i++) {
if (BarsInDay == 0) {
baseX = i;
baseY = floor(Bot/Den)*Den;
maxY = floor(Top/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/LastValue(BarsInDay);


if (EnMP2 == "Letters") {
for (j=0; j<= relTodayRange; j++) {
if (L <= baseY+j*Den AND H >= 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<flt,0,ceil(BarsInDay/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay,x[j]*(range_x/spread)), baseY+j*Den,
colorWhite,ColorHSB(10+((ceil(BarsInDay/(tpl/Intervalmin)))*Color),160,140));
x[j]++;

}
}
}

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

}
}
}

// Draw Initial Balance after 11am bar is complete
if (BarsInDay == 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[j]) {
maxXj = x[j]; maxj = j; StaticVarSet("Maxj",j); new=j;
} else if ( MaxXj == x[j]) {
if (abs(midrange-j) < abs(midrange-StaticVarGet("Maxj"))) {
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]-MaxXj)-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]-MaxXj)>=Value_area){shiftup=a; shiftdn=maxj-1; break;}
}
else if(Maxj+a>relTodayRange )
{
if(MaxXj+total[relTodayRange]-total[Maxj]+(total[maxj]-MaxXj)-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", colorBlueGrey),styleLine|styleNoRescale);
Plot(Val,"",ParamColor("Color_VA", colorLightBlue),styleLine|styleNoRescale);}
if(ViewPOC==1){Plot(poc,"",Colorpoc,styleLine|styleNoRescale);}
if(Viewvalues==1){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]-MaxXj)+" / "+(total[maxj-shiftdn-1]),basex,bot-(Top-bot)*0.05,ParamColor("Color_Below_VA", colorGrey40));
PlotText(""+(total[relTodayRange]-total[maxj])+" / "+(total[relTodayRange]-total[maxj+shiftup]),basex,Top,ParamColor("Color_Above_VA", colorGrey40));
}




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_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:

travi

Well-Known Member
Could anyone please help me solve the error in the below code? Thanks in advance
You should
1. mention link or source of the code or where you got it from.
2. mention changes made by you if any.
3. post snap shots of what error you are getting

Apart from that, you need to provide all relevant info that may be useful to someone.
Time is precious for everyone.
 

john302928

Well-Known Member
You should
1. mention link or source of the code or where you got it from.
2. mention changes made by you if any.
3. post snap shots of what error you are getting

Apart from that, you need to provide all relevant info that may be useful to someone.
Time is precious for everyone.
travi, I have just edited my previous message with the details you had mentioned. apologize for inconvenience
 

travi

Well-Known Member
travi, I have just edited my previous message with the details you had mentioned. apologize for inconvenience
I think you don't have enough data, that's why you have array subscript issue.
This kind of error isn't related to the code itself like syntax errors etc
 

john302928

Well-Known Member
I didnt even drag it on to the chart. I checked for errors in the coding area. there itself it showed that error. and moreover I have 15 days of intraday data
 

travi

Well-Known Member
I didnt even drag it on to the chart. I checked for errors in the coding area. there itself it showed that error. and moreover I have 15 days of intraday data
Chart and Debugger in Editor are different.
That is why in my first post I told you to provide as much info as you can. so in this case, you should say i'm checking syntax in Editor.

If you want proof :D goto Tools > Preferences > Debugger

You can see the base interval and number of bars are separately defined. (Limit bar count and other settings)

Use the formula in the chart.
 

Similar threads