PureBytes Links
Trading Reference Links
|
Hi all.. whenever I use the DeMark Demand formula with Amibroker, the
program freez and hang... it sometimes takes more than 5 minutes to
upload... is there any soultion....
_SECTION_BEGIN("DeMark's Demand ");
/* DeMark's Demand and Supply Line Trading System -
Original code by marmal417, Johsun, Dimitris Tsokakis
with variations by Bill Barnard, 2/19/04.
The numerous loops make for a slow calculation
when the stock of interest has more than two
or three years of data. Suggest making short-lived
duplicates of stocks to be studied.
Colors set for use with black background */
/* Following line allows changing the number of days which
must preceed a pivot. "equal" allows a pivot which is
equal in value to the preceeding day. */
rules = Param("1-1day, 2-Equal, 3-3day", 3,1,3,1);
/* Following line allows the use of DeMark's three
qualifiers for a legitimate breakout. */
Q_On = Param("Use Qualifier", 1,0,1,1);
extension = 20; // length of demand/supply line extension
Plot(C,"",colorWhite,styleCandle | styleNoLabel);
prevLow = IIf(Ref(L,-1)<Ref(C,-2), Ref(L,-1), Ref(C,-2));
prevHigh = IIf(Ref(H,-1)>Ref(C,-2), Ref(H,-1), Ref(C,-2));
pivothigh = IIf(rules==1, prevHigh<H AND H>Ref(H,1),
IIf(rules==2, prevHigh<=H AND H>Ref(H,1),
IIf(rules==3, Ref(C,-3)<H AND Ref(H,-2)<H AND
Ref(H,-1)<H AND H>=Ref(H,1), 0)));
pivotlow = IIf(rules==1, prevLow>L AND L<Ref(L,1),
IIf(rules==2, prevLow>=L AND L<Ref(L,1),
IIf(rules==3, Ref(C,-3)>L AND Ref(L,-2)>L AND
Ref(L,-1)>L AND L<=Ref(L,1), 0)));
/* Following section loops through the data to develop
all the Buy/Sell points for back testing purposes. */
pLo = IIf(pivotLow==1, L, 1000000);
pHi = IIf(pivotHigh==1, H, 0);
By = 0; Sel = 0; CountHi = 0; CountLo = 0;
for (i=3; i<BarCount; i++)
{
if (plo[i]<1000000)
{
CountLo = CountLo + 1;
j = i;
while (plo[j-0]>=plo[i] AND j>2)
{
pplo[j-1] = plo[j-1];
j = j - 1;
}
dLine = IIf(CountLo<2 OR pplo[j]>plo[i],Null,
LineArray(j,pplo[j],i,plo[i],1));
exit = 0;
for (k = i+2; exit==0 AND k<BarCount; k++)
{
SellQualifier = IIf(Q_On, C[k-1]>C[k-2] OR
(2*C[k-1] - IIf(H[k-1]<C[k-2],
C[k-2], H[k-1])) > dLine[k-1]
OR O[k] < dLine[k], 1);
if (L[k]<dLine[k] AND SellQualifier)
{
Sel[k] = 1;
SellPrice[k]=ShortPrice[k]=dLine[k];
exit = 1;
for (m=k+1; m<BarCount; m++)
{
Sel[m] = 0;
}
}
}
}
if (phi[i]>0)
{
CountHi = CountHi + 1;
j = i;
while (phi[j-0]<=phi[i] AND j>2)
{
pphi[j-1] = phi[j-1];
j = j - 1;
}
sLine = IIf(CountHi<2 OR pphi[j]<phi[i], Null,
LineArray(j,pphi[j],i,phi[i],1));
exit = 0;
for (k = i+2; exit==0 AND k<BarCount; k++)
{
BuyQualifier = IIf(Q_On, C[k-1]<C[k-2] OR
(2*C[k-1] - IIf(L[k-1]>C[k-2],
C[k-2], L[k-1])) < sLine[k-1] OR
O[k] > sLine[k], 1);
if (H[k]>sLine[k] AND BuyQualifier)
{
By[k] = 1;
BuyPrice[k] = CoverPrice[k]= sLine[k];
exit = 1;
for (m=k+1; m<BarCount; m++)
{
By[m] = 0;
}
}
}
}
}
Buy = Cover = ExRem(By, Sel);
Sell = Short = ExRem(Sel, By);
SetTradeDelays(0, 0, 0, 0);
eq = Equity( 0, -2 );
/* Following section constructs the plots of the demand and
supply lines at the area of selection with the pole. */
x1=SelectedValue(ValueWhen(pivotlow,BarIndex(),1));
y1=SelectedValue(ValueWhen(pivotlow,L,1));
x0=SelectedValue(ValueWhen(pivotlow AND L<y1,BarIndex(),1));
y0=SelectedValue(ValueWhen(pivotlow AND L<y1,L,1));
x3=SelectedValue(ValueWhen(pivothigh,BarIndex(),1));
y3=SelectedValue(ValueWhen(pivothigh,H,1));
x2=SelectedValue(ValueWhen(pivothigh AND H>y3,BarIndex(),1));
y2=SelectedValue(ValueWhen(pivothigh AND H>y3,H,1));
demandLine =IIf(x0==0,Null,LineArray(x0,y0,x1,y1,1));
supplyLine =IIf(x2==0,Null,LineArray(x2,y2,x3,y3,1));
Plot(IIf(Cum(1)<x3+extension, supplyLine, Null),"",colorWhite,
styleLine|styleThick|styleNoRescale|styleNoLabel);
Plot(IIf(Cum(1)<x1+extension, demandLine, Null),"",colorWhite,
styleLine|styleThick|styleNoRescale|styleNoLabel);
BuyQualifier = IIf(Q_On, Ref(C, -1)<Ref(C,-2) OR (2*Ref(C,-1) -
IIf(Ref(L,-1)>Ref(C,-2), Ref(C,-2), Ref(L,-1))) <
Ref(supplyline, -1) OR O > supplyline, 1);
SellQualifier = IIf(Q_On, Ref(C, -1)>Ref(C,-2) OR (2*Ref(C,-1) -
IIf(Ref(H,-1)<Ref(C,-2), Ref(C,-2), Ref(H,-1))) >
Ref(demandline, -1) OR O < demandline, 1);
By = Cross(Cum(H>supplyline AND BarIndex()-1>x3 AND
BuyQualifier),0);
Sel = Cross(Cum(L<demandLine AND BarIndex()-1>x1 AND
SellQualifier),0);
PlotShapes((BarIndex()==x0 OR BarIndex()==x1)*
shapeSmallCircle,colorWhite,0,L, -8);
PlotShapes(Sell*shapeDownArrow,colorRed,0,H);
PlotShapes(Sel*shapeDownArrow,colorLightOrange,0,H,-25);
PlotShapes((BarIndex()==x2 OR BarIndex()==x3)*
shapeSmallCircle,colorWhite,0,H,8);
PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,L);
PlotShapes(By*shapeUpArrow,colorAqua,0,L, -25);
// buy and hold simulation for plotting in IB
Short = Cover =0;
Buy = Status("firstbarintest");
Sell = Status("lastbarintest");
SetTradeDelays(0,0,0,0); PositionSize = -100;
ApplyStop(0,0,0,0);
ApplyStop(1,0,0,0);
ApplyStop(2,0,0,0);
bh = Equity( 0, -2 );
/* Following section sets limits for StyleOwnScale plots.
A typical plot statement would be:
Plot(xxxx, "xxxx", 0, styleOwnScale,
LL2(xxxx, yyyy, 5), UL1(xxxx, yyyy, 20));
where the 5 and the 20 represent the percent of freespace
below and above the plots of xxxx and yyyy */
function LL2 (Variable1, Variable2, FreespacePercent) // lower
{
barpresent = Status("barvisible");
Hii = IIf(LastValue(Highest(Variable1*barpresent)) >
LastValue(Highest(Variable2*barpresent)),
LastValue(Highest(Variable1*barpresent)),
LastValue(Highest(Variable2*barpresent)));
Loo = IIf(LastValue(Lowest((Variable1-Hii)*barpresent)+Hii)<
LastValue(Lowest((Variable2-Hii)*barpresent)+Hii),
LastValue(Lowest((Variable1-Hii)*barpresent)+Hii),
LastValue(Lowest((Variable2-Hii)*barpresent)+Hii));
range = Hii -Loo;
result = Loo - 0.01*FreespacePercent*range;
return result;
}
function UL2 (Variable1, Variable2, FreespacePercent) // upper
{
barpresent = Status("barvisible");
Hii = IIf(LastValue(Highest(Variable1*barpresent)) >
LastValue(Highest(Variable2*barpresent)),
LastValue(Highest(Variable1*barpresent)),
LastValue(Highest(Variable2*barpresent)));
Loo = IIf(LastValue(Lowest((Variable1-Hii)*barpresent)+Hii)<
LastValue(Lowest((Variable2-Hii)*barpresent)+Hii),
LastValue(Lowest((Variable1-Hii)*barpresent)+Hii),
LastValue(Lowest((Variable2-Hii)*barpresent)+Hii));
range = Hii -Loo;
result = Loo + range / (1 - 0.01*FreespacePercent);
return result;
}
Plot( bh,"Buy&Hold", colorWhite,
styleOwnScale, LL2(bh, eq, 5), UL2(bh, eq, 70));
Plot(eq, "Trading Result", colorRed,
styleOwnScale, LL2(bh, eq, 5), UL2(bh, eq, 70));
Title= Name()+" "+Date()+EncodeColor(colorWhite)+
" Open "+WriteVal(Open, 1.3)+" Hi "+WriteVal(High,1.3)+
" Lo "+WriteVal(Low,1.3)+" Close "+WriteVal(Close,1.3)+
EncodeColor(colorRed)+" Sell =,"+WriteVal((y1-y0)/(x1-x0)+
SelectedValue(DEMAndline),1.3)+EncodeColor(colorBrightGreen)+
" Buy =,"+WriteVal((y3-y2)/(x3-x2)+
SelectedValue(supplyline),1.3 )+
"\n\\c03Use Param to select Qualifiers and Days \n "+
EncodeColor(colorWhite)+" Buy and Hold = "+WriteVal(bh, 1.3)+
EncodeColor(colorRed)+"\n Trading Result = "+WriteVal(eq, 1.3);
GraphXSpace=24;
_SECTION_END();
------------------------------------
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|