Extended features for Dealbook Chartstudio CTL programming
click to enlarge




CTLDLL HOME


Link charts of different times



strategy CTLDLL_15m_30s;
/*******************************************************************
This code is an example only of how to utilise CTLDLL to carry data
over different charts and timeframes.

** It does not provide full error handling nor trading logic !!!! **

- You need a valid copy of CTLDLL installed and running to use the
CTLDLL functions ~ www.CTLDLL.blogspot.com

-----------------------------------------------------------------
In dealbook, create two charts, one 15 minute and one 30 second for
the same currency pair. Attach this strategy to each.
Open the debug window to observe activity

*******************************************************************/

import "CtlDll.dll" number funcN( string, number, string, number ),
"CtlDll.dll" string funcS( string, number, string, string );

input iChart = 2301, lots = 1;

vars lst(number), fst(number), rsp(number), glots(number),
t1(number), t2(number), t(number);

begin
lst := back(close);
fst := front(close);
if lst-2 < fst then return;

// calculate what time frame this chart is running in
t1 := timestamp[back(open)-1];
t2 := timestamp[back(open)-2];
t := t1 - t2;

if t > 60 then // if more than a minute
begin
print("> 60: check enter conditions");
rsp := funcN("GetNum", iChart, "trade_" + symbol, 0);
if rsp < -100000 then
// should do more error handling on rsp here
print(numbertostring(rsp));

if rsp = 0 then //already in a trade
begin
if (open[lst ] > open[lst-1]) and
(open[lst-1] > open[lst-2]) then
begin
print("buy");
buy(lots);
rsp := funcN("SetNum", iChart, "trade_" + symbol, lots);
// should do error handling on rsp here
end;
end;
end;

if t < 61 then // if less than a minute
/* below here could be in a separate CTL program,
as long as iChart and the variable name are the same */
begin
// only check each 30 seconds
if funcN("EachTime", iChart, "trade_" + symbol + "_EachTime", 30) = 0 then return;

print("< 60: check exit conditions");

rsp := funcN("GetNum", iChart, "trade_" + symbol, 0);
if rsp < -100000 then
// should do more error handling on rsp here
print(numbertostring(rsp));

if rsp > 0 then
begin
if (open[lst ] > open[lst-4]) then
begin
// still going up ... so be happy
end
else
begin
if rsp > 0 then
begin
print("sell");
sell(rsp);
rsp := funcN("SetNum", iChart, "trade_" + symbol, 0);
// should do error handling on rsp here
end;
end;
end;
end;
end.



CTLDLL HOME