This is my first attempt at programming with Lite C and Zorro. I would appreciate some help with the code.
I am coding Joe Krutsinger's One Night Stand system. This system is pretty easy to find with a google search. The idea is to enter on Friday and hold over the weekend, seeking the weekend risk premium. The rules are:
- Buy only on Fridays--- at one pip above the highest high of the last ten days--- if the 10 day simple moving average is above the 40 day simple moving average. - Sell only on Fridays--- at one pip below the lowest low of the last ten days--- if the 10 day simple moving average is below the 40 day simple moving average. - If you get filled on either rule, exit on Monday morning's open, or Tuesday morning's open, if Monday is a holiday.
Below is my current attempt:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function run() {
BarPeriod = 1440;
if ((dow( ) == FRIDAY) and (SMA(priceClose,10) > SMA(priceClose,40))) { Entry = HH(10) + 1*PIP; enterLong(); } else if ((dow( ) == FRIDAY) and (SMA(priceClose,10) < SMA(priceClose,40))) { Entry = LL(10) - 1*PIP; enterShort(); }
I have not taken into account holidays. I am yet to decide what to do about this. Attached is an example equity curve from an internet source. It trades around ten times a year.
Here are the problems I am having:
1. For some reason I am only getting short entries in the test. The code for the long entry appears to be the same as the short entry, except for the '>' and the enterLong() command. So this seems very odd. Below are extracts from the result report. Notice the discrepancy between the total number of trades and the number of long and short trades.
Test period 05.04.2008-11.06.2013 Number of trades 47 (10/year, 1/week, 1/day)
2. I am trying to exit the trade at about 8:30am NY time since these is a good approximation of the Monday open. I may adjust this later, but for now, the code above fails to execute the exit order. Thus there is something wrong with my if statement conditions. It exits when I omit 'minute() >= 30;', But I am not sure yet if that case exits at 8am NYT.
3. Thoughts on how to check that the code is conceptually correct when the output graph is too small to read. Do people set the test period to a small time so that the resolution is better in the output graph? I guess the rules are simple enough to manually check a hand full trades from the output file. Which reminds me....what is the code for outputting trades to a .csv file?
Thanks in advance.
Re: My first script - JK's One Night Stand
[Re: DMB]
#427819 08/14/1308:0108/14/1308:01
1) You need a series for the SMA, so your entry conditions are wrong.
vars Close = series(priceClose()); if(SMA(Close....
2) You're using daily bars, but want to exit the trade within 30 minutes. You need 30 minutes bars for that. Use then also a certain time for Friday to make sure that only one trade is opened.
3) set LOGFILE for this.
Re: My first script - JK's One Night Stand
[Re: jcl]
#427832 08/14/1312:1808/14/1312:18
@jcl, have I handled the offsets and timeframes correctly so that the daily price series are for ET market close, the SMA's thursday nights, and the hh & ll the correct 10 ET daily highs and lows? Does this now automatically handle ET daylight savings?
@DMB what instruments is this supposed to work on? I've assumed that the open & close are US regualr sessions, cna you confirm if this is the case. It does not look profitable to me.
Code:
function run()
{
BarPeriod = 30;
FrameOffset = timeOffset(ET,0,0,0); // calculate daily bars with ET close
TimeFrame = 48; // Calculate daily bars
vars dailycl = series(priceClose());
vars sma10 = series(SMA(dailycl,10));
vars sma40 = series(SMA(dailycl,40));
var longentry = HH(10) + (1*PIP);
var shortentry = LL(10) - (1*PIP);
TimeFrame = 1; // back to 30 min bars
TimeWait = 15; // Remove pending orders at end of market day
if (ldow(ET) == FRIDAY)
{
if (sma10[0] > sma40[0])
{
if ((lhour(ET,0) == 9) and (minute(0) == 30))
{
enterLong(1,longentry);
}
}
if (sma10[0] < sma40[0])
{
if ((lhour(ET,0) == 9) and (minute(0) == 30))
{
enterShort(1,shortentry);
}
}
}
if (ldow(ET) == MONDAY)
{
if ((lhour(ET,0) == 9) and (minute(0) == 30))
{
exitLong();
exitShort();
}
}
PlotWidth = 4000;
PlotHeight1 = 700;
}
Last edited by swingtraderkk; 08/14/1312:20.
Re: My first script - JK's One Night Stand
[Re: swingtraderkk]
#427885 08/15/1308:4008/15/1308:40
Thanks for your help swingtraderkk / jcl. I am in the process of reviewing / testing / learning. Just thought I would answer your questions. I believe the system is supposed to work on the major currency pairs and crosses. I also believe Krutsinger released it in the 80's. It is quite possible that it does not work anymore. I was tried to test it on my former software a couple years ago, but getting an accurate exit was very difficult.
Also when I was testing it, I discovered that Krutsinger was not using tick level resolution. Rather daily bars with assumed intraday movement. Thus there was some error there despite the simplicity of the system. I never really got to the bottom of it. I thought I would try again given the flexibility of programming with lite C.
Next I will start reviewing all of my old attempts at mech trading with Larry Williams concepts. The code you have provided above has helped me understand better how to make systems for Zorro.
Last edited by DMB; 08/15/1308:40.
Re: My first script - JK's One Night Stand
[Re: DMB]
#427893 08/15/1310:3808/15/1310:38
I'm not a programmer just another zorro learner a little bit further down the road.
Wait for jcl to confirm I'm correct.
It may be worth trying again then as I assumed it was S&P, DOW strategy. You also would need to adjust the entries & exits as it is written for ET market hours.
I'd put a stop in too, NFP Fridays can be a wild ride for the dollar.
Re: My first script - JK's One Night Stand
[Re: swingtraderkk]
#427971 08/16/1302:1608/16/1302:16
Stop is a good idea. The info I have says a stop is helpful but not essential. Personally, I would prefer that extra protection and I was planning on testing a stop anyway.
The website below talks about the ONS system, after a lot of other dribble. It looks like Joel Rensink has another very simple system called 'First Strike' (find with google) that I might code just for practice. I have some other info on ONS directly from Krutsinger, though I have never done a course with him or really followed any of his work. I am just happy to finally test it accurately. Ditto with all the other stuff I have tried but without WFO. Very interesting development tool.
Googling revealed a little more information about Rensink and this system. It appears that the entries went live at 12:00am CST Friday morning and the exit executed at 12:00am CST Monday morning. He traded this system and the other system, First Strike (a Monday to Friday breakout system) on an account starting at $500 to prove it can be done. Four currencies and one cross. He blogged it but for some reason the blogs stops after 5 years and $34k.
Anyway, I think I have enough code from above to complete the script for both systems. So I will do that and make the final code and test results public on this thread.
Re: My first script - JK's One Night Stand
[Re: DMB]
#428164 08/19/1311:2108/19/1311:21
Midnight. Let's say 12:01am Friday morning for entry and 12:01am Monday morning for exit..
In the last couple years he only did one blog a year. I guess it was becoming a little cumbersome. Also at the rate of return he was getting, he would have reached his $150k target, so probably didn't bother blogging that he had done so, but maybe sent an email to the subscribers of the blog/newsletter.
Also, if you intend to look into the FirstStrike system, I think he changed the strategy at some point. It looks more like a typical Larry Williams' 'Open+/- % or range with First Profitable Open Exit' system. Basically what I was going to work on next anyway, but on a smaller time frame than weekly.
It's going to take me a few weeks, but I will report back on my system development.