BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: Better Volume Code
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Better Volume Code

 Post Reply Post Reply Page  <123>
Author
Message
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post 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);



Edited by maximo - 16 Sep 2008 at 4:39pm
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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 : )   
Back to Top
tcoates_au View Drop Down
Newbie
Newbie


Joined: 15 Sep 2008
Posts: 3
Post Options Post Options   Quote tcoates_au Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
paras View Drop Down
Newbie
Newbie


Joined: 15 Dec 2008
Posts: 1
Post Options Post Options   Quote paras Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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 ?
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post 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;
 
 


Edited by maximo - 14 Feb 2009 at 6:48pm
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jalna View Drop Down
Regular
Regular


Joined: 31 Mar 2007
Posts: 95
Post Options Post Options   Quote jalna Quote  Post ReplyReply Direct Link To This Post 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);

Back to Top
 Post Reply Post Reply Page  <123>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz