Hi all

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();
}

if(dow() == MONDAY && lhour(ET) >= 8 /* && minute() >= 30 */ ) {
exitLong();
exitShort();
}

PlotWidth = 800;
PlotHeight1 = 320;

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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)

Portfolio analysis OptF ProF Win/Loss
GBP/USD:L .000 ---- 0/0
GBP/USD:S .070 1.20 22/25

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.

Attached Files
ONS example.jpg (8 downloads)