Australian (ASX) Stock Market Forum

Hi Trash,

I input the code you kindly provided and got a list of stocks! Your inclusion of Date was most useful as it allowed me to immediately see that I am getting a list of stocks and the date they closed at a 52 week high.

How may I vary your code to only include stocks that closed at 52 week high on the most recent Friday?

Thanks again.
 
I have not included Date column. Ticker and Datetime are default columns in exploration. They can be turned off by adding SetOption( "NoDefaultColumns", True );

https://www.amibroker.com/guide/afl/setoption.html

How may I vary your code to only include stocks that closed at 52 week high on the most recent Friday?

If periodicity set to weekly and depending on what you wanna achieve

New52High = C == HHV( H, 52 );

or

New52High = C == HHV( C, 52 );

or

http://www.amibroker.com/guide/afl/almostequal.html

New52High = AlmostEqual( C, HHV( H, 52 ), ulps = 5 );

or

New52High = AlmostEqual( C, HHV( C, 52 ), ulps = 5 );

or
.
.
.
.
 
Hi Guys,

not a specific code question, but related to data. I have yahoo data set up via amiquote and seems to work well.

except randomly for some stocks, some days are missing. This is despite all stocks been loaded from the same list within amiquote.

for example, i dont have the quotes for RIO for yesterday, but have todays and up to friday. however i have all the quotes inlcuding today for most others such as CBA, ANZ, BHP etc.....its puzzling me!?

I cannot seem to find a link between the stocks that have a full range of quotes for and those i dont. has anyone else had this issue? Is it just a hazard of using free data?

Cheers
 
I got Yahoo prices for RIO 12/05/2014 in Ami. so the download works. However as per usual the data is slightly different from Commsec. Low on Yahoo is 60.25 when it really was Low 60.94.
 
I got Yahoo prices for RIO 12/05/2014 in Ami. so the download works. However as per usual the data is slightly different from Commsec. Low on Yahoo is 60.25 when it really was Low 60.94.

i assume you mean 60.24?

I guess you get what you pay for....my only solution it seems is to log on regularly and do the data upload from amibroker, they dont seem to make yesterdays data available so that leaves a gap as well.

no doubt there is a way to do this automatically so i dont even have to open lists etc...but one step at a time!
 
i assume you mean 60.24?

I guess you get what you pay for....my only solution it seems is to log on regularly and do the data upload from amibroker, they dont seem to make yesterdays data available so that leaves a gap as well.

no doubt there is a way to do this automatically so i dont even have to open lists etc...but one step at a time!

It seems to me that you mix up a few things. AmiBroker is not a data vendor. It provides data from different data vendors. If the data you downloaded via AQ is wrong or missing then you have to complain to Yahoo. AQ just downloads the same EOD data that you get from Yahoo EOD historical prices i.e. http://finance.yahoo.com/q/hp?s=^GSPC+Historical+Prices Anyway Yahoo is a free source and they care less about non US markets. So I think there is not much you can do about it.
 
Know Sure Thing is an indicator created apparently by Martin Pring. Dunno if it can be tweaked to closer represent price ranges. Just found it at http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:know_sure_thing_kst



Code:
// Know Sure Thing (KST) - Developed by Martin Pring

RC1 = ROC(Avg, 10);
RC2 = ROC(Avg, 15);
RC3 = ROC(Avg, 20);
RC4 = ROC(Avg, 30);

RCMA1 = MA(RC1, 10); // 10-Period SMA of 10-Period Rate-of-Change 
RCMA2 = MA(RC2, 10); //10-Period SMA of 15-Period Rate-of-Change 
RCMA3 = MA(RC3, 10); // 10-Period SMA of 20-Period Rate-of-Change 
RCMA4 = MA(RC4, 15); // 15-Period SMA of 30-Period Rate-of-Change 

KST = (RCMA1 * 1) + (RCMA2 * 2) + (RCMA3 * 3) + (RCMA4 * 4);  
SignalLine = MA(KST, 9); // 9-period SMA of KST
VerticalLineUp = Cross(KST, -100);
VerticalLineDown = Cross(100, KST);

Plot(KST, "Know Sure Thing", colorBlue, styleThick);
Plot(SignalLine, "KST Signal", colorBlack);
Plot(100, "", colorDarkRed, styleDashed);
Plot(-100, "", colorSeaGreen, styleDashed);
Plot(VerticalLineUp, "", colorYellow, 16384+32768+4096, 0, 1);
Plot(VerticalLineDown, "", colorDarkRed, 16384+32768+4096, 0, 1);
Plot(0, "", colorWhite);
 
Know Sure Thing is an indicator created apparently by Martin Pring. Dunno if it can be tweaked to closer represent price ranges. Just found it at http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:know_sure_thing_kst



Code:
// Know Sure Thing (KST) - Developed by Martin Pring

RC1 = ROC(Avg, 10);
RC2 = ROC(Avg, 15);
RC3 = ROC(Avg, 20);
RC4 = ROC(Avg, 30);

RCMA1 = MA(RC1, 10); // 10-Period SMA of 10-Period Rate-of-Change 
RCMA2 = MA(RC2, 10); //10-Period SMA of 15-Period Rate-of-Change 
RCMA3 = MA(RC3, 10); // 10-Period SMA of 20-Period Rate-of-Change 
RCMA4 = MA(RC4, 15); // 15-Period SMA of 30-Period Rate-of-Change 

KST = (RCMA1 * 1) + (RCMA2 * 2) + (RCMA3 * 3) + (RCMA4 * 4);  
SignalLine = MA(KST, 9); // 9-period SMA of KST
VerticalLineUp = Cross(KST, -100);
VerticalLineDown = Cross(100, KST);

Plot(KST, "Know Sure Thing", colorBlue, styleThick);
Plot(SignalLine, "KST Signal", colorBlack);
Plot(100, "", colorDarkRed, styleDashed);
Plot(-100, "", colorSeaGreen, styleDashed);
Plot(VerticalLineUp, "", colorYellow, 16384+32768+4096, 0, 1);
Plot(VerticalLineDown, "", colorDarkRed, 16384+32768+4096, 0, 1);
Plot(0, "", colorWhite);


The code itself can be tweaked a little bit more by using dynamic variables.

Code:
// Know Sure Thing (KST) - Developed by Martin Pring
// http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:know_sure_thing_kst
// modified by trash 

for ( j = 10; j <= 30; j = j + 5 )
{
    if( j <= 20 ) VarSet( "RCMA" + j, MA( ROC( Avg, j ), 10 ) ); 
    else          VarSet( "RCMA" + j, MA( ROC( Avg, j ), 15 ) ); 
} 

KST = ( RCMA10 * 1 ) + ( RCMA15 * 2 ) + ( RCMA20 * 3 ) + ( RCMA30 * 4 );
SignalLine = MA( KST, 9 ); // 9-period SMA of KST
VerticalLineUp = Cross( KST, -100 );
VerticalLineDown = Cross( 100, KST );

Plot(KST, "Know Sure Thing", colorBlue, styleThick);
Plot(SignalLine, "KST Signal", colorBlack);
Plot(100, "", colorDarkRed, styleDashed);
Plot(-100, "", colorSeaGreen, styleDashed);
Plot(VerticalLineUp, "", colorYellow, 16384+32768+4096, 0, 1);
Plot(VerticalLineDown, "", colorDarkRed, 16384+32768+4096, 0, 1);
Plot(0, "", colorWhite);
 
Amibroker user asked for Tech Trader and I think this is correct but only Tech/A (the creator) can verify. There was no author so can't credit the code. To the Amibroker beginner :- notice the conditions are ingredients for an increasing price. The loss rate is relatively high because the timing may be out, i.e. buy in before a pullback of >10% which stops you out or the trend ends completely in which the stop loss saves you from larger loss. The trick is in the outliers that more than make up for the run of stop outs. Run this code on the ASX 300 for this calender year for what may have occurred. It isn't rocket science, it's about being profitable in the long run.

Code:
// techtrader v2 amibroker version
// here we define buy conditions and name each one as a variable
PosQty = 10; // You can define here how many open positions you want
SetOption("MaxOpenPositions", PosQty );
PositionScore = Random();
SetOption ("UsePrevBarEquityForPosSizing", True);
SetTradeDelays(1,1,0,0);

// techtrader v2 amibroker version
// here we define buy conditions and name each one as a variable
PositionSize = -10; // always invest only 10% of the current Equity
cond1=Cross(H,Ref(HHV(H,10),-1)); // when todays high crosses last highest high over the last 10 periods
cond2=H > EMA(C,40); // todays high is greater than the 40 day Exp MA of closes
cond3=HHVBars(H,70) == 0; // todays high is the highest for 70 periods
cond4=EMA(V*C,21) > 500000; // ensure at least $500k of money flow
cond5=C < 10.00; // only trading in stocks less than $10
cond6=C > O; // todays close higher than open

// the following line is the trigger if all conditions satisfied
Buy=cond1 AND cond2 AND cond3 AND cond4 AND cond5 AND cond6;
Sell= Cross(Ref(EMA(L,180),-1),C); // close crosses below yesterdays average of the low

ApplyStop(stopTypeLoss, stopModePercent, 10);

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0); // 
Filter = Sell; // lists exploration results conforming to our buy criteria
AddColumn(Sell, "sell", 1.0); // 

Buy = ExRem(Buy,Sell) ; 
Sell = ExRem(Sell, Buy);
 
Ironic, if you see this then you might consider an Index filter to add to the trend follower. A simple one is below but you can try anything really. Add the Identifier to the buy section. The set foreign function calls the parenthesis symbol. After the code body, restore price arrays is as it says. PositionScore is for preference to stocks if more candidates than funds available.
In such case AmiBroker will use the absolute value of PositionScore variable to decide which trades are preferred.


Code:
SetForeign("$XI"); 
IndexFilter = EMA(C, 10) > EMA(C, 20);
RestorePriceArrays(); 

PositionScore = Correlation(IndexFilter, Ref(C, -5), 5);

// the following line is the trigger if all conditions satisfied
Buy=cond1 AND cond2 AND cond3 AND cond4 AND cond5 AND cond6 & IndexFilter;
 
Can I set a weekly periodicity through an AFL code. I know I can do this in the analysis window but would like to be able to embed it in my system code.

I have not been able to see how I would do so. At the moment I have the following options set:

Code:
SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);
 
Can I set a weekly periodicity through an AFL code. I know I can do this in the analysis window but would like to be able to embed it in my system code.

I have not been able to see how I would do so. At the moment I have the following options set:

Code:
SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);

In the Users Guide take a look at the TimeFrame***() functions
 
This is one I've used for fading opens etc. Can give you the raw statistics for fading different days. You can then go for your life, setting targets and so on from this:

//Day of Week Buying and Selling Up and Down Opens.

SetTradeDelays(0,0,0,0);
TimeFrameSet(inDaily);
BuyPrice = Open;
SellPrice = Close;
ShortPrice = Open;
CoverPrice = Close;


Cond1 = O < Ref(C, -1);
Cond2 = O > Ref(C, -1);
Buy = Cond1 AND DayOfWeek() == Optimize("DayOfWeek", 1,1,5,1);
Sell = BarsSince(Buy) ==0;
Short = Cond2 AND DayOfWeek() == Optimize("DayOfWeek", 1,1,5,1);
Cover = BarsSince(Short) ==0;
 
This will get your optimization variables listing at the start of the report.

Save it as a part of your default template:

SetOption("ExtraColumnsLocation", 1 );
 
This is pretty good. Found it on the AB Yahoo site. Uses GFX to plot price. By James Hutchison.





function GetMonth( MonthNumber )
{
switch (MonthNumber) {
case 2 :
result = "Feb";
break ;
case 3 :
result = "Mar";
break ;
case 4 :
result = "Apr";
break ;
case 5 :
result = "May";
break ;
case 6 :
result = "Jun";
break ;
case 7 :
result = "Jul";
break ;
case 8 :
result = "Aug";
break ;
case 9 :
result = "Sep";
break ;
case 10 :
result = "Oct";
break ;
case 11 :
result = "Nov";
break ;
case 12 :
result = "Dec";
break ;
}

return result;
}



GfxSetOverlayMode( 2 );

String = "" ;
for ( x = 0 ; x < 200 ; x++ )
{
WList = CategoryGetName( categoryWatchlist, x );
if (WList != "" )
{
String = String + WList +"," ;
}
}
WatchList = ParamList ( "Watch List", String );
for ( x = 0 ; x < 200 ; x++ )
{
sym = StrExtract ( String, x );
if (sym == WatchList)
{
listNum = x ;
}
}

Page = Param ( "Page #", 0 , 0 , 12 , 1 );
ChartsWiNum = Param ( "# Charts Wide", 3 , .1 , 14 , .1 );
ChartsHiNum = Param ( "# Charts High", 3 , .1 , 14 , .1 );
Bars =Param ( "Number Of Bars", 195 , 20 , 250 , 1 ) ;
lDays =Param ( "Long MA", 200 , 50 , 250 , 1 ) ;
sDays =Param ( "Short MA", 50 , 5 , 100 , 1 ) ;
vDays =Param ( "Volume MA", 50 , 5 , 100 , 1 ) ;
ChartMargin = 15 ;
DateMargin = 10 ;
DataMargin = 20 ;
NumCharts = ChartsWiNum * ChartsHiNum ;
ScreenHeight = Status ( "pxheight" ) ;
SceernWidth = Status ( "pxwidth" ) ;
ChartHeight = ScreenHeight / ChartsHiNum -2 ;
Width = SceernWidth / ChartsWiNum - 2 ;
BarChartHeight= (0.75 ) * ChartHeight - DataMargin;
VolChartHeight = ChartHeight - BarChartHeight - DataMargin*2 ;
NumberPriceLevels = BarChartHeight / 25 ;
BarChartWidth= Width - 45 ;
BarWidth = (BarChartWidth - ChartMargin * 3 ) / Bars ;
LastBar = BarCount ;
FirstBar = LastBar - Bars;
_N (list = CategoryGetSymbols( categoryWatchlist, listnum ));
printf ( "Watch List Name\n");
WL = CategoryGetName( categoryWatchlist, listnum );
SymbolNum = Page * NumCharts;

for ( x = 0 ; x < ChartsHiNum ; x++ )
{
for ( i = 0 ; i < ChartsWiNum ; i++ )
{
notDone = True;
sym = StrExtract ( list, SymbolNum );
if (sym != "" )
{
x1 = Width * i + 5 ;
y1 = ChartHeight * x + 5 ;
x2 = Width * (i + 1 );
y2 = ChartHeight * (x + 1 )-DateMargin;
GfxSelectPen ( colorBlack );
GfxRectangle ( x1, y1, x2, y2 );
SymbolNum++;

SetForeign (sym);

EMAShort= EMA (C,sDays);
EMALong= EMA (C,lDays);
EMAVol= EMA (V,vDays);

D = Day ();
M = Month ();
Y = Year ();

priceHigh = 0 ;
VolHigh = 0 ;
priceMin = 1000000 ;
for ( z = FirstBar; z < LastBar ; z++ )
{
Vol = V[z];
BarH = H[z];
BarL = L[z];
if ( Vol > VolHigh )
{
VolHigh = Vol;
}
if ( BarH > priceHigh )
{
priceHigh = BarH;
}
if ( BarL < priceMin )
{
priceMin = BarL;
}
}

LOpen = O[LastBar- 1];
LHigh = H[LastBar- 1];
LLow = L[LastBar- 1];
LClose = C[LastBar- 1];
LVol = V[LastBar- 1];
GfxSelectFont ( "Tahoma" , 9 );
GfxSetTextColor (colorBlack);
GfxTextOut (sym + " O: " +LOpen + " H: " +LHigh + " L: " +LLow + " C: " +LClose + " Vol: " +LVol/ 1000000 + " M", x1+5 , y1+2 );

VolRatio = VolChartHeight / VolHigh ;
Range = priceHigh - priceMin;
Ratio = BarChartHeight / Range ;
PriceLineLevel = Range / NumberPriceLevels;
yHi=(((priceHigh - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
GfxTextOut ( WriteVal (priceHigh, 1.2 ), x1 + BarChartWidth, yHi -8 );
GfxSelectPen ( colorLightGrey );
GfxMoveTo ( x1 , yHi );
GfxLineTo ( x1 + BarChartWidth -5 , yHi );
for ( z = 0 ; z < NumberPriceLevels- 1 ; z++ )
{
PriceLevel = PriceLineLevel*z + priceMin;

yHi=(((PriceLevel - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
GfxTextOut ( WriteVal (PriceLevel, 1.2 ), x1 + BarChartWidth, yHi -8 );
GfxSelectPen ( colorLightGrey );
GfxMoveTo ( x1 , yHi );
GfxLineTo ( x1 + BarChartWidth -5 , yHi );
}

HighestLast = 0 ;
w = 1 ;
sEMAlast = EMAShort[FirstBar];
lEMAlast = EMALong[FirstBar];
vEMAlast = EMAVol[FirstBar];
for ( z = FirstBar; z < LastBar ; z++ )
{
BarH = H[z];
BarL = L[z];
BarO = O[z];
BarC = C[z];
Vol = V[z];
sEMA = EMAShort[z];
lEMA = EMALong[z];
vEMA = EMAVol[z];
BarDay = D[z];
BarMonth = M[z];
BarYear = Y[z];

yO = (((BarO - priceMin )* Ratio)- BarChartHeight ) * -1 + y1 + DataMargin;
yC = (((BarC - priceMin )* Ratio)- BarChartHeight ) * -1 + y1 + DataMargin;
yHi = (((BarH - priceMin )* Ratio)- BarChartHeight ) * -1 + y1 + DataMargin;
yLo = (((BarL - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin ;
ysEMAlast = (((sEMAlast - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
ysEMA = (((sEMA - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
ylEMAlast = (((lEMAlast - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
ylEMA = (((lEMA - priceMin )* Ratio) - BarChartHeight) * -1 + y1 + DataMargin;
vHi = y2 - (Vol * VolRatio) ;
yvEMAlast = y2 - (vEMAlast * VolRatio) ;
yvEMA = y2 - (vEMA * VolRatio) ;

if ( BarH > HighestLast )
{
HighestLast = BarH;
GfxSelectPen ( colorBlue );
}

else
{
GfxSelectPen ( colorRed );
}

GfxMoveTo ( BarWidth * w + x1 + ChartMargin , yHi );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, yLo );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin -1 , yO );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, yO );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin +1 , yC );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, yC );
if ( BarO > BarC)
{
GfxSelectPen ( colorRed );
}
else
{
GfxSelectPen ( colorLime );
}
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , vHi );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y2 );

GfxSelectPen ( colorLime );
GfxMoveTo ( BarWidth * (w -1 ) + x1 + ChartMargin , ysEMAlast );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, ysEMA );
GfxSelectPen ( colorDarkRed );
GfxMoveTo ( BarWidth * (w -1 ) + x1 + ChartMargin , ylEMAlast );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, ylEMA );
GfxSelectPen ( colorBlack );
GfxMoveTo ( BarWidth * (w -1 ) + x1 + ChartMargin , yvEMAlast );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, yvEMA );
w++;

sEMAlast = sEMA ;
lEMAlast = lEMA ;
vEMAlast = vEMA ;

GfxSelectFont ( "Tahoma" , 7 );
GfxSelectPen ( colorLightGrey );

if (BarDay== 1 & notDone )
{
if (BarMonth == 1 ) myLabel =WriteVal (BarYear, 1.0 );
else myLabel =GetMonth(BarMonth);
GfxTextOut (myLabel, BarWidth * w + x1 + ChartMargin - 5 , y2 +DateMargin/3 );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , y2 );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y1 + DataMargin );
notDone = False;
}

if (BarDay== 2 & notDone )
{
if (BarMonth == 1 ) myLabel =WriteVal (BarYear, 1.0 );
else myLabel =GetMonth(BarMonth);
GfxTextOut (myLabel, BarWidth * w + x1 + ChartMargin - 5 , y2 +DateMargin/3 );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , y2 );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y1 + DataMargin );
notDone = False;
}

if (BarDay== 3 & notDone )
{
if (BarMonth == 1 ) myLabel =WriteVal (BarYear, 1.0 );
else myLabel =GetMonth(BarMonth);
GfxTextOut (myLabel, BarWidth * w + x1 + ChartMargin - 5 , y2 +DateMargin/3 );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , y2 );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y1 + DataMargin );
notDone = False;
}

if (BarDay== 4 & notDone )
{
if (BarMonth == 1 ) myLabel =WriteVal (BarYear, 1.0 );
else myLabel =GetMonth(BarMonth);
GfxTextOut (myLabel, BarWidth * w + x1 + ChartMargin - 5 , y2 +DateMargin/3 );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , y2 );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y1 + DataMargin );
notDone = False;
}

if (BarDay== 5 & notDone )
{
if (BarMonth == 1 ) myLabel =WriteVal (BarYear, 1.0 );
else myLabel =GetMonth(BarMonth);
GfxTextOut (myLabel, BarWidth * w + x1 + ChartMargin - 5 , y2 +DateMargin/3 );
GfxMoveTo ( BarWidth * w + x1 + ChartMargin , y2 - VolChartHeight );
GfxLineTo ( BarWidth * w + x1 + ChartMargin, y1 + DataMargin );
notDone = False;
}
if (BarDay== 6 |BarDay== 7 |BarDay== 8 |BarDay== 9 |BarDay== 10 )
{
notDone = True;
}

}
RestorePriceArrays ();
}
}
}
 
I am a new Aussie Stock Forum member so I do not mean to hijack this thread.

I think it is a great idea to post useful scans and code, but just browsing your two pages I see it already goes off track and has many general forum questions.

May I suggest you look at this site which also is attempting to gather useful AmiBroker instruction/scans/codes etc and is well segregated into different topics.

http://amibrokerforum.proboards.com/

It seems to be primarily the work of one excellent code writer but apparently anyone with interesting code can post in the appropriate thread. Hopefully the moderator will keep general forum q and a in the appropriate file.

It appears to me that there are some very experienced and knowledgeable AB users here so I thought they might have some worthwhile contributions.

But I am new here so feel free ignore.

Good trading to all,

Larry
 
Some ASF brains trust required to overcome this problem of getting the total volume for a price range and a horizontal plot. Normal volume is summed for a period of time so I suppose start and end points in time will be required. I was thinking some calculation for price being say > $1 and < $2. Step 3. below is my mental block. Got the easy bit down for this custom VAP chart. Using 10 instead of 12 zones.

Price by Volume from StockCharts

Code:
_SECTION_BEGIN("#1AtPriceVolume");
/*There are four steps involved in the calculation. 
This example is based on closing prices AND the 
default parameter setting (12). 

  1. Find the High-Low range for closing prices for the entire period.  
  2. Divide this range by 12 to create 12 equal price zones.
  3. Total the amount of Volume traded within each price zone.  
  4. Divide the Volume into up Volume AND down Volume (optional). 
*/

SetChartOptions(0, chartHideQuoteMarker);

VAPLookback = Param("VAP Lookback", 100, 1, 500, 1);
HighValue = LastValue(HHV(C, VAPLookback));
LowValue = LastValue(LLV(C, VAPLookback));

HighLowRange = HighValue - LowValue;
HighLowEqualiser = HighLowRange / 10;
TotalVol = Cum(V);

PriceZero   = LowValue;
PriceLine1  = PriceZero  + HighLowEqualiser;
PriceVolZone1 = IIf(L > LowValue & H < PriceLine1, TotalVol, 0);

PriceLine2  = PriceLine1 + HighLowEqualiser;
PriceVolZone2 = IIf(L > PriceLine1 & H < PriceLine2, TotalVol, 0);

PriceLine3  = PriceLine2 + HighLowEqualiser;
PriceLine4  = PriceLine3 + HighLowEqualiser;
PriceLine5  = PriceLine4 + HighLowEqualiser;
PriceLine6  = PriceLine5 + HighLowEqualiser;
PriceLine7  = PriceLine6 + HighLowEqualiser;
PriceLine8  = PriceLine7 + HighLowEqualiser;
PriceLine9  = PriceLine8 + HighLowEqualiser;
PriceLine10 = PriceLine9 + HighLowEqualiser;

PlotLines = ParamToggle("Plot Lines", "Off|On", 1);

if(PlotLines)
{
Plot(PriceZero,   "", colorOrange, ParamStyle("Zero",styleLine|styleThick|styleNoLabel),0,0,15);
Plot(PriceLine1,  "", colorWhite, ParamStyle("Line1",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine2,  "", colorWhite, ParamStyle("Line2",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine3,  "", colorWhite, ParamStyle("Line3",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine4,  "", colorWhite, ParamStyle("Line4",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine5,  "", colorWhite, ParamStyle("Line5",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine6,  "", colorWhite, ParamStyle("Line6",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine7,  "", colorWhite, ParamStyle("Line7",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine8,  "", colorWhite, ParamStyle("Line8",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine9,  "", colorWhite, ParamStyle("Line9",styleDashed|styleNoLabel),0,0,15);
Plot(PriceLine10, "", colorWhite, ParamStyle("Line10",styleDashed|styleNoLabel),0,0,15);
}
_SECTION_END();
 
Top