Simple Coding Help - No Promise.

Hello mastermind007 Sir
I am not getting the correct results but i think this might be helpful
Code:
nd = (Day() != Ref(Day(), -1));
tn = TimeNum();
CDR = IIf(ND == 0, Sum(V, 1 + BarsSince(ND)), V);
PDR1 = 0;
bi = BarIndex();
IIf(ValueWhen(bi>375,tn)==ValueWhen(bi<375,tn), pdr1 = ValueWhen(bi<375,cdr),0);
PDR2 = ValueWhen(tn == TimeNum(), CDR, 2);
AddColumn(CDR, "CDR");
AddColumn(PDR1, "PDR1");
AddColumn(PDR2, "PDR2");
Filter = 1;
:)
Romeo

Thank you very much for attempting.
logic of PDR1 that I posted is 100% correct. PDR2 logic is meant to be its equivalent for comparison.

Also, if-comparision of loop variable with 375 is not actually part of core logic but is needed to avoid amibroker errors. 375 happens to be time span of NSE trading session in minutes.

Logic that is needed is to obtain running volume of previous trading at the same time as now. So at 10:00 AM, it should show current running volume of today and running volume at 10:00 as of yesterday.

I have come up with this to do approximate jump into the correct previous day candle but better solution is still welcome
Code:
cbi = ValueWhen(nd, bi);
pbi = ValueWhen(nd, bi, 2);
PDR2 = Ref(CDR, pbi - cbi);
This logic will fail when there are gaps in data.
 
Last edited:
Hello all, i'm new to amibroker,
i'm looking for a simple indicator which plot close of last 30 mins candle on a 5 min chart till next 30 mins.
Something similar to Tradingviews plot(security(tickerid,"30", close). the problem in TV is that it repaint the close of the last 6 candles in 5 mins tf.
 
Hello everyone / @Happy_Singh ,

Need some help in getting the output of an afl in explorer. Right now i am getting the attached image output from an afl. Basically i wanted to remove empty cells in output . So basically it should give only that output where there is a match for pattern column. Kindly help. I have copied the afl as well below.

Kindly help.

Code:
/*Candle Stick Chart For Stock*/

/*Body Colors*/
Whitebody=C>=O;
Blackbody=O>C;
Realbody =abs(O-C);
Realbodypercent = (Realbody/Ref(C, -1))*100;
Range = H-L;
Percentdiff =((C - Ref(C, -1))/Ref(C, -1))*100;
Tiny = 0.25;
Small = 1;
Medium = 3;
Large = 5;


/*Body Size*/
Smallbody = Realbodypercent <= Small;
Mediumbody =Small < Realbodypercent < Medium ;
Largebody = Medium < Realbodypercent < Large ;
Extralargebody = Realbodypercent >= Large;



/*Shadows*/
Lowershadow = abs(Min(O,C) - L);
Lowershadowpercent = ((abs(Min(O,C) - L))/Ref(C, -1))*100;
Uppershadow =abs( H - Max(O,C));
Uppershadowpercent = ((abs( H - Max(O,C)))/Ref(C, -1))*100;

Lowershadow1 = Min(Ref(O, -1) ,C) - Min(L,Ref(L,-1));
Uppershadow1 = Max(H, Ref(H,-1)) - Max(Ref(O, -1),C);
Range1= Max(H, Ref(H,-1))-Min(L,Ref(L,-1));
Realbody1 =abs(C-Ref(O,-1));

Min1 = Min( L, Ref(L,-1));
Max1 = Max(H, Ref(H,-1));
Lowershadow2 = Min(Ref(O, -2) ,C) - Min(Min1, Ref(L,-2));
Uppershadow2 = Max(Max1,Ref(H,-2)) - Max(Ref(O, -2),C);

Range2= Max(Max1,Ref(H,-2))-Min(Min1,Ref(L,-2));
Realbody2 =abs(C-Ref(O,-2));
Smalluppershadow= Uppershadowpercent <= Tiny;
Smalllowershadow= Lowershadowpercent <= Tiny;

Largeuppershadow= Uppershadowpercent >= Small;
Largelowershadow= Lowershadowpercent >=Small;


/*Gaps*/
Upgappoint = O - Ref(C,-1);
Upgap=  O >= (Ref(C, -1) + Ref(C, -1)*0.005);
Downgap= O <= (Ref(C, -1) - Ref(C, -1)*0.005);

/*Candlestick Chart Of Bullish Sentiment Start */


Engulfingbullish=Open<Ref(Low,-1) AND Close>Ref(High,-1) AND Close>=Open*1.01 AND LLV(Low, 5)==Low AND LLV(Low, 5)==Min(Low, Ref(Low,-1));

Hammer=Open>=(High-((High-Low)*.25)) AND Close>=(High-((High-Low)*.25)) AND LLV(Low,5)==Low AND LLV(Low, 5)==Min(Low, Ref(Low,-1));

Matchinghigh=HHV(High,8)==HHV(High,2) AND Ref(Close,-1)>=Ref(Open,-1)*.99 AND abs(High-Ref(High,-1))<=High*.0025 AND Open> Close AND LLV(Low, 5)==Min(Low, Ref(Low,-1));


/*Candlestick Chart Of Bearish Sentiment Start */


Engulfingbearish=Open>Ref(High,-1) AND Close<Ref(Low,-1) AND HHV(High, 5)== Max(High, Ref(High, -1));

Matchinglow=LLV(Low,8)==LLV(Low,2) AND Ref(Close,-1)<=Ref(Open,-1)*.99 AND abs(Close-Ref(Close,-1))<=Close*.0025 AND Open>Ref(Close,-1) AND Open<=(High-((High-Low)*.5)) AND HHV(High, 5)== Max(High, Ref(High, -1));

Shootingstar=Low>Ref(High,-1) AND Open<=(Low+((High-Low)*.25)) AND Close<=(Low+((High-Low)*.25)) AND HHV(High, 5)== Max(High, Ref(High, -1));


/*Bullish Doji Reversal Set Ups*/

OnebarDojibullish1 = abs(Close-Open) <= (Close*.0025) AND LLV(Low, 8)==Min(Low, Ref(Low,-1));

OnebarDojibullish2 = abs(Open-Close)<=((High-Low)*0.1) AND LLV(Low, 8)==Min(Low, Ref(Low,-1));

OnebarDojibullishyesterday1=(abs(Ref(Close,-1)-Ref(Open,-1)) <= (Ref(Close,-1)*.0025) AND LLV(Low, 8)==Ref(Low,-1));

OnebarDojibullishyesterday2=(abs(Ref(Open,-1)-Ref(Close,-1))<=((Ref(High,-1)-Ref(Low,-1))*0.1) AND LLV(Low, 8)==Ref(Low,-1));


/*Bearish Doji Reversal Set Ups*/

Dojibearish1=abs(Close-Open) <= (Close*.0025) AND HHV(High, 8)== Max(High, Ref(High, -1));

Dojibearish2=abs(Open-Close)<=((High-Low)*0.1)AND HHV(High, 8)==Max(High, Ref(High, -1));

Dojibearishyesterday1=abs(Ref(Close,-1)-Ref(Open,-1)) <= (Ref(Close,-1)*.0025) AND HHV(High, 8)==Max(Ref(High,-1),Ref(High,-2));

Dojibearishyesterday2=(abs(Ref(Open,-1)-Ref(Close,-1))<=((Ref(High,-1)-Ref(Low,-1))*0.1)AND HHV(High, 8)==Ref(High,-1));



/*Bullish Wick Reversal Set Up */
Onebarbullishwick=(Range/Realbody)>3.5 AND C>= (Low +Range*0.8) AND LLV(Low,5)==Low;

Twobarbullishwick=(Range1/Realbody1)>3.5 AND C>= (Min(L,Ref(L,-1)) +Range1*0.8) AND LLV(Low,5)==Min(L,Ref(L,-1)) AND L < Ref(L, -1);

Threebarbullishwick=(Range2/Realbody2)>3.5 AND C>= (Min(Min1,Ref(L,-2)) +Range2*0.8) AND LLV(Low,5)==Min(Min1,Ref(L,-2)) AND L < Ref(L, -1);


/*Bearish Wick Reversal Set Up */

Onebarbearishwick=(Range/Realbody)>3.5 AND C<= (High-Range*0.8) AND HHV(High, 5)==High;

Twobarbearishwick=(Range1/Realbody1)>3.5 AND C<= (Max(H, Ref(H,-1))-Range1*0.8) AND HHV(High, 5)==Max(H, Ref(H,-1)) AND H < Ref(H, -1);

Threebarbearishwick=(Range2/Realbody2)>3.5 AND C<= (Max(Max1,Ref(H,-2))-Range2*0.8) AND HHV(High, 5)==Max(Max1,Ref(H,-2)) AND H < Ref(H, -1);


/*Bullish Extreme Reversal Setup*/
Candleaverage = Ref(MA(H, 5), -1) - Ref(MA(L, 5), -1);
Theextremereversalbullish = Range > 3*Candleaverage AND HHV(L, 5) ==Low AND Realbody > Range*0.5 AND Realbody < Range*0.85;

/*Bearish Extreme Reversal Setup*/

Theextremereversalbearish = Range > 3*Candleaverage AND HHV(H, 5) ==High AND C<= (L +Range*0.8) AND C>= (L +Range*0.4);


/*Bullish Trend Continuation */

Eightdaynewlinepatternbullish = (H>Ref(H,-1) AND Ref(H,-1) >Ref(H,-2) AND Ref(H,-2) >Ref(H,-3) AND Ref(H,-3) >Ref(H,-4) AND Ref(H,-4) >Ref(H,-5) AND Ref(H,-5) >Ref(H,-6) AND Ref(H,-6) >Ref(H,-7) ) OR (L>Ref(L,-1) AND Ref(L,-1) >Ref(L,-2) AND Ref(L,-2) >Ref(L,-3) AND Ref(L,-3) >Ref(L,-4) AND Ref(L,-4) >Ref(L,-5) AND Ref(L,-5) >Ref(L,-6) AND Ref(L,-6) >Ref(L,-7) );

Thrteendaynewlinepatternbullish  = (H>Ref(H,-1) AND Ref(H,-1) >Ref(H,-2) AND Ref(H,-2) >Ref(H,-3) AND Ref(H,-3) >Ref(H,-4) AND Ref(H,-4) >Ref(H,-5) AND Ref(H,-5) >Ref(H,-6) AND Ref(H,-6) >Ref(H,-7) AND Ref(H,-7) >Ref(H,-8) AND Ref(H,-8) >Ref(H,-9) AND Ref(H,-9)>Ref(H,-10) AND Ref(H,-10)>Ref(H,-11) AND Ref(H,-11) >Ref(H,-12) ) OR (L>Ref(L,-1) AND Ref(L,-1) >Ref(L,-2) AND Ref(L,-2) >Ref(L,-3) AND Ref(L,-3) >Ref(L,-4) AND Ref(L,-4) >Ref(L,-5) AND Ref(L,-5) >Ref(L,-6) AND Ref(L,-6) >Ref(L,-7)  AND Ref(L,-7) >Ref(L,-8)  AND Ref(L,-8) >Ref(L,-9) AND Ref(L,-9)  >Ref(L,-10) AND Ref(L,-10) >Ref(L,-11)  AND Ref(L,-11)   >Ref(L,-12) );



/*Bearish Trend Continuation */

Eightdaynewlinepatternbearish = (H<Ref(H,-1) AND Ref(H,-1) <Ref(H,-2) AND Ref(H,-2) <Ref(H,-3) AND Ref(H,-3) <Ref(H,-4) AND Ref(H,-4) <Ref(H,-5) AND Ref(H,-5) <Ref(H,-6) AND Ref(H,-6) <Ref(H,-7) ) OR (L<Ref(L,-1) AND Ref(L,-1) <Ref(L,-2) AND Ref(L,-2) <Ref(L,-3) AND Ref(L,-3) <Ref(L,-4) AND Ref(L,-4) <Ref(L,-5) AND Ref(L,-5) <Ref(L,-6) AND Ref(L,-6) <Ref(L,-7) );

Thrteendaynewlinepatternbearish  = (H<Ref(H,-1) AND Ref(H,-1) <Ref(H,-2) AND Ref(H,-2) <Ref(H,-3) AND Ref(H,-3) <Ref(H,-4) AND Ref(H,-4) <Ref(H,-5) AND Ref(H,-5) <Ref(H,-6) AND Ref(H,-6) <Ref(H,-7) AND Ref(H,-7) <Ref(H,-8) AND Ref(H,-8) <Ref(H,-9) AND Ref(H,-9)<Ref(H,-10) AND Ref(H,-10)<Ref(H,-11) AND Ref(H,-11) <Ref(H,-12) ) OR (L<Ref(L,-1) AND Ref(L,-1) <Ref(L,-2) AND Ref(L,-2) <Ref(L,-3) AND Ref(L,-3) <Ref(L,-4) AND Ref(L,-4) <Ref(L,-5) AND Ref(L,-5) <Ref(L,-6) AND Ref(L,-6) <Ref(L,-7)  AND Ref(L,-7) <Ref(L,-8)  AND Ref(L,-8) <Ref(L,-9) AND Ref(L,-9)  <Ref(L,-10) AND Ref(L,-10) <Ref(L,-11)  AND Ref(L,-11)   <Ref(L,-12) );


Explore = /*Bullish Wick Reversal Set Up */

WriteIf(Onebarbullishwick, "Onebar Bullish Wick",
WriteIf(Twobarbullishwick, "Twobar Bullish Wick",
WriteIf(Threebarbullishwick, "Threebar Bullish Wick",


/*Bullish Doji Reversal Set Ups*/

WriteIf(OnebarDojibullish1, "Doji Bullish Today 1",
WriteIf(OnebarDojibullish2, "Doji Bullish Today 2",
WriteIf(OnebarDojibullishyesterday1, "Doji Bullish Yesterday 1",
WriteIf(OnebarDojibullishyesterday2, "Doji Bullish Yesterday 2",

/*Bullish Sentiment Start*/

WriteIf(Engulfingbullish, "Engulfing Bullish",
WriteIf(Hammer, "Hammer",
WriteIf(Matchinghigh, "Matching High",



/*Bullish Extreme Reversal Setup */
WriteIf(Theextremereversalbullish, "Extreme Reversal Bullish",



/*Bullish Trend Continuation */
WriteIf(Thrteendaynewlinepatternbullish, "Thrteenday Newlinepattern Bullish",
WriteIf(Eightdaynewlinepatternbullish, "Eightday Newlinepattern Bullish",



/*Bearish Doji Reversal Set Ups*/
WriteIf(Dojibearish1, "Doji Bearish Today 1",
WriteIf(Dojibearish2, "Doji Bearish Today 2",
WriteIf(Dojibearishyesterday1, "Doji Bearish Yesterday 1",
WriteIf(Dojibearishyesterday2, "Doji Bearish Yesterday 2",

/*Bearish Trend Continuation */
WriteIf(Theextremereversalbearish, "Extreme Reversal Bearish",

/*Bearish Sentiment Start */

WriteIf(Engulfingbearish, "Engulfing Bearish",
WriteIf(Matchinglow, "Matching Low",
WriteIf(Shootingstar, "Shooting Star",

/*Bearish Wick Reversal Set Up */

WriteIf(Onebarbearishwick, "Onebar Bearish Wick",
WriteIf(Twobarbearishwick, "Twobar Bearish Wick",
WriteIf(Threebarbearishwick, "Threebar Bearish Wick",


/*Bearish Trend Continuation */
WriteIf(Thrteendaynewlinepatternbearish, "Thrteenday Newline Pattern Bearish",
WriteIf(Eightdaynewlinepatternbearish, "Eightday Newlinepattern Bearish",""))))))))))))))))))))))))));


Filter = 1;

Col1 =    IIf(Onebarbullishwick OR Twobarbullishwick OR Threebarbullishwick OR OnebarDojibullish1 OR OnebarDojibullish2 OR OnebarDojibullishyesterday1 OR OnebarDojibullishyesterday2 OR Engulfingbullish OR Hammer OR Matchinghigh OR Eightdaynewlinepatternbullish OR Thrteendaynewlinepatternbullish OR Theextremereversalbullish, colorGreen,
    IIf(Onebarbearishwick OR Twobarbearishwick OR Threebarbearishwick OR Dojibearish1 OR Dojibearish2 OR Dojibearishyesterday1 OR Dojibearishyesterday2 OR Engulfingbearish OR Shootingstar OR Matchinglow OR Eightdaynewlinepatternbearish OR Thrteendaynewlinepatternbearish OR Theextremereversalbearish, colorRed, 0));



AddColumn(C, "Close", 1.2);

AddTextColumn(Explore, "Pattern", 1.0, Col1, colorDefault,190);
afl_issue.jpg
afl_issue.jpg
 
Last edited:
Hello everyone / @Happy_Singh ,

Need some help in getting the output of an afl in explorer. Right now i am getting the attached image output from an afl. Basically i wanted to remove empty cells in output . So basically it should give only that output where there is a match for pattern column. Kindly help. I have copied the afl as well below.

Kindly help.

Code:
/*Candle Stick Chart For Stock*/

/*Body Colors*/
Whitebody=C>=O;
Blackbody=O>C;
Realbody =abs(O-C);
Realbodypercent = (Realbody/Ref(C, -1))*100;
Range = H-L;
Percentdiff =((C - Ref(C, -1))/Ref(C, -1))*100;
Tiny = 0.25;
Small = 1;
Medium = 3;
Large = 5;


/*Body Size*/
Smallbody = Realbodypercent <= Small;
Mediumbody =Small < Realbodypercent < Medium ;
Largebody = Medium < Realbodypercent < Large ;
Extralargebody = Realbodypercent >= Large;



/*Shadows*/
Lowershadow = abs(Min(O,C) - L);
Lowershadowpercent = ((abs(Min(O,C) - L))/Ref(C, -1))*100;
Uppershadow =abs( H - Max(O,C));
Uppershadowpercent = ((abs( H - Max(O,C)))/Ref(C, -1))*100;

Lowershadow1 = Min(Ref(O, -1) ,C) - Min(L,Ref(L,-1));
Uppershadow1 = Max(H, Ref(H,-1)) - Max(Ref(O, -1),C);
Range1= Max(H, Ref(H,-1))-Min(L,Ref(L,-1));
Realbody1 =abs(C-Ref(O,-1));

Min1 = Min( L, Ref(L,-1));
Max1 = Max(H, Ref(H,-1));
Lowershadow2 = Min(Ref(O, -2) ,C) - Min(Min1, Ref(L,-2));
Uppershadow2 = Max(Max1,Ref(H,-2)) - Max(Ref(O, -2),C);

Range2= Max(Max1,Ref(H,-2))-Min(Min1,Ref(L,-2));
Realbody2 =abs(C-Ref(O,-2));
Smalluppershadow= Uppershadowpercent <= Tiny;
Smalllowershadow= Lowershadowpercent <= Tiny;

Largeuppershadow= Uppershadowpercent >= Small;
Largelowershadow= Lowershadowpercent >=Small;


/*Gaps*/
Upgappoint = O - Ref(C,-1);
Upgap=  O >= (Ref(C, -1) + Ref(C, -1)*0.005);
Downgap= O <= (Ref(C, -1) - Ref(C, -1)*0.005);

/*Candlestick Chart Of Bullish Sentiment Start */


Engulfingbullish=Open<Ref(Low,-1) AND Close>Ref(High,-1) AND Close>=Open*1.01 AND LLV(Low, 5)==Low AND LLV(Low, 5)==Min(Low, Ref(Low,-1));

Hammer=Open>=(High-((High-Low)*.25)) AND Close>=(High-((High-Low)*.25)) AND LLV(Low,5)==Low AND LLV(Low, 5)==Min(Low, Ref(Low,-1));

Matchinghigh=HHV(High,8)==HHV(High,2) AND Ref(Close,-1)>=Ref(Open,-1)*.99 AND abs(High-Ref(High,-1))<=High*.0025 AND Open> Close AND LLV(Low, 5)==Min(Low, Ref(Low,-1));


/*Candlestick Chart Of Bearish Sentiment Start */


Engulfingbearish=Open>Ref(High,-1) AND Close<Ref(Low,-1) AND HHV(High, 5)== Max(High, Ref(High, -1));

Matchinglow=LLV(Low,8)==LLV(Low,2) AND Ref(Close,-1)<=Ref(Open,-1)*.99 AND abs(Close-Ref(Close,-1))<=Close*.0025 AND Open>Ref(Close,-1) AND Open<=(High-((High-Low)*.5)) AND HHV(High, 5)== Max(High, Ref(High, -1));

Shootingstar=Low>Ref(High,-1) AND Open<=(Low+((High-Low)*.25)) AND Close<=(Low+((High-Low)*.25)) AND HHV(High, 5)== Max(High, Ref(High, -1));


/*Bullish Doji Reversal Set Ups*/

OnebarDojibullish1 = abs(Close-Open) <= (Close*.0025) AND LLV(Low, 8)==Min(Low, Ref(Low,-1));

OnebarDojibullish2 = abs(Open-Close)<=((High-Low)*0.1) AND LLV(Low, 8)==Min(Low, Ref(Low,-1));

OnebarDojibullishyesterday1=(abs(Ref(Close,-1)-Ref(Open,-1)) <= (Ref(Close,-1)*.0025) AND LLV(Low, 8)==Ref(Low,-1));

OnebarDojibullishyesterday2=(abs(Ref(Open,-1)-Ref(Close,-1))<=((Ref(High,-1)-Ref(Low,-1))*0.1) AND LLV(Low, 8)==Ref(Low,-1));


/*Bearish Doji Reversal Set Ups*/

Dojibearish1=abs(Close-Open) <= (Close*.0025) AND HHV(High, 8)== Max(High, Ref(High, -1));

Dojibearish2=abs(Open-Close)<=((High-Low)*0.1)AND HHV(High, 8)==Max(High, Ref(High, -1));

Dojibearishyesterday1=abs(Ref(Close,-1)-Ref(Open,-1)) <= (Ref(Close,-1)*.0025) AND HHV(High, 8)==Max(Ref(High,-1),Ref(High,-2));

Dojibearishyesterday2=(abs(Ref(Open,-1)-Ref(Close,-1))<=((Ref(High,-1)-Ref(Low,-1))*0.1)AND HHV(High, 8)==Ref(High,-1));



/*Bullish Wick Reversal Set Up */
Onebarbullishwick=(Range/Realbody)>3.5 AND C>= (Low +Range*0.8) AND LLV(Low,5)==Low;

Twobarbullishwick=(Range1/Realbody1)>3.5 AND C>= (Min(L,Ref(L,-1)) +Range1*0.8) AND LLV(Low,5)==Min(L,Ref(L,-1)) AND L < Ref(L, -1);

Threebarbullishwick=(Range2/Realbody2)>3.5 AND C>= (Min(Min1,Ref(L,-2)) +Range2*0.8) AND LLV(Low,5)==Min(Min1,Ref(L,-2)) AND L < Ref(L, -1);


/*Bearish Wick Reversal Set Up */

Onebarbearishwick=(Range/Realbody)>3.5 AND C<= (High-Range*0.8) AND HHV(High, 5)==High;

Twobarbearishwick=(Range1/Realbody1)>3.5 AND C<= (Max(H, Ref(H,-1))-Range1*0.8) AND HHV(High, 5)==Max(H, Ref(H,-1)) AND H < Ref(H, -1);

Threebarbearishwick=(Range2/Realbody2)>3.5 AND C<= (Max(Max1,Ref(H,-2))-Range2*0.8) AND HHV(High, 5)==Max(Max1,Ref(H,-2)) AND H < Ref(H, -1);


/*Bullish Extreme Reversal Setup*/
Candleaverage = Ref(MA(H, 5), -1) - Ref(MA(L, 5), -1);
Theextremereversalbullish = Range > 3*Candleaverage AND HHV(L, 5) ==Low AND Realbody > Range*0.5 AND Realbody < Range*0.85;

/*Bearish Extreme Reversal Setup*/

Theextremereversalbearish = Range > 3*Candleaverage AND HHV(H, 5) ==High AND C<= (L +Range*0.8) AND C>= (L +Range*0.4);


/*Bullish Trend Continuation */

Eightdaynewlinepatternbullish = (H>Ref(H,-1) AND Ref(H,-1) >Ref(H,-2) AND Ref(H,-2) >Ref(H,-3) AND Ref(H,-3) >Ref(H,-4) AND Ref(H,-4) >Ref(H,-5) AND Ref(H,-5) >Ref(H,-6) AND Ref(H,-6) >Ref(H,-7) ) OR (L>Ref(L,-1) AND Ref(L,-1) >Ref(L,-2) AND Ref(L,-2) >Ref(L,-3) AND Ref(L,-3) >Ref(L,-4) AND Ref(L,-4) >Ref(L,-5) AND Ref(L,-5) >Ref(L,-6) AND Ref(L,-6) >Ref(L,-7) );

Thrteendaynewlinepatternbullish  = (H>Ref(H,-1) AND Ref(H,-1) >Ref(H,-2) AND Ref(H,-2) >Ref(H,-3) AND Ref(H,-3) >Ref(H,-4) AND Ref(H,-4) >Ref(H,-5) AND Ref(H,-5) >Ref(H,-6) AND Ref(H,-6) >Ref(H,-7) AND Ref(H,-7) >Ref(H,-8) AND Ref(H,-8) >Ref(H,-9) AND Ref(H,-9)>Ref(H,-10) AND Ref(H,-10)>Ref(H,-11) AND Ref(H,-11) >Ref(H,-12) ) OR (L>Ref(L,-1) AND Ref(L,-1) >Ref(L,-2) AND Ref(L,-2) >Ref(L,-3) AND Ref(L,-3) >Ref(L,-4) AND Ref(L,-4) >Ref(L,-5) AND Ref(L,-5) >Ref(L,-6) AND Ref(L,-6) >Ref(L,-7)  AND Ref(L,-7) >Ref(L,-8)  AND Ref(L,-8) >Ref(L,-9) AND Ref(L,-9)  >Ref(L,-10) AND Ref(L,-10) >Ref(L,-11)  AND Ref(L,-11)   >Ref(L,-12) );



/*Bearish Trend Continuation */

Eightdaynewlinepatternbearish = (H<Ref(H,-1) AND Ref(H,-1) <Ref(H,-2) AND Ref(H,-2) <Ref(H,-3) AND Ref(H,-3) <Ref(H,-4) AND Ref(H,-4) <Ref(H,-5) AND Ref(H,-5) <Ref(H,-6) AND Ref(H,-6) <Ref(H,-7) ) OR (L<Ref(L,-1) AND Ref(L,-1) <Ref(L,-2) AND Ref(L,-2) <Ref(L,-3) AND Ref(L,-3) <Ref(L,-4) AND Ref(L,-4) <Ref(L,-5) AND Ref(L,-5) <Ref(L,-6) AND Ref(L,-6) <Ref(L,-7) );

Thrteendaynewlinepatternbearish  = (H<Ref(H,-1) AND Ref(H,-1) <Ref(H,-2) AND Ref(H,-2) <Ref(H,-3) AND Ref(H,-3) <Ref(H,-4) AND Ref(H,-4) <Ref(H,-5) AND Ref(H,-5) <Ref(H,-6) AND Ref(H,-6) <Ref(H,-7) AND Ref(H,-7) <Ref(H,-8) AND Ref(H,-8) <Ref(H,-9) AND Ref(H,-9)<Ref(H,-10) AND Ref(H,-10)<Ref(H,-11) AND Ref(H,-11) <Ref(H,-12) ) OR (L<Ref(L,-1) AND Ref(L,-1) <Ref(L,-2) AND Ref(L,-2) <Ref(L,-3) AND Ref(L,-3) <Ref(L,-4) AND Ref(L,-4) <Ref(L,-5) AND Ref(L,-5) <Ref(L,-6) AND Ref(L,-6) <Ref(L,-7)  AND Ref(L,-7) <Ref(L,-8)  AND Ref(L,-8) <Ref(L,-9) AND Ref(L,-9)  <Ref(L,-10) AND Ref(L,-10) <Ref(L,-11)  AND Ref(L,-11)   <Ref(L,-12) );


Explore = /*Bullish Wick Reversal Set Up */

WriteIf(Onebarbullishwick, "Onebar Bullish Wick",
WriteIf(Twobarbullishwick, "Twobar Bullish Wick",
WriteIf(Threebarbullishwick, "Threebar Bullish Wick",


/*Bullish Doji Reversal Set Ups*/

WriteIf(OnebarDojibullish1, "Doji Bullish Today 1",
WriteIf(OnebarDojibullish2, "Doji Bullish Today 2",
WriteIf(OnebarDojibullishyesterday1, "Doji Bullish Yesterday 1",
WriteIf(OnebarDojibullishyesterday2, "Doji Bullish Yesterday 2",

/*Bullish Sentiment Start*/

WriteIf(Engulfingbullish, "Engulfing Bullish",
WriteIf(Hammer, "Hammer",
WriteIf(Matchinghigh, "Matching High",



/*Bullish Extreme Reversal Setup */
WriteIf(Theextremereversalbullish, "Extreme Reversal Bullish",



/*Bullish Trend Continuation */
WriteIf(Thrteendaynewlinepatternbullish, "Thrteenday Newlinepattern Bullish",
WriteIf(Eightdaynewlinepatternbullish, "Eightday Newlinepattern Bullish",



/*Bearish Doji Reversal Set Ups*/
WriteIf(Dojibearish1, "Doji Bearish Today 1",
WriteIf(Dojibearish2, "Doji Bearish Today 2",
WriteIf(Dojibearishyesterday1, "Doji Bearish Yesterday 1",
WriteIf(Dojibearishyesterday2, "Doji Bearish Yesterday 2",

/*Bearish Trend Continuation */
WriteIf(Theextremereversalbearish, "Extreme Reversal Bearish",

/*Bearish Sentiment Start */

WriteIf(Engulfingbearish, "Engulfing Bearish",
WriteIf(Matchinglow, "Matching Low",
WriteIf(Shootingstar, "Shooting Star",

/*Bearish Wick Reversal Set Up */

WriteIf(Onebarbearishwick, "Onebar Bearish Wick",
WriteIf(Twobarbearishwick, "Twobar Bearish Wick",
WriteIf(Threebarbearishwick, "Threebar Bearish Wick",


/*Bearish Trend Continuation */
WriteIf(Thrteendaynewlinepatternbearish, "Thrteenday Newline Pattern Bearish",
WriteIf(Eightdaynewlinepatternbearish, "Eightday Newlinepattern Bearish",""))))))))))))))))))))))))));


Filter = 1;

Col1 =    IIf(Onebarbullishwick OR Twobarbullishwick OR Threebarbullishwick OR OnebarDojibullish1 OR OnebarDojibullish2 OR OnebarDojibullishyesterday1 OR OnebarDojibullishyesterday2 OR Engulfingbullish OR Hammer OR Matchinghigh OR Eightdaynewlinepatternbullish OR Thrteendaynewlinepatternbullish OR Theextremereversalbullish, colorGreen,
    IIf(Onebarbearishwick OR Twobarbearishwick OR Threebarbearishwick OR Dojibearish1 OR Dojibearish2 OR Dojibearishyesterday1 OR Dojibearishyesterday2 OR Engulfingbearish OR Shootingstar OR Matchinglow OR Eightdaynewlinepatternbearish OR Thrteendaynewlinepatternbearish OR Theextremereversalbearish, colorRed, 0));



AddColumn(C, "Close", 1.2);

AddTextColumn(Explore, "Pattern", 1.0, Col1, colorDefault,190);
View attachment 29757 View attachment 29757

Replace
Code:
...Filter = 1;....
with
Code:
...Filter = StrLen(Explore) > 0;....
 
Code:
nd = (Day() != Ref(Day(), -1));
dn = DateNum();
tn = TimeNum();
CDR = IIf(ND == 0, Sum(V, 1 + BarsSince(ND)), V);
PDR1 = 0;
PDR2 = 0;
pbd = ValueWhen(nd, dn, 2);
matchd = DateTimeConvert(2, pbd, tn);

for (i = 1; i < BarCount; i++) {
PDR1[i] = PDR1[i-1];
PDR2[i] = Lookup(CDR, matchd[i], -1);
if (i > 375) {
for(k = i - 1; k > 0; k--) {
if (tn[i] == tn[k]) {
PDR1[i] = CDR[k];
break;
k = 0;
}}}}

AddColumn(CDR, "CDR");
AddColumn(PDR1, "PDR1");
AddColumn(PDR2, "PDR2");
Filter = 1;
Romeo and others...

I fixed the problem reported earlier. This is also a good example of how to use Lookup function. Now values of PDR1 and PDR2 will always match thus eliminating need for PDR1 which is slower
 
Hi All,

I am new to afl. Below is a code which i made : my aim is to get high and low of a particular date and then explore for stocks breaking out of tht high and low any time of the day. I am checking for 18th high and low getting being broken. This is nt giving any result when i ma running with 5 min as periodicity where as in reality there are many cases where on 19th --18th high and low was broken, Pls help.
_SECTION_BEGIN("HighLow");

// AFL to read Close price on 14/June/2017/
// Datenum calculated as being
//(10000 * (2017 - 1900)) + (100 * 6) + 14 = 1170614

H1 = ValueWhen(DateNum() ==1181018, High);

L1 = ValueWhen(DateNum() ==1181018, Low);

HBO=(C>H1 AND L<H1);
HRV=(C<H1 AND L>H1);
LBO=(C<L1 AND L>L1);
LRV=(C>L1 AND L<L1);

Filter=HBO OR HRV OR LBO OR LRV;


_SECTION_END()
 
Hi All,

I am new to afl. Below is a code which i made : my aim is to get high and low of a particular date and then explore for stocks breaking out of tht high and low any time of the day. I am checking for 18th high and low getting being broken. This is nt giving any result when i ma running with 5 min as periodicity where as in reality there are many cases where on 19th --18th high and low was broken, Pls help.
_SECTION_BEGIN("HighLow");

// AFL to read Close price on 14/June/2017/
// Datenum calculated as being
//(10000 * (2017 - 1900)) + (100 * 6) + 14 = 1170614

H1 = ValueWhen(DateNum() ==1181018, High);

L1 = ValueWhen(DateNum() ==1181018, Low);

HBO=(C>H1 AND L<H1);
HRV=(C<H1 AND L>H1);
LBO=(C<L1 AND L>L1);
LRV=(C>L1 AND L<L1);

Filter=HBO OR HRV OR LBO OR LRV;


_SECTION_END()
Sir I think the following changes should work in your code :

Code:
Plot(H1,"H1",colorred,styleline,0,0,0,-1); // just for visual verifications
Plot(L1,"L1",colorgreen,styleline,0,0,0,-1);// just for visual verifications

HBO = Cross(C,H1);
HRV = Cross(H1,C);
LBO = Cross(L1,C);
LRV = Cross(C,L1);

AddColumn (HBO, "HBO");
AddColumn (HRV, "HRV");
AddColumn (LBO, "LBO");
AddColumn (LRV, "LRV");
 
Hi Everybody,

I am a beginer in using afl and amibroker. I am looking to trade on Bollinger Band Squeeze Breakout . I would be working on the Nifty 50 stocks. I requre help to create a alert system where this kind of senario is hapenning.If anyone knows any afl which can help me in this case pls share.

Regards

Bollinger-Bands-Squeeze.png
 

Similar threads