hi,
this the afl code that i wish to use and the last line runs a
scan
can some one please modify the scan so that i get results with volume breakout (say volume more than 20%
of average 15 days voulme)
thanks in advance
need help
with just the last line.
the code begins here
_SECTION_BEGIN(" Support and Resistance ");
/* Support
and Resistance Formula for Amibroker
based on Excel spreadsheet by
nmralarb */
GraphXSpace=1;
MaxGraph=15;
Period=Param("MM_Period", 70, 4, 256, 1)
;
Graph1Color=6; Graph2Color=6; Graph3Color=6;
Graph4Color=6;
Graph5Color=6; Graph6Color=6;
Graph7Color=6; Graph8Color=6;
Graph9Color=6;
Graph10Color=6;
Graph11Color=6;Graph12Color=6;
Graph13Color=6;
Graph0=Close;
Graph0Color=1; Graph0Style=64;
Graph1Style=1;
Graph2Style=1; Graph3Style=1;
Graph4Style=1;
Graph5Style=1; Graph6Style=1;
Graph7Style=1; Graph8Style=1;
Graph9Style=1;
Graph10Style=1; Graph11Style=4;
Graph12Style=1;
Graph12Style=1;
PER =
Period;
BarNR = LastValue(Cum(1)) ;
TimeFrame = BarNR - PER ;
TF
= TimeFrame ;
Lo = LastValue(ValueWhen(Cross(Cum(1), TF),
LLV(Min(H,L),PER),1)) ;
Hi =
LastValue(ValueWhen(Cross(Cum(1), TF), HHV(Max(H,L),PER),1))
;
Lo = LastValue( LLV(Min(H,L),PER ),1) ;
Hi = LastValue(
HHV(Max(H,L),PER ),1) ;
Fractal = IIf(Hi<=250,100,
IIf(Hi<=2500,1000, IIf(Hi<=25000,10000, IIf(Hi<=250000,100000, 0 ))))
;
int_Log = int( log(Fractal/(Hi-Lo))/log(2) ) ;
Oct = Fractal
* ( exp(ln(1/2)* int_Log ) ) ;
Min_1 = int( Lo / Oct ) * Oct
;
Max_1 = IIf( (Min_1 + Oct) > Hi, Min_1 + Oct, Min_1 + 2*Oct )
;
Min_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <=
(Max_1 - 1/8*(Max_1-Min_1)) ,
(Min_1 + 1/4*(Max_1-Min_1)) , Min_1
) ;
Max_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <=
(Max_1 - 1/8*(Max_1-Min_1)) ,
(Max_1 - 1/4*(Max_1-Min_1)) , Max_1
) ;
/******************************/
Diff = Max_2
- Min_2 ;
H1 = IIf( (Min_2 + 3/16*Diff) <= Lo AND Hi <=
(9/16*Diff + Min_2) ,
Min_2 + 1/2*Diff, 0) ;
H2 = IIf( (Min_2 -
1/8*Diff) <= Lo AND Hi <= (5/8*Diff + Min_2) AND H1==0,
Min_2 +
1/2*Diff, 0) ;
H3 = IIf( (Min_2 + 7/16*Diff) <= Lo AND Hi <=
(Min_2 + 13/16*Diff), Min_2 + 3/4*Diff, 0 ) ;
H4 = IIf( (Min_2 +
3/8*Diff) <= Lo AND Hi <= (Min_2 + 9/8*Diff) AND H3==0,
Max_2, 0 )
;
H5 = IIf( (Min_2 + 1/8*Diff)<=Lo AND Hi <= (Min_2 + 7/8*Diff)
AND H1==0 AND H2==0 AND H3==0 AND H4==0,
Min_2 + 3/4*Diff , 0 ) ;
H6
= IIf( ( H1 + H2 + H3 + H4 + H5 ) == 0, Max_2, 0 )
;
/**************************/
L1 = IIf(H1>0, Min_2
+ 1/4*Diff, 0) ;
L2 = IIf(H2>0, Min_2, 0) ;
L3 = IIf(H3>0,
Min_2 + 1/2*Diff, 0) ;
L4 = IIf(H4>0, Min_2 + 1/2*Diff, 0)
;
L5 = IIf(H5>0, Min_2 + 1/4*Diff, 0) ;
L6 = IIf(H6>0,
Min_2, 0 ) ;
M_8 = ( H1 + H2 + H3 + H4 + H5 + H6 ) ;
M_0 = (
L1 + L2 + L3 + L4 + L5 + L6 )
;
/**************************************/
Graph1
= ValueWhen(Cum(1) >= TF, M_0 );
Graph2 = ValueWhen(Cum(1)
>= TF, M_0 + (1*(0.175*(M_8-M_0))));
Graph3 =
ValueWhen(Cum(1) >= TF, M_0 +
(2*(0.175*(M_8-M_0))));
Graph4 = ValueWhen(Cum(1) >=
TF, M_0 + (3*(0.175*(M_8-M_0))));
Graph5 =
ValueWhen(Cum(1) >= TF, M_0 +
(4*(0.175*(M_8-M_0))));
Graph6 = ValueWhen(Cum(1) >=
TF, M_0 + (5*(0.175*(M_8-M_0))));
Graph7 =
ValueWhen(Cum(1) >= TF, M_0 +
(6*(0.175*(M_8-M_0))));
Graph8 = ValueWhen(Cum(1) >=
TF, M_0 + (7*(0.175*(M_8-M_0))));
Graph9 =
ValueWhen(Cum(1) >= TF, M_0 +
(8*(0.175*(M_8-M_0))));
Graph10 = ValueWhen(Cum(1) >=
TF, M_0 + (9*(0.175*(M_8-M_0))));
Graph11 =
ValueWhen(Cum(1) >= TF, M_0 -
(1*(0.175*(M_8-M_0))));
Graph12 = ValueWhen(Cum(1) >=
TF, M_0 - (2*(0.175*(M_8-M_0))));
Graph13 =
ValueWhen(Cum(1) >= TF, M_0 -
(3*(0.175*(M_8-M_0))));
/**************************************************
************/
Title = Name()
+ "=" + WriteIf( round(C)== C,
NumToStr(C,1) , WriteVal(C) ) + " " + "\\c17"
+ WriteIf(
Interval()==86400, "Daily ", WriteIf(Interval()==3600,"Hourly
",
WriteIf(Interval()==900,"15 Min ", WriteIf(Interval()==300,"5
Min ",
WriteIf(Interval()==60,"1 Min ", "" ) ) ) ) )
+ Date() +
"\\c12" + WriteIf(Volume>0," Turnover=","")
+ WriteIf(Volume>0,
WriteVal(Volume*Close/1000), "" )
;
_SECTION_END();
_SECTION_BEGIN("Volume");
Plot(
Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ),
styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale |
styleThick | styleNoLabel, maskHistogram ), 2
);
_SECTION_END();
/*
**********************************
Code to automatically
identify pivots
**********************************
*/
//if (farback > BarCount-1)
//farback = BarCount-1;
// -- what
will be our lookback range for the hh and ll?
farback=Param("How Far
back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5,
40);
// -- Title.
Title = Name() + " (" +
StrLeft(FullName(), 15) + ") O: " + Open + ",H: " + High + ", L: " + Low
+ ", C: " + Close;
// -- Plot basic candle chart
PlotOHLC(Open,
High, Low, Close,
"BIdx = " + BarIndex() +
"\n" + "O = " + O +
"\n"+"H = "+ H + "\n"+"L = " + L
+ "\n"+"C ",
colorBlack,
styleCandle);
GraphXSpace=7;
// -- Create
0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs
= L - L;
// -- More for future use, not necessary for basic
plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs
= H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs =
0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH =
0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from
the current bar, how many bars
// back were the hhv and llv values of
the previous
// n bars, etc.?
aHHVBars = HHVBars(H,
nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H,
nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so
pivots are calculated back from
// last visible bar to make it easy to
"go back" and see the pivots
// this code would find. However, the
first instance of
// _Trace output will show a value of
0
aVisBars = Status("barvisible");
nLastVisBar =
LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last
visible bar: " + nLastVisBar);
// -- Initialize value of
curTrend
curBar = (BarCount-1);
curTrend = "";
if
(aLLVBars[curBar] <
aHHVBars[curBar]) {
curTrend =
"D";
}
else {
curTrend = "U";
}
// -- Loop
through bars. Search for
// entirely array-based approach
// in
future version
if (farback > BarCount-1)
farback = BarCount-1;
for
(i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// --
Have we identified a pivot? If trend is down...
if (aLLVBars[curBar]
< aHHVBars[curBar]) {
// ... and had been up, this is a trend
change
if (curTrend == "U") {
curTrend = "D";
// --
Capture pivot information
curPivBarIdx = curBar -
aLLVBars[curBar];
aLPivs[curPivBarIdx] =
1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] =
curPivBarIdx;
nLPivs++;
}
// -- or current trend is
up
} else {
if (curTrend == "D") {
curTrend =
"U";
curPivBarIdx = curBar -
aHHVBars[curBar];
aHPivs[curPivBarIdx] =
1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs]
= curPivBarIdx;
nHPivs++;
}
// -- If curTrend is
up...else...
}
// -- loop through bars
}
// --
Basic attempt to add a pivot this logic may have missed
// -- OK, now I
want to look at last two pivots. If the most
// recent low pivot is
after the last high, I could
// still have a high pivot that I didn't
catch
// -- Start at last bar
curBar =
(BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx =
aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx =
aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx
> lastHPIdx) {
// -- Bar and price info for candidate
pivot
candIdx = curBar - aHHVBars[curBar];
candPrc =
aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx
> lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll
add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then
rearrange elements in the
// pivot information arrays
for (j=0;
j<nHPivs; j++) {
aHPivHighs[nHPivs-j] =
aHPivHighs[nHPivs-
(j+1)];
aHPivIdxs[nHPivs-j] =
aHPivIdxs[nHPivs-(j+1)];
}
aHPivHighs[0] = candPrc
;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
} else
{
// -- Bar and price info for candidate pivot
candIdx =
curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if
(
lastLPL > candPrc AND
candIdx > lastHPIdx
AND
candIdx < curBar) {
// -- OK, we'll add this as a
pivot...
aLPivs[candIdx] = 1;
// ...and then rearrange elements
in the
// pivot information arrays
for (j=0; j<nLPivs; j++)
{
aLPivLows[nLPivs-j] =
aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] =
aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] =
candPrc;
aLPivIdxs[0] =
candIdx;
nLPivs++;
}
}
// -- Dump inventory of
high pivots for debugging
/*
for (k=0; k<nHPivs; k++)
{
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs[k]
+ ", "
+
WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],
DateTime(),
1), formatDateTime)
+ ", " +
aHPivHighs[k]);
}
*/
// -- OK, let's plot the pivots
using arrows
PlotShapes(
IIf(aHPivs==1, shapeDownArrow,
shapeNone), colorRed, 0,
High,
Offset=-15);
PlotShapes(
IIf(aLPivs==1, shapeUpArrow ,
shapeNone), colorGreen, 0,
Low,
Offset=-15);
//PlotShapes(IIf(aHPivs==1, shapeDownArrow,
shapeNone), colorRed, 0,High, Offset=-8);
//Sell = IIf(aHPivs==1, 1,
0);
//PlotShapes(IIf(aLPivs==1, shapeUpArrow , shapeNone),
colorGreen, 0, Low, Offset=-8);
Buy = IIf(aLPivs==1, 1, 0);