Hello Andrew, i am having lot of trouble, trying to build very simple strategies, for example:
History is QQQ.t6 just OHLC, i want to open 1 trade wednesday at market open and close the same trade at Thrusday market close.
Seem a very simple strategy but i am not able to close at trusday close, as the signal cant be executed at market close, i know it is not realistic strategy because when signal is send, market just close, but i want to do this because i have more years in this QQQ.t6 file than other QQQ tick data files. By the way i copy the claude code i got. I am a totally novice in c-lite, so you have an idea of a novice zorro trader coder
The code:
// IWM_WedThu.c
// Simple Zorro Lite-C bot:
// - Buy IWM at Wednesday's market open
// - Sell (close) that position at Thursday's market open
//
// Data file used: C:\Zorro\History\IWM_eod.t6
// (Zorro finds it automatically because the asset name below
// matches the file name, minus the .t6 extension.)
//
// IMPORTANT TIMING NOTE:
// Zorro evaluates the script at the CLOSE of each daily bar, and any
// order placed during that evaluation is filled at the OPEN of the
// NEXT bar. So to get filled on Wednesday's open, the enterLong()
// signal must be raised on TUESDAY's bar. Likewise, to get filled on
// Thursday's open, exitLong() must be raised on WEDNESDAY's bar.
//
// dow() returns a plain number, not a named constant:
// 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
// IWM_WedThu.c
// Simple Zorro Lite-C bot:
// - Buy IWM at Wednesday's market open
// - Sell (close) that position at Thursday's market open
//
// Data file used: C:\Zorro\History\IWM_eod.t6
// (Zorro finds it automatically because the asset name below
// matches the file name, minus the .t6 extension.)
//
// IMPORTANT TIMING NOTE:
// Zorro evaluates the script at the CLOSE of each daily bar, and any
// order placed during that evaluation is filled at the OPEN of the
// NEXT bar. So to get filled on Wednesday's open, the enterLong()
// signal must be raised on TUESDAY's bar. Likewise, to get filled on
// Thursday's open, exitLong() must be raised on WEDNESDAY's bar.
//
// dow() returns a plain number, not a named constant:
// 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
// Trade pointer kept between bars so we can exit the specific trade
// we opened, rather than "the current open long position".
TRADE *myTrade;
function run()
{
set(LOGFILE); // write a trade log so you can verify fills
BarPeriod = 1440; // 1440 minutes = daily bars (matches EOD data)
LookBack = 0; // no indicators, no warm-up period needed
StartDate = 2015; // adjust to taste, or delete to use full history
EndDate = 2017;
Fill = 3; // delayed fill: entry order executes at the OPEN of
// the next bar instead of the close of the signal bar
//asset("IWM_eod"); // loads C:\Zorro\History\IWM_eod.t6
asset("QQQ"); // loads C:\Zorro\History\QQQ.t6
// --- DIAGNOSTIC: print what Zorro sees on the days that matter ---
if(dow(0) == 2 || dow(0) == 3 || dow(0) == 4)
printf("\n%s dow=%i Fill=%i Open=%.3f Close=%.3f",
strdate("%Y-%m-%d", 0), dow(0), Fill, priceOpen(), priceClose());
// --- Entry: signal on Tuesday (2), fills at Wednesday's open ---
// (Standard Zorro behavior: order raised now, filled at next bar's open.)
if(dow(0) == 2 && !myTrade)
myTrade = enterLong();
// --- Exit: signal on Thursday (4), plain market close.
// IMPORTANT: exitTrade() must be called WITHOUT a price argument here.
// Passing a price (e.g. exitTrade(myTrade, priceClose())) makes Zorro
// register it as a Stop level on the trade (visible in the log as
// "Trail ... Stop ..."), and that Stop gets checked against price
// action independently of the Fill setting -- which is why changing
// Fill from 0 to 3 had no effect on the unwanted stop-outs. A plain,
// price-less exitTrade() just closes the position at market with no
// Stop object attached, removing that artifact entirely.
if(dow(0) == 4 && myTrade) {
exitTrade(myTrade);
// --- DIAGNOSTIC: confirm the exit landed on THIS (Thursday) bar
// and that no Stop/Trail line appears for this trade in the log.
printf("\n >> EXIT check: signaled %s (dow=%i) at Close=%.3f -- check trade log above for Stop/Trail lines",
strdate("%Y-%m-%d", 0), dow(0), priceClose());
myTrade = 0;
}
}