Thomas DeMark Sequential System

amibrokerfans

Well-Known Member
Hi
I love all your hardwork for this and here is my developed afl i made it on tomdemark i have still some final stage to set this one with my wave count when complete i will share it for this forum .Please give me your feed back to improove it this is some of which i am currently using it with my experience on tomdemark count since last 8 years

_SECTION_END();
nice work forexsolution4u:thumb: i have few ideas also, will give u after more testing. thanks once again.
 

devadas

Well-Known Member
The following are also giving errors

1) TDset9_buy = TDset_buy==9;

2) TDset9_sell = TDset_sell==9;

3)setBuy_perf = LLVL2<=Ref(LLVL2,-2) AND TDset_buy>=9;

4)setSell_perf = HHVH2>=Ref(HHVH2,-2) AND TDset_sell>=9;

5) TDSTrs = ValueWhen(TDset_buy==9,H,1);//ValueWhen(TDset_buy==1,H,1),1);

6) TDSTsp = ValueWhen(TDset_sell==9,L,1);//ValueWhen(TDset_sell==1,L,1),1);
 

amibrokerfans

Well-Known Member

devadas

Well-Known Member
The following are also giving errors

1) TDset9_buy = TDset_buy==9;

2) TDset9_sell = TDset_sell==9;

3)setBuy_perf = LLVL2<=Ref(LLVL2,-2) AND TDset_buy>=9;

4)setSell_perf = HHVH2>=Ref(HHVH2,-2) AND TDset_sell>=9;

5) TDSTrs = ValueWhen(TDset_buy==9,H,1);//ValueWhen(TDset_buy==1,H,1),1);

6) TDSTsp = ValueWhen(TDset_sell==9,L,1);//ValueWhen(TDset_sell==1,L,1),1);

Does anyone know how to rectify it ?
 

rkkarnani

Well-Known Member
Demark charts always fascinated me but I could never understand them properly and hence just stopped trying! :p

I have some stuff in my archives copied from the Net and may be of interest to friends here.
Most of the stuff was for Metastock but I found this one for Amibroker , an AFL :

_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 */
SetChartBkColor(16);
/* 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<1000000)
{
CountLo = CountLo + 1;
j = i;
while (plo[j-0]>=plo AND j>2)
{
pplo[j-1] = plo[j-1];
j = j - 1;
}
dLine = IIf(CountLo<2 OR pplo[j]>plo,Null,
LineArray(j,pplo[j],i,plo,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>0)
{
CountHi = CountHi + 1;
j = i;
while (phi[j-0]<=phi AND j>2)
{
pphi[j-1] = phi[j-1];
j = j - 1;
}
sLine = IIf(CountHi<2 OR pphi[j]<phi, Null,
LineArray(j,pphi[j],i,phi,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();




No idea if it correct or not or whether its one more AFL commonly available !
 

Similar threads