[Code] Help needed fpr code fixing

Questions about MultiCharts and user contributed studies.
2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

[Code] Help needed fpr code fixing

Postby 2haerim » 16 Jun 2009

Code: Select all

[IntrabarOrderGeneration=TRUE];

Input: PerVolDiff(1000), TicksToSkip(1), ExTime(1500);

var: intrabarpersist uv_acc(0), intrabarpersist dv_acc(0), intrabarpersist uv_dv(0), TickCount(0);
var: intrabarpersist BP(0), intrabarpersist PrevBP(0), intrabarpersist DP(0);

if d<>d[1] then begin
TickCount= 0;
uv_acc = 0;
dv_acc = 0;
PrevBP = 0;
end;

TickCount += 1;
uv_acc += UpTicks;
dv_acc += DownTicks;

if TickCount >= TicksToSkip then begin
uv_acc += UpTicks;
dv_acc += DownTicks;
uv_dv = uv_acc - dv_acc;
BP = IntPortion(uv_dv / PerVolDiff);
if d=1090615 {and time_s<=093000} then
print(d:8:0, t:8:0, " ", TickCount:6:0, " ", UpTicks:6:0, " ", DownTicks:6:0,
" ", uv_acc:6:0, " ", dv_acc:6:0, " ", " ", uv_dv:6:0, BP:6:0, " ", PrevBP:6:0, " ", DP:6:0);
if BP > 0 then begin
DP = BP - PrevBP;
{ if d=1090615 {and time_s<=093000} then
print(d:8:0, t:8:0, " ", TickCount:6:0, " ", UpTicks:6:0, " ", DownTicks:6:0,
" ", uv_acc:6:0, " ", dv_acc:6:0, " ", " ", uv_dv:6:0, BP:6:0, " ", PrevBP:6:0, " ", DP:6:0);}
if DP > 0 then begin
Buy DP contracts Next Bar at Market;
PrevBP = BP;
end
else if DP < 0 then begin
if PrevBP > 0 then begin
if PrevBP >= -DP then begin
Sell -DP contracts Next Bar at Market;
PrevBP += DP;
end
else {if PrevBP < -DP then} begin
Sell PrevBP contracts Next Bar at Market;
PrevBP = 0;
end;
end;
end
else {if DP = 0 then}begin
PrevBP = BP;
end;
end
else begin
if PrevBP > 0 then begin
Sell PrevBP contracts Next Bar at Market;
PrevBP = 0;
end;
end;
end
else begin
end;

if time >= ExTime then begin
Sell All Contracts Next bar at Market;
BuyToCover All Contracts Next Bar at Market;
end;

SetExitOnClose;
Above code is to keep the # of buy positions depending on the difference of accumulated up vol and down vol. For example, if the current difference between uv_acc and dv_acc is 3000, then the #of buy positions should be maintained as 3. If it is 5000, 5 buy positions. If it gets below 0, then clear all buy positions.

And one thing to note is to exclude the first tick of the day in the calculation of uv_acc and dv_acc.

The problem with this code is that: the value of uv_acc and dv_acc gets too big to be realistic.

This was tested on a 1 min chart with Trade Volume on.

Could anybody point out what is wrong?

HR

Return to “MultiCharts”