PureBytes Links
Trading Reference Links
|
[I tried to post this earlier, but an attached jpg prevented it from
being distributed. If you want to see the pic, e-mail me privately.
Tks.]
I use EL functions that calculate Chandelier stops and objectives for my
trades, and I thought I'd share them with the list. I have included a
sample indicator that plots stops and objectives based on a manual "L"
or "S" you place on a chart (see the pic). In my own work, I connect the
functions into my system's signal generator.
I haven't seen a discussion about Chandelier objectives, so the code
here is my own way of calculating them. It eyeballs fine, and works for
my purposes.
/Greg
PS, I have completed my stint in software development purgatory, and
returned to daytrading the S&P full time. Is the SPDT discussion group
still active? If not, is anybody interested in resurrecting it?
{==================================================================================}
{ Indicator: MyChandelier }
input: stpFactor(5), objFactor(5), stpATRlen(20), objATRlen(20);
var: MyDir(0), ShowChand(false);
{
This indicator demonstrates the ChandelierStop and ChandelierObjective
functions.
USAGE: Use the text tool to place a cap L (for longs) or cap S (for
shorts)
above or below the start of a trade.
The Stop appears as a cyan dot, and the Objective appears as a
blue dot.
}
{ SETUP }
if currentbar = 1 then begin
var: handl(0), ss(""), date1(0), time1(0), price1(0);
handl = text_getfirst(2);
while handl >= 0 begin
ss = text_getstring(handl);
if ss = "S" or ss = "L" then begin
date1 = text_getdate(handl);
time1 = text_gettime(handl);
price1 = text_getvalue(handl);
MyDir = iff(ss = "L",1,-1);
end;
handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if
this is missing! }
end;
end;
{ BAR BY BAR }
if date = date1 and time = time1 then ShowChand = true;
var: MyObjective(0), MyStop(0);
MyStop = ChandelierStop(MyDir, ShowChand <> ShowChand[1], stpFactor,
stpATRLen);
MyObjective = ChandelierObj(MyDir, ShowChand <> ShowChand[1], objFactor,
objATRLen);
if ShowChand then begin
if MyStop > 0 then
plot2(MyStop,"",cyan,default,1);
if MyObjective > 0 then
plot3(MyObjective,"",blue,default,1);
if MyStop = 0 or MyObjective = 0 then ShowChand = false;
end;
{==================================================================================}
{ Function: ChandelierStop }
{ sample: ChandelierStop(0, 5, 20); }
{ returns 0 if no stop }
input: MktDir(NumericSeries), Reset(TrueFalseSimple),
Fac(NumericSimple), ATRLen(NumericSimple);
var: hh(0), ll(0);
var: MaxChand(0), MinChand(0), atr(0);
if Reset then begin
hh = h;
ll = l;
MaxChand = 0;
MinChand = 999999;
end;
atr = Fac*Average(TrueRange,ATRLen);
if hh < h then hh = h;
if ll > l then ll = l;
value1 = hh - atr;
value2 = ll + atr;
if MaxChand < value1 then MaxChand = value1;
if MinChand > value2 then MinChand = value2;
if MktDir = 1 then
ChandelierStop = iff(h<MaxChand,0,MaxChand)
else if MktDir = -1 then
ChandelierStop = iff(l>MinChand,0,MinChand)
else
ChandelierStop = 0;
{==================================================================================}
{ Function: ChandelierObj }
{ sample: ChandelierExit(0, 5, 20); }
{ returns 0 if no objective }
Input: MktDir(NumericSeries), Reset(TrueFalseSimple),
Fac(NumericSimple),ATRLen(NumericSimple);
var: cc(0);
var: MaxChand(0), MinChand(0), atr(0);
if Reset then begin
cc = c;
MaxChand = 0;
MinChand = 999999;
end;
atr = Fac*Average(TrueRange,ATRLen);
value1 = cc - atr;
value2 = cc + atr;
if MaxChand < value1 then MaxChand = value1;
if MinChand > value2 then MinChand = value2;
if MktDir = 1 then
ChandelierObj = iff(h>MinChand,0,MinChand)
else if MktDir = -1 then
ChandelierObj = iff(l<MaxChand,0,MaxChand)
else
ChandelierObj = 0;
Attachment:
Description: "JGWCHANDELIER.ELS"
|