Print Page | Close Window

Better Volume Code

Printed From: BullCharts Forum
Category: BullCharts
Forum Name: BullScript
Forum Discription: Technical discussion related specifically to the BullScript programming language.
URL: http://www.bullcharts.com.au/forum/forum_posts.asp?TID=501
Printed Date: 20 May 2024 at 2:14pm
Software Version: Web Wiz Forums 9.69 - http://www.webwizforums.com


Topic: Better Volume Code
Posted By: jalna
Subject: Better Volume Code
Date Posted: 09 Sep 2008 at 10:48pm
Can anyone convert this Trade station code to BC. Its a
simple volume analysis. I got it from emini-watch.com. Intereting site

Inputs: Color(Cyan), LowColor(Yellow), ClimaxColor(Red), ChurnColor(Green), ClimaxChurnColor(Magenta), LowChurnColor(White), AvgColor(Red);
Variables: BarColor(Cyan);
 
BarColor = Color;
 
Value1 = V;
Value2 = V*Range;
If Range <> 0 then Value3 = V/Range;
Value4 = Average(Value1,100);
 
If Value1 = Lowest(Value1,20) then BarColor = LowColor;
If Value2 = Highest(Value2,20) then BarColor = ClimaxColor;
If Value3 = Highest(Value3,20) then BarColor = ChurnColor;
If Value2 = Highest(Value2,20) and Value3 = Highest(Value3,20) then BarColor = ClimaxChurnColor;
If Value3 = Lowest(Value3,20) then BarColor = LowChurnColor;
 
Plot1(Value1,"Volume",BarColor);
Plot2(Value4,"Avg",AvgColor);




Replies:
Posted By: jalna
Date Posted: 11 Sep 2008 at 9:39pm

Oh no , has everyone left the building ?

Volume spread analysis is becoming very popular and lots of codes are being written for different programs. There is a book out by Tom Williams called Master the Markets. It can be downloaded for free on the web . His thinking hails from Wyckoffs works


Posted By: maximo
Date Posted: 12 Sep 2008 at 11:56pm

Haha funny one jalna,  okay done! I had trouble finding what the 'Range' value was...

Anyhow paste that link to Tom Williams book if you don't mind Smile
 
 
{ Volume Spread Analysis }
[description="Better Volume Indicator - http://emini-watch.com/free-stuff/volume-indicator/ - http://emini-watch.com/free-stuff/volume-indicator/ "]
Range := High - Low;
Value1 := Volume;
Value2 := Volume*Range;
Value3 := If(Range<>0,Volume/Range,0);
ma(Value1,100,S);
[linestyle=Grounded Bar; width=4]
[Color=Cyan] { Normal }
Volume;
[Color=Gold] { Low volume }
If(Value1 = Lowest(Value1,20),V,undefined);
[Color=Red] { Volume climax }
If(Value2 = Highest(Value2,20),V,undefined);
[Color=Lime Green] { High churn }
If(Value3 = Highest(Value3,20),V,undefined);
[Color=Magenta] { Climax & High churn }
If(Value2 = Highest(Value2,20) and Value3 = Highest(Value3,20),V,undefined);
[Color=Coral] { Low churn }
If(Value3 = Lowest(Value3,20),V,undefined)
 

 



Posted By: jalna
Date Posted: 13 Sep 2008 at 7:26am
Thanks heaps Maximo
Here is the link   http://www.tradethetruth.com/pics/mtmv3.pdf
There are numerous forums that discuss these ideas, one in the US and one in India
http://www.traderji.com/advanced-trading-strategies/23128-volume-spread-analysis-3.html
http://www.traderslaboratory.com/forums/

Better volume is not really VSA code. They are much more complicated


Posted By: jalna
Date Posted: 13 Sep 2008 at 2:30pm
Hi Maximo, here is the code for a version of VSA written for Amibroker.
What do you reckon ? Looks very complicated to me. Tim has been putting up some of his codes on the above forums. He is fine if we want to try and script it. I have posted some stuff at the bottom that he suggested might help for Bull script

SECTION_BEGIN("Volume Analysis");

////////////////////////////////////////////////////////////////////////////////////
//
// Volume Analysis Studies
//
// this code studies price/volume based on information from
//
//   * Master the Markets,
//   * http://www.traderji.com/
//   * http://www.traderslaboratory.com/
//
// I do not claim responsibility or liability for how this code is used.
// If you change the code in any way, please send me an updated copy of
// the changes to:
//
//   tcoates_au@hotmail.com
//
////////////////////////////////////////////////////////////////////////////////////


SetChartOptions(0,chartShowArrows|chartShowDates);

////////////////////////////////////////////////////////////////////////////////////
//
// constants
//
////////////////////////////////////////////////////////////////////////////////////

numDays = 30;
dwWideSpread = 1.8;
dwNarrowSpread = 0.8;
dwSpreadMiddle = 0.5;
dwHighClose = 0.7;
dwLowClose = 0.3;

volNumDays = 30; //numDays;
dwUltraHighVol = 2;
dwVeryHighVol = 2.2; // was 1.8
dwHighVol = 1.8; // was 1.8
dwAboveAvgVol = 1.5; // was 1.8
dwLowVol = 0.8; // was 0.8

//avgVolume = EMA(V, volNumDays);

volSpeedUp = 1; //int(numDays * 0.33);
avgVolume = EMA(EMA(V, volNumDays),volSpeedUp) ;

////////////////////////////////////////////////////////////////////////////////////

longTermAvg = int(EMA(C, 200) * 100);
medTermAvg = int(EMA(C, 50) * 100);
shortTermAvg = int(EMA(C, 10) * 100);
MAvgDir = EMA(C, 13);
MAvgDirTestDays = 30;
MAvgDirHigh = HHV(MAvgDir, MAvgDirTestDays);
MAvgDirLow = LLV(MAvgDir, MAvgDirTestDays);
MAvgDirTrend = IIf(MAvgDir > Ref(MAvgDirHigh, -1), 1,
        IIf(MAvgDir < Ref(MAvgDirLow,-1), -1, 0));


////////////////////////////////////////////////////////////////////////////////////
//
// Classify each bar...
//
////////////////////////////////////////////////////////////////////////////////////


upBar = C > Ref(C,-1);
downBar = C < Ref(C,-1);
closeEqual = int(C*100) == int(Ref(C,-1)*100);
spread = H-L;
avgRange = Sum(spread, numDays) / numDays;
wideRange = spread >= (dwWideSpread * avgRange);
narrowRange = spread <= (dwNarrowSpread * avgRange);
testHighClose = L + (spread * dwHighClose);
testLowClose = L + (spread * dwLowClose);
testCloseMiddle = L + (spread * dwSpreadMiddle);

upClose = C > testHighClose;
upClose12 = C >= testCloseMiddle;
downClose = C < testLowClose;
downClose12 = C < testCloseMiddle;
middleClose = C >= testLowClose AND C <= testHighClose;


aboveAvgVolume = V > (avgVolume * dwAboveAvgVol);
highVolume = V > (avgVolume * dwHighVol);
veryHighVolume = V > (avgVolume * dwVeryHighVol);
ultraHighVolume = V > (avgVolume * dwUltraHighVol);
LowVolume = V < (avgVolume * dwLowVol);

markUpVol = (V > (avgVolume * dwLowVol)) AND (V <= (avgVolume * dwUltraHighVol));
markUpVol2 = markUpVol AND Ref(markUpVol,-1);

narrowBar1 = spread < Ref(spread,-1);
HH = H > Ref(H,-1);
LL = L < Ref(L,-1);
LH = H < Ref(H,-1);

////////////////////////////////////////////////////////////////////////////////////
//
// direction and title
//
////////////////////////////////////////////////////////////////////////////////////

ColorScheme = Param( "Color Scheme", 1, 0, 2, 1);

Trend_U = ( LLV( L, 20 ) + 2 * ATR( 10 ) );
Trend_D = ( HHV( H, 20 ) - 2 * ATR( 10 ) );
TrendUp = C >= Trend_U;
TrendDown = C < Trend_D;

////////////////////////////////////////////////////////////////////////////////////
//
// Basic patterns...
//
//
//see also:
//
// http://www.traderslaboratory.com/forums/151/vsa-volume-spread-analysis-1369-28.html
// http://www.traderslaboratory.com/forums/151/vsa-volume-spread-analysis-1369-7.html#post13343
//
// older definitions...
//
// upThrustBar = downClose AND HH AND (NOT narrowRange); // AND (H > Ref(HHV(H,4),-1)) ; //(C == L) AND;

////////////////////////////////////////////////////////////////////////////////////

testVolLow2 = (V < Ref(V,-1)) AND (V < Ref(V,-2));
testVolHigh2 = (V > Ref(V,-1)) AND (V > Ref(V,-2));
WRD = (spread > Ref(spread,-1)) AND (spread > Ref(spread,-2)) AND (spread > Ref(spread,-3));

////////////////////////////////////////////////////////////////////////////////////
// NO DEMAND

basicNoDemandBar = narrowRange AND Lowvolume AND upBar AND (upClose OR middleClose);
noDemandBar = basicNoDemandBar; // AND TrendUp;

////////////////////////////////////////////////////////////////////////////////////
// NO SUPPLY

basicNoSupplyBar = narrowRange AND LowVolume AND downBar AND (downclose OR middleClose);

// It is also common to find these bars in an up trend which are indications
// of continuation of the trend. They would also be found on consolidation bases.
// During up moves a No supply could indicate non participation from SM.

noSupplyBarUp = basicNoSupplyBar AND TrendUp;

// The No Supply bar is a narrow range Low Volume down bar closing in the lower half.
// The No Supply bars are found in the early Bottom reversals AND indicate strength.

noSupplyBarDown = basicNoSupplyBar AND TrendDown;

////////////////////////////////////////////////////////////////////////////////////
//
// STOPPING VOLUME

stoppingVolume1 = downBar AND upClose12 AND Highvolume;
stoppingVolume2 = Ref(wideRange,-1) AND Ref(HighVolume,-1) AND Ref(downClose12,-1)
        AND upBar AND HH; // AND HighVolume;// AND upClose12;
stoppingVolume3 = Ref(wideRange,-1) AND Ref(HighVolume,-1) AND Ref(downClose12,-1)
        AND upBar AND HighVolume AND upClose12;


stoppingVolume = TrendDown AND (stoppingVolume1 OR StoppingVolume2 OR StoppingVolume3);

////////////////////////////////////////////////////////////////////////////////////
//
// TEST

testBar = narrowRange AND lowvolume AND (C > testCloseMiddle);
testBar = testBar AND (NOT NoDemandBar);

////////////////////////////////////////////////////////////////////////////////////
//
// upThrustBar - see
// http://www.traderji.com/advanced-trading-strategies/23128-volume-spread-analysis-4.html#post202084
//

upThrustBar = WRD AND testVolHigh2 AND TrendUp AND HH AND downClose12 AND NOT Ref(upBar,1);
upThrustBarWithNoDemand = upThrustBar AND LowVolume;
upThrustBarWithSupplyOverDemand = upThrustBar AND testVolHigh2;


absorption = Ref(downbar, -1) AND Ref(highVolume, -1) AND upBar;
support = Ref(downBar,-1) AND (NOT Ref(downClose,-1)) AND Ref(highVolume,-1) AND upBar;


absorptionVolume1 = downBar AND downClose AND Highvolume AND Ref(upBar,1);
absorptionVolume2 = downBar AND downClose12 AND Highvolume AND Ref(upBar,1);


reverseUpThrust = TrendDown AND wideRange AND upClose AND Highvolume;

////////////////////////////////////////////////////////////////////////////////////
//
// Strength and Weakness
//
////////////////////////////////////////////////////////////////////////////////////

weakness1 = downBar AND downClose AND C < Ref(L,-1);
weakness = upThrustBar OR noDemandBar;

weaknessInUpTrend = weakness AND TrendUp;
weaknessInDownTrend = weakness AND TrendDown;

WideRangeAlert1 = wideRange AND aboveAvgVolume AND TrendUp AND (C < O);
WideRangeAlert2 = wideRange AND downClose12 AND TrendUp;

EffortToGoDown = wideRange AND aboveAvgVolume AND TrendUp AND downClose;

MyMarkUp = markUpVol AND Ref(markUpVol,-1) AND (MAvgDirTrend > 0) AND V > Ref(V,-1);
////////////////////////////////////////////////////////////////////////////////////
//
// Display stuff goes here!
//
////////////////////////////////////////////////////////////////////////////////////

OffSet = 0;

PlotShapes( shapeDownArrow*EffortToGoDown , colorIndigo , 0, H);
Offset += IIf(EffortToGoDown, 25, 5); //Offset = abs(Offset);

PlotShapes( shapeSmallSquare*(upThrustBarWithNoDemand OR upThrustBarWithSupplyOverDemand),
        IIf(upThrustBarWithSupplyOverDemand, colorRed, colorDarkRed), 0, H, Offset);
Offset += IIf(upThrustBarWithNoDemand OR upThrustBarWithSupplyOverDemand, 25, 5); //Offset = abs(Offset);

//PlotShapes( shapeHollowDownArrow*weaknessInDownTrend, colorBrown, 0, H, Offset);
//Offset -= IIf(weaknessInDownTrend, 15, 0);

PlotShapes( shapeSmallCircle*NoDemandBar, colorBlack,0, H, Offset);
Offset += IIf(NoDemandBar, 15, 0);



PlotShapes( shapeSmallUpTriangle*stoppingVolume, IIf(stoppingVolume, colorGreen, colorSeaGreen),0, L);
PlotShapes( shapeSmallCircle*testBar , colorBlue,0, L);
PlotShapes( shapeSmallUpTriangle*reverseUpThrust , colorDarkGreen, 0, L);
PlotShapes( shapeSmallCircle*(noSupplyBarUp OR noSupplyBarDown), colorPink,0, L);
//PlotShapes( shapeSmallUpTriangle*MyMarkUp , colorSeaGreen, 0, L);

//Plot( testCloseMiddle, "", colorBlack, styleDots );
//PlotShapes( shapeSmallCircle*markUpVol2, colorBrown,0, L, negY);


//Plot( TREND_U, "", colorRed);

Color0 = colorBlack;
Color1 = IIf(wideRange, colorBlue,
        IIf( narrowRange, colorLightBlue,
        IIf( upBar, colorDarkGreen,
        IIf( downBar, colorRed, colorDarkGrey))));
Color2 = IIf( TrendUp, colorDarkGreen,
        IIf( TrendDown, colorRed, colorBlack));

Color = IIf(ColorScheme == 0, Color0,
        IIf(ColorScheme == 1, Color1, Color2));

Plot( C, "Close", Color, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

////////////////////////////////////////////////////////////////////////////////////
//
// trend direction...
//
////////////////////////////////////////////////////////////////////////////////////


Dir = EncodeColor(colorBlack) + "Volume: " +
        WriteIf(ultraHighVolume , "Ultra High",
        WriteIf(veryHighVolume , "Very High",
        WriteIf(highVolume , "High",
        WriteIf(lowVolume , "Low", "Average")))) + " " +

        // spread

        EncodeColor(colorBlack) + "Spread: " +
               WriteIf(wideRange , EncodeColor(colorBlue) + "Wide",
               WriteIf(narrowRange , EncodeColor(colorLightBlue) + "Narrow",
                      EncodeColor(colorBlack) + "Average")) + ", " +

        EncodeColor(colorBlack) + "Close: " +
               WriteIf(upClose , EncodeColor(colorGreen) + "Up",
               WriteIf(downClose , EncodeColor(colorRed) + "Down",
               EncodeColor(colorBlack) + "Middle")) + EncodeColor(colorBlack) + ",\n" +

        EncodeColor(colorBlack) + "Long Term: " +
               WriteIf(longTermAvg < Ref(longTermAvg,-1),
                      EncodeColor(colorRed) + "Down",
                      WriteIf(longTermAvg == Ref(longTermAvg ,-1),
                               EncodeColor(colorBlack) + "Flat",
                      EncodeColor(colorGreen) + "Up")) +
        EncodeColor(colorBlack) + ", " + "Med Term: " +
               WriteIf(medTermAvg < Ref(medTermAvg ,-1),
                      EncodeColor(colorRed) + "Down",
                      WriteIf(medTermAvg == Ref(medTermAvg ,-1),
                               EncodeColor(colorBlack) + "Flat",
                      EncodeColor(colorGreen) + "Up")) +
        EncodeColor(colorBlack) + ", " + "Short Term: " +
               WriteIf(shortTermAvg < Ref(shortTermAvg,-1),
                      EncodeColor(colorRed) + "Down",
                      WriteIf(shortTermAvg == Ref(shortTermAvg,-1),
                               EncodeColor(colorBlack) + "Flat",
                      EncodeColor(colorGreen) + "Up")) +
        EncodeColor(colorBlack) + "\n" +
               WriteIf(MAvgDirTrend == 1, "Up", "") +
               WriteIf(MAvgDirTrend == 0, "No Direction", "") +
               WriteIf(MAvgDirTrend == -1, "Down", "");


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)",
        O, H, L, C, SelectedValue( ROC( C, 1 ) )) + "\n" + Dir);
_SECTION_END();




TIP FOR   Bullscript users...

Keep in mind that it is still a work in progress. I am somewhat happy with it.

Couple of suggestion though...

Change assignment statements from = to :=

for example...

X = Y;

becomes

X := Y;

Since it (Bullscript) uses Pascal style assignments, you would probably change != to <> and == to = and call to Ref get convered to Hist. Another example (Joels script...)
NoDemand = C>Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2);
NoDemand2 = C==Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND Ref(C,-1)>Ref(C,-2);

NoSupply = C<Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2);
NoSupply2= C==Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND Ref(C,-1)<Ref(C,-2);

The corresponding bullscript should (?) like
NoDemand := C>Hist(C,1) AND V<Hist(V,1) AND V<Hist(V,2);
NoDemand2 := C=Hist(C,1) AND V<Hist(V,1) AND V<Hist(V,2) AND Hist(C,1)>Hist(C,2);

NoSupply := C<Hist(C,1) AND V<Hist(V,1) AND V<Hist(V,2);
NoSupply2:= C=Hist(C,1) AND V<Hist(V,1) AND V<Hist(V,2) AND Hist(C,1)<Hist(C,2);




Posted By: maximo
Date Posted: 14 Sep 2008 at 4:53am

OMG jalna that's a fair chunk of code!

I can see a couple of functions there that I have no idea what they do..   like WriteIf( ),  and EncodeColor()  other than that it's a step by step process one line at  a time.  It's helpful if you can see what it's supposed to look like on the other platform,  a picture says a 1000 words they say.   Like the video for the better volume indicator, which  also helps to make sure every step you've taken is a correct.      Not sure if bullscript can do all those kinds of plots like PlotShapes( shapeSmallUpTriangle), might be able to substitute up arrows or something.        
I will have a look at the links you've pasted, thanks! 


Posted By: jalna
Date Posted: 14 Sep 2008 at 6:44pm
Hi guys, here is a link from Tim on how the code works and looks
http://s289.photobucket.com/albums/ll230/tcoates_au/


Posted By: tcoates_au
Date Posted: 15 Sep 2008 at 8:16am
Hi,

My name is Tim Coates and I wrote the script above. The script itself is OK. You have to note there are 3 parts to the script above. The first part is volume analysis, and that is the top part of the script.

The next part is direction and that is implemented quite simply using moving averages (though these are not plotted on the chart as such!). I also use a 13 day moving average to determine whether trend direction is flat or not using HHV and LLV. Its an idea from Trading for a living. Found it to be more effective than either the short or medium term averages.

Finally there is the plotting of the chart and associated "alerts". I have 2 (or 3) coloring schemes - plain black, bars colored based on wide range, narrow range etc., and the last color scheme is an ATR based green and red. (On this last color scheme, you can find many links on the Internet to code for Jim Bergs volatility which you should be able to modify as necessary)

The alerts are plotted as either dots or small up/down triangles. Amibroker gives you numerous choices here. The main reason why I used small up/down triangles is so they don't get in the way of the charts compared with a regular trianges.

In the 2nd version I switched to dots as they are less intrusive - especially when you plot all types of alerts on a chart, either above the high or below the low.

So you should be able to substitute arrow as you suggested.

Hope that helps. (if you have any questions about the script, I don't mind if you send me an email)

Cheers,
Tim



Posted By: trev04
Date Posted: 15 Sep 2008 at 7:31pm
Hi Tim,
I have been reading and noting data from "Master The Markets" for a few weeks now and am fascinated with the concept!
After reading from BullCharts forum, and comming across your post, I have become even more interested in utilizing the indicators more.  So I have been attempting to copy and change aspects of the code to suit BC, yet am still unable to get it to work!!!
Would you please be able to show me exactly how to get the code to work in BC?

The first part is volume analysis: Is that from "SetChartOptions... to LH = H < Ref(H,-1);"
The next part is direction: Is that from "ColorScheme = Param... to ?"
There are so many parts of codes that you have showed,  yet I cannot assertain how that all combine together!!! It is probably just me that is not following the code, yet I would appreciate very much If you could assist me in the following of your explanation.

I have been thrilled with the information I have obtained of the whole concept, and am looking forward to utilising this in Bullcharts successfully.

Thankyou again for any assistance you can give me.
Best Regards
Trevor Jones


Posted By: tcoates_au
Date Posted: 16 Sep 2008 at 11:55am
Not sure what code others have converted as yet. But here is the first bit...

numDays := 30;
dwWideSpread := 1.8;
dwNarrowSpread := 0.8;
dwSpreadMiddle := 0.5;
dwHighClose := 0.7;
dwLowClose := 0.3;

volNumDays := 30;
dwUltraHighVol := 2;
dwVeryHighVol := 2.2;
dwHighVol := 1.8;
dwAboveAvgVol := 1.5;
dwLowVol := 0.8;

volSpeedUp := numDays * 0.33;
avgVolume := MA(MA(V, volNumDays, S),volSpeedUp, S) ;

upClose := C > testHighClose;
upClose12 := C >= testCloseMiddle;
downClose := C < testLowClose;
downClose12 := C < testCloseMiddle;
middleClose := C >= testLowClose AND C <= testHighClose;

aboveAvgVolume := V > (avgVolume * dwAboveAvgVol);
highVolume := V > (avgVolume * dwHighVol);
veryHighVolume := V > (avgVolume * dwVeryHighVol);
ultraHighVolume := V > (avgVolume * dwUltraHighVol);
LowVolume := V < (avgVolume * dwLowVol);

Combine that with

[Color=Cyan] { Normal }
Volume;
[Color=Gold] { Low volume }
If(highVolume,V,undefined);

(assuming you want to color volume bars) and you are off to a start?!?

Tim

PS. I dont have or use BullCharts so what I work out is partially guess work. Jalna asked me if he could post my code here. I said Yes. So whatever help I give is ....



Posted By: maximo
Date Posted: 16 Sep 2008 at 3:32pm

Thanks Tim,

I've spent a little time on it today getting the JB paint bar coloring done.   Just need to code
the colors for the Volume bars, Averages and Point markers.  It's a start and can serve
 as a base for others to work on if they wish. 
  Thanks for your script and the useful analysis technique.
 

[description="Volume Spread Analysis - Tim Coates"]

{ Constants }

numDays := 30;

dwWideSpread := 1.8;

dwNarrowSpread := 0.8;

dwSpreadMiddle := 0.5;

dwHighClose := 0.7;

dwLowClose := 0.3;

volNumDays := 30;

dwUltraHighVol := 2;

dwVeryHighVol := 2.2;

dwHighVol := 1.8;

dwAboveAvgVol := 1.5;

dwLowVol := 0.8;

{ Moving Averages }

volSpeedUp := int(numDays * 0.33);

avgVolume := MA(MA(V,volNumDays,E),volSpeedUp,E);

longTermAvg := int(MA(C,200,E) * 100);

medTermAvg := int(MA(C,50,E) * 100);

shortTermAvg := int(MA(C,10,E) * 100);

MAvgDir := MA(C,13,E);

MAvgDirTestDays:= 30;

MAvgDirHigh := HHV(MAvgDir, MAvgDirTestDays);

MAvgDirLow := LLV(MAvgDir, MAvgDirTestDays);

MAvgDirTrend := If(MAvgDir > Ref(MAvgDirHigh, -1), 1, If(MAvgDir < Ref(MAvgDirLow,-1), -1, 0));

{ Classify each bar }

upBar:= C > Ref(C,-1);

downBar:= C < Ref(C,-1);

closeEqual:= int(C*100) = int(Ref(C,-1)*100);

spread := H-L;

avgRange := Sum(spread, numDays) / numDays;

wideRange := spread >= (dwWideSpread * avgRange);

narrowRange := spread <= (dwNarrowSpread * avgRange);

testHighClose := L + (spread * dwHighClose);

testLowClose := L + (spread * dwLowClose);

testCloseMiddle := L + (spread * dwSpreadMiddle);

upClose := C > testHighClose;

upClose12 := C >= testCloseMiddle;

downClose := C < testLowClose;

downClose12 := C < testCloseMiddle;

middleClose := C >= testLowClose AND C <= testHighClose;

aboveAvgVolume := V > (avgVolume * dwAboveAvgVol);

highVolume := V > (avgVolume * dwHighVol);

veryHighVolume := V > (avgVolume * dwVeryHighVol);

ultraHighVolume := V > (avgVolume * dwUltraHighVol);

LowVolume := V < (avgVolume * dwLowVol);

markUpVol := (V > (avgVolume * dwLowVol)) AND (V <= (avgVolume * dwUltraHighVol));

markUpVol2:= markUpVol AND Ref(markUpVol,-1);

narrowBar1 := spread < Ref(spread,-1);

HH := H > Ref(H,-1);

LL := L < Ref(L,-1);

LH := H < Ref(H,-1);

{ Direction and title }

Trend_U := (LLV(L,20) + 2 * ATR(10));

Trend_D := (HHV(H,20) - 2 * ATR(10));

TrendUp := C >= Trend_U;

TrendDown := C < Trend_D or C < Trend_U;

[linestyle=pricecolor]

[color=rgb(98,217,98)] {lime green}

If(TrendUp,1,0);

[color=rgb(226,118,118)] {red}

If(TrendDown,1,0);

[linestyle=Grounded Bar; width=2]

[color=rgb(226,118,118)] {red}

If(Close<=Open,Volume,undefined);

[Color=Lime Green]

If(Close>Open,Volume,undefined);



Posted By: jalna
Date Posted: 16 Sep 2008 at 5:05pm
Hi Guys , Day from Bull Charts will have a go when he gets back from holiday and see if he can help. We might have it solved anyway : )   


Posted By: tcoates_au
Date Posted: 16 Sep 2008 at 6:05pm
Note the following references....

longTermAvg := int(MA(C,200,E) * 100);

medTermAvg := int(MA(C,50,E) * 100);

shortTermAvg := int(MA(C,10,E) * 100);

MAvgDir := MA(C,13,E);


Do not have anything to do with VSA. These are just averages that I calculate to display as part of the page header when the user moves from one bar to the next.

As far as MAvgDir is concerned, that is only used to determine whether the direction is up, down or flat, using HHV, LLV. The other moving averages (as far as direction is concerned) are just up or down based on today vs yesterday.

The references to EncodeColor are so that that I can plot the long, medium and short term average indicators (in the chart header) are colors red or green depending on whether up or down. It is purely a visual thing.

You will also find that I color the volume label and bar spread in the chart header also. Again, this is just a visual thing (for me).

Since the moving averages are not really part of VSA (or whatever you want to call it!) you dont need to have these as part of the script.

Secondly, the trend up and down part allow me/you to color bars in the same way as traderguider does (?). That is if the close (doing this from memory) is greater than LLV of last N days by 2 * ATR(10), then color green. This code is also straight from an idea on

http://ilmusaham.wordpress.com/2008/06/01/amibroker-the-truth-about-volatility/

which was also coded on other traders tip and tricks coding forum. Again this is not VSA but makes the chart prettier.

Finally, the alerts that you get from the script might/will be different to what you get from other VSA related documents. But is close, and you still see alerts like stopping volume and weakness and no-demand which are the main things to look for?!?

Tim


Posted By: paras
Date Posted: 15 Dec 2008 at 11:52pm

Hello eveyone,

This is my frst post...and i am happy to find " volume " lovers here ....
the formla of [ VSA] for amibroker can be downloaded from vpanalysis.blogspot ...it has been coded by Mr Karthik....
**Mr karthik ..who  discussed  VSA on traderji
 
I hope you all will love this  afl ..
Thank you


Posted By: jalna
Date Posted: 16 Jan 2009 at 10:44am
Hi Guys , Here is the script with the marker code that Day has written for me. It shows how to write code for markers which is good to know too.


[description="Volume Spread Analysis - Tim Coates"]
[target=price]
{ Constants }

numDays := 30;

dwWideSpread := 1.8;

dwNarrowSpread := 0.8;

dwSpreadMiddle := 0.5;

dwHighClose := 0.7;

dwLowClose := 0.3;

volNumDays := 30;

dwUltraHighVol := 2;

dwVeryHighVol := 2.2;

dwHighVol := 1.8;

dwAboveAvgVol := 1.5;

dwLowVol := 0.8;

{ Moving Averages }

volSpeedUp := int(numDays * 0.33);

avgVolume := MA(MA(V,volNumDays,E),volSpeedUp,E);

longTermAvg := int(MA(C,200,E) * 100);

medTermAvg := int(MA(C,50,E) * 100);

shortTermAvg := int(MA(C,10,E) * 100);

MAvgDir := MA(C,13,E);

MAvgDirTestDays:= 30;

MAvgDirHigh := HHV(MAvgDir, MAvgDirTestDays);

MAvgDirLow := LLV(MAvgDir, MAvgDirTestDays);

MAvgDirTrend := If(MAvgDir > Ref(MAvgDirHigh, -1), 1, If(MAvgDir < Ref(MAvgDirLow,-1), -1, 0));

{ Classify each bar }

upBar:= C > Ref(C,-1);

downBar:= C < Ref(C,-1);

closeEqual:= int(C*100) = int(Ref(C,-1)*100);

spread := H-L;

avgRange := Sum(spread, numDays) / numDays;

wideRange := spread >= (dwWideSpread * avgRange);

narrowRange := spread <= (dwNarrowSpread * avgRange);

testHighClose := L + (spread * dwHighClose);

testLowClose := L + (spread * dwLowClose);

testCloseMiddle := L + (spread * dwSpreadMiddle);

upClose := C > testHighClose;

upClose12 := C >= testCloseMiddle;

downClose := C < testLowClose;

downClose12 := C < testCloseMiddle;

middleClose := C >= testLowClose AND C <= testHighClose;

aboveAvgVolume := V > (avgVolume * dwAboveAvgVol);

highVolume := V > (avgVolume * dwHighVol);

veryHighVolume := V > (avgVolume * dwVeryHighVol);

ultraHighVolume := V > (avgVolume * dwUltraHighVol);

LowVolume := V < (avgVolume * dwLowVol);

markUpVol := (V > (avgVolume * dwLowVol)) AND (V <= (avgVolume * dwUltraHighVol));

markUpVol2:= markUpVol AND Ref(markUpVol,-1);

narrowBar1 := spread < Ref(spread,-1);

HH := H > Ref(H,-1);

LL := L < Ref(L,-1);

LH := H < Ref(H,-1);

{ Direction and title }

Trend_U := (LLV(L,20) + 2 * ATR(10));

Trend_D := (HHV(H,20) - 2 * ATR(10));

TrendUp := C >= Trend_U;

TrendDown := C < Trend_D or C < Trend_U;
{----------------------}
testVolLow2 := (V < Ref(V,-1)) AND (V < Ref(V,-2));
testVolHigh2 := (V > Ref(V,-1)) AND (V > Ref(V,-2));
WRD := (spread > Ref(spread,-1)) AND (spread > Ref(spread,-2)) AND (spread > Ref(spread,-3));

{---UpThrustbar--------}
upThrustBar := WRD AND testVolHigh2 AND TrendUp AND HH AND downClose12 AND NOT Ref(upBar,1);
upThrustBarWithNoDemand := upThrustBar AND LowVolume;
upThrustBarWithSupplyOverDemand := upThrustBar AND testVolHigh2;

absorption := Ref(downbar, -1) AND Ref(highVolume, -1) AND upBar;
support := Ref(downBar,-1) AND (NOT Ref(downClose,-1)) AND Ref(highVolume,-1) AND upBar;


absorptionVolume1 := downBar AND downClose AND Highvolume AND Ref(upBar,1);
absorptionVolume2 := downBar AND downClose12 AND Highvolume AND Ref(upBar,1);


reverseUpThrust := TrendDown AND wideRange AND upClose AND Highvolume;
{----Stopping Volume-------}
stoppingVolume1 := downBar AND upClose12 AND Highvolume;
stoppingVolume2 := Ref(wideRange,-1) AND Ref(HighVolume,-1) AND Ref(downClose12,-1)
        AND upBar AND HH;
stoppingVolume3 := Ref(wideRange,-1) AND Ref(HighVolume,-1) AND Ref(downClose12,-1)
        AND upBar AND HighVolume AND upClose12;


stoppingVolume := TrendDown AND (stoppingVolume1 OR StoppingVolume2 OR StoppingVolume3);
{--------No Supply ------------}
basicNoSupplyBar := narrowRange AND LowVolume AND downBar AND (downclose OR middleClose);
noSupplyBarUp := basicNoSupplyBar AND TrendUp;
noSupplyBarDown := basicNoSupplyBar AND TrendDown;
{--------No Demand--------------}

basicNoDemandBar := narrowRange AND Lowvolume AND upBar AND (upClose OR middleClose);
noDemandBar := basicNoDemandBar;
{-----TestBar-----------------}
testBar0 := narrowRange AND lowvolume AND (C > testCloseMiddle);
testBar := testBar0 AND (NOT NoDemandBar);
{----Strength & Weakness---}
weakness1 := downBar AND downClose AND C < Ref(L,-1);
weakness := upThrustBar OR noDemandBar;

weaknessInUpTrend := weakness AND TrendUp;
weaknessInDownTrend := weakness AND TrendDown;

WideRangeAlert1 := wideRange AND aboveAvgVolume AND TrendUp AND (C < O);
WideRangeAlert2 := wideRange AND downClose12 AND TrendUp;
MyMarkUp := markUpVol AND Ref(markUpVol,-1) AND (MAvgDirTrend > 0) AND V > Ref(V,-1);
EffortToGoDown := wideRange AND aboveAvgVolume AND TrendUp AND downClose;
Spread_ := If (wideRange,"wide",If(narrowRange,"narrow","average"));

[name="";linestyle=marker; marker=type1; tooltip="EffortToGoDown"]
EffortToGoDown;

[name="UpThrustWithNoDemand";linestyle=points;tooltip="UpThrustWithNoDemand";color=Red]
UtNodemand:= If(upThrustBarWithNoDemand,L,undefined);
UtNodemand-(L*0.005);

[name="upThrustBarWithSupplyOverDemand";linestyle=points;tooltip="upThrustBarWithSupplyOverDemand";color="Dark Red"]
Utdemand:= If(upThrustBarWithSupplyOverDemand,L,undefined);
Utdemand-(L*0.005);

[name="weaknessInDownTrend";linestyle=points;tooltip="weaknessInDownTrend";color="Brown"]
weaknessin:= If(weaknessInDownTrend,L,undefined);
weaknessin-(L*0.008);

[name="NoDemandBar";linestyle=points;tooltip="NoDemandBar";color="Black"]
nodB:= If(NoDemandBar,H,undefined);
nodB + (H*0.005);

[name="stoppingVolume";linestyle=points;tooltip="stoppingVolume";color="Sea Green"]
sv:= If(stoppingVolume,L,undefined);
sv-(L*0.011);

[name="testBar";linestyle=points;tooltip="testBar";color="Blue"]
tb:= If(testBar,L,undefined);
tb-(L*0.015);

[name="reverseUpThrust";linestyle=points;tooltip="reverseUpThrust";color="Dark Green"]
rt:= If(reverseUpThrust,L,undefined);
rt-(L*0.018);

[name="noSupplyBarUpORDown";linestyle=points;tooltip="noSupplyBarUpORDown";color="Pink"]
nsbud:= If(noSupplyBarUp OR noSupplyBarDown,L,undefined);
nsbud-(L*0.022);

[name="MyMarkUp";linestyle=points;tooltip="MyMarkUp";color="Sea Green"]
mmu:= If(MyMarkUp,L,undefined);
mmu-(L*0.022);


You may need to put the volume code in as well to make it work

[description="Volume Spread Analysis - Tim Coates"]
{ Constants }
numDays := 30;
dwWideSpread := 1.8;
dwNarrowSpread := 0.8;
dwSpreadMiddle := 0.5;
dwHighClose := 0.7;
dwLowClose := 0.3;
volNumDays := 30;
dwUltraHighVol := 2;
dwVeryHighVol := 2.2;
dwHighVol := 1.8;
dwAboveAvgVol := 1.5;
dwLowVol := 0.8;
{ Moving Averages }
volSpeedUp := int(numDays * 0.33);
avgVolume := MA(MA(V,volNumDays,E),volSpeedUp,E);
longTermAvg := int(MA(C,200,E) * 100);
medTermAvg := int(MA(C,50,E) * 100);
shortTermAvg := int(MA(C,10,E) * 100);
MAvgDir := MA(C,13,E);
MAvgDirTestDays:= 30;
MAvgDirHigh := HHV(MAvgDir, MAvgDirTestDays);
MAvgDirLow := LLV(MAvgDir, MAvgDirTestDays);
MAvgDirTrend := If(MAvgDir > Ref(MAvgDirHigh, -1), 1, If(MAvgDir < Ref(MAvgDirLow,-1), -1, 0));
{ Classify each bar }
upBar:= C > Ref(C,-1);
downBar:= C < Ref(C,-1);
closeEqual:= int(C*100) = int(Ref(C,-1)*100);
spread := H-L;
avgRange := Sum(spread, numDays) / numDays;
wideRange := spread >= (dwWideSpread * avgRange);
narrowRange := spread <= (dwNarrowSpread * avgRange);
testHighClose := L + (spread * dwHighClose);
testLowClose := L + (spread * dwLowClose);
testCloseMiddle := L + (spread * dwSpreadMiddle);
upClose := C > testHighClose;
upClose12 := C >= testCloseMiddle;
downClose := C < testLowClose;
downClose12 := C < testCloseMiddle;
middleClose := C >= testLowClose AND C <= testHighClose;
aboveAvgVolume := V > (avgVolume * dwAboveAvgVol);
highVolume := V > (avgVolume * dwHighVol);
veryHighVolume := V > (avgVolume * dwVeryHighVol);
ultraHighVolume := V > (avgVolume * dwUltraHighVol);
LowVolume := V < (avgVolume * dwLowVol);
markUpVol := (V > (avgVolume * dwLowVol)) AND (V <= (avgVolume * dwUltraHighVol));
markUpVol2:= markUpVol AND Ref(markUpVol,-1);
narrowBar1 := spread < Ref(spread,-1);
HH := H > Ref(H,-1);
LL := L < Ref(L,-1);
LH := H < Ref(H,-1);
{ Direction and title }
Trend_U := (LLV(L,20) + 2 * ATR(10));
Trend_D := (HHV(H,20) - 2 * ATR(10));
TrendUp := C >= Trend_U;
TrendDown := C < Trend_D or C < Trend_U;
[linestyle=pricecolor]
[color=green] {lime green}
If(TrendUp,1,0);
[color=red] {red}
If(TrendDown,1,0);
[linestyle=Grounded Bar; width=2]
[color=red] {red}
If(Close<=Open,Volume,undefined);
[Color=Lime Green]
If(Close>Open,Volume,undefined);


It takes awhile for my computer to digest all the info but I have an old one.
What do you think, code needs tweaking ?


Posted By: jalna
Date Posted: 16 Jan 2009 at 10:49am
Day sent the above to me in two different folders to put into custom indicators.
Just beware there are 2 different sections in the above and name them each differently eg VSA1 and VSA2 to go into the Custom Indicator folder


Posted By: jalna
Date Posted: 14 Feb 2009 at 5:15pm
Hi Maximo,( the star of BC forum,) is it possible to scan from the Bettervolume code. I have tried but to no avail. What would need to be changed. "If true" does not work etc.
I'm looking for low churn days in particular. other scans are already written in BC for high volume etc


Posted By: maximo
Date Posted: 14 Feb 2009 at 6:40pm
Hi Jalna,
 
That shouldn't be too difficult.. I guess help is easiest  given when you've already written the code, be great if someone had written it for me lol
 
Bullscan can only act on variables and the Better volume code is only using IF commands to display the volume bar colours, so to get the scanner to be able to scan for them you need to put them in a variable.  Then the number for the variable should appear in the list for scanning using the better volume indicator.
 
currently:
If(Value3 = Lowest(Value3,20),V,undefined)
 
change to this:
lowchurn := If(Value3 = Lowest(Value3,20),V,undefined)
lowchurn;
 
 


Posted By: jalna
Date Posted: 14 Feb 2009 at 7:23pm
Thanks very much Maximo, really appreciate your help. I'm afraid my brain doesn't seem to work when it comes to computer code. I can draw and paint well though : )
I will have a go changing the code for the whole indicator then, and see how well i do, looks easy
Thanks


Posted By: jalna
Date Posted: 14 Feb 2009 at 9:19pm
Hi Mazimo, just having trouble with this one and how to write in the --and value 3. It says I perhaps have a semicolon missing.
 If and when you have time. I have tried a lor of different ways , putting brackets here and there.
Also it didn't like the above formula but if i left off the last low churn; line it accepted it


lowchurn := If(Value3 = Lowest(Value3,20),V,undefined)
lowchurn;



[Color=Magenta] { Climax & High churn }
If(Value2 = Highest(Value2,20) and Value3 = Highest(Value3,20),V,undefined);



Posted By: maximo
Date Posted: 14 Feb 2009 at 11:37pm
Ah I must be getting old...  every line should end with  a semicolon; and I forgot to add them, so just add it to the end of the line and it should accept :)


Posted By: maximo
Date Posted: 03 Sep 2009 at 3:47am
Here's a Volume indicator I created to view Volume breakouts.
 
features:
  When blue line crosses the purple line the 5 day average volume is above the 50 day average volume.
  Green Volume bars indicate a 10 day high of volume.
  Red short bars indicate that Volume bar is 600% or greater.
 
Parameters can be changed to suit.
 

{ Volume Breakouts - Max }

[Description="Apply averages 21 and 150sma onto price."]

p1:= input("Volume average small",5,1);

p2:= input("Volume average large",50,1);

p3:= input("Volume Bar Highest in period",10,1);

p4:= input("Volume Bar Spike increase%",600,1);

vp:=((V-ref(V,-1))/ref(V,-1))*100 > p4;

[linestyle=Grounded Bar; Color=coral]

If(Volume <= hist(HHV(V,p3),1),V*0.5,undefined);

{ 10 day Volume breakouts are green bars }

[Color=lime green]

If(Volume > hist(HHV(V,p3),1),V*0.5,undefined);

{ 600% Volume increase are short red bars }

[Color=red; width=2]

If(vp,1,undefined);

[linestyle=solid; width=1; color=blue]

ma(Volume,p1,E);

[color=Medium Orchid]

ma(Volume,p2,E);

 
 



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums® version 9.69 - http://www.webwizforums.com
Copyright ©2001-2010 Web Wiz - http://www.webwiz.co.uk