Yeah. I was hoping not to have to do that, but I will concede defeat.
It's mainly the good Friday that seems to be the problem. As any other can be screened out with a code that works for each year.
But if anyone has already done that leg work, that'd be awesome, and save me some time.
I have found that using a specific day of the week can cause
unexpected results when the market isn't open that day. I use the
following approach to evaluate daily data on the last day of the week
(typically but not always a Friday) with trades occurring the next
market day (typically but not always a Monday).
To determine if a given day is in fact the last market day of the
week use:
LastDayofWeek = IIf(DayOfWeek() > Ref(DayOfWeek(),1),1,0);
You can then use ScoreNoRotate if it is not the last day.
You can use SetTradeDelays(1,1,1,1) to execute on next market day.
Using this approach saves you from having to mess with Time Frames
and takes into account that Friday is not always the last trading day
of the week (Good Friday for example in US), and that Monday is not
always the first trading day.
Note that this method "looks ahead" one day to determine if it is the
end of the week. The "Check AFL code" function will give you a
warning. Also because it needs to know if the next trading day is in
this week or next, it may not work very well in real time, but is
good for backtesting purposes.
LastDayofWeek = IIf(DayOfWeek() > Ref(DayOfWeek(),1),1,0);
The code looks ahead to the following day and returns true on the last day. If it's a Friday it evaluates as 5 (Friday) greater than 1 (Monday). If it's a Thursday (ie. no trade on Friday) then it evaluates as 4 (Thursday) greater than 1 (Monday) as there's no 5 (Friday). Hope that makes sense
You can not look into the future of price data in realtime.
Also because it needs to know if the next trading day is in
this week or next, it may not work very well in real time, but is
good for backtesting purposes.
It is not a proper way looking into the future. You can not look into the future of price data in realtime.
A proper code is not dependent on looking into the future of DB data. And it can be done so.
But we aren't attempting to look ahead into future price data. Only available trading days. Exactly the same as if we know Christmas is on a Friday etc.
EndOfWeekGF = datenum() == GoodFriday() -1;
I'll give this code a crack and see if it works.
I haven't tested it so would be interesting to know if it works. If not then there's always the option of collating the Friday holiday dates and/or using a plugin like Trash has illustrated in the post above.
It definitely does work.
If not then there's always the option of collating the Friday holiday dates and/or using a plugin like Trash has illustrated in the post above.
Thanks Howard.
I can't seem to get it to optimize PositiveChg before or in the Buy line. Will I have to use another function given I want it to return a numerical value and not just a true or false?
Cheers,
Chops.
I can't seem to get it to optimize PositiveChg before or in the Buy line. Will I have to use another function given I want it to return a numerical value and not just a true or false?
returns either true or false so your currently optimising the wrong variable. I assume you're really wanting to optimise the "pchng" value?PositiveChg = pchng >=0;
Buy = .... cannot be a number. The buyline requires a condition.
Try instead:
Buy = ((O - Ref(C, -1)) / Ref(C,-1)) *100 > Optimize("PositiveChg",0,0,5,0.2);
...and lose all the other lines. They are unecessary.
How come we can use ">" in the buy line? I would have thought that would have brought up an error like that.
"Returns either true or false so your currently optimising the wrong variable. I assume you're really wanting to optimise the "pchng" value."
That's right. But I couldn't seem to get that. Slowly getting there again...
Hello and welcome to Aussie Stock Forums!
To gain full access you must register. Registration is free and takes only a few seconds to complete.
Already a member? Log in here.