Corn Futures Strategy (Amibroker And Tradestation Code)
The original article is here.
Backtest no 1:
Plain English:
- We go long corn futures at the close of March.
- We close our long position and sell short at the close of May.
- We cover our short position and go long at the close of September
- We close our long position and sell short at the close of February.
Amibroker code:
Buy =
(Month() != Ref(Month(),1) AND Month()==3 )
OR
(Month() != Ref(Month(),1) AND Month()==9 )
;
buyPrice=Close;
Sell =
(Month() != Ref(Month(),1) AND Month()==5 )
OR
(Month() != Ref(Month(),1) AND Month()==2 )
;
sellPrice=Close;
Short= (Month() != Ref(Month(),1) AND Month()==2 )
OR
(Month() != Ref(Month(),1) AND Month()==5 )
;
ShortPrice = Close ;
Cover =
(Month() != Ref(Month(),1) AND Month()==3 )
OR
(Month() != Ref(Month(),1) AND Month()==9 )
;
CoverPrice=Close;
Backtest no 2:
Plain English:
- Buy on the sixth last trading day of the month if the close is above the close 20 days back.
- Sell at the close of the month
Amibroker code:
Buy = Ref(Month(),5) != Ref(Month(),6) AND C>Ref(C,-20);
buyPrice=Close;
Sell = Month() != Ref(Month(),-1);
sellPrice=Close;
Tradestation code:
{
Corn strategy (no 159A):
We go long corn futures at the close of March.
We close our long position and sell short at the close of May.
We cover our short position and go long at the close of September
We close our long position and sell short at the close of February.
It is necessary to import functions: TdaysTillMonthEnd, IsHoliday
}
if ((TdaysTillMonthEnd=0) and (Month(Date)=3)) or ((TdaysTillMonthEnd=0) and (Month(Date)=9)) then
Buy this bar at close;
if ((TdaysTillMonthEnd=0) and (Month(Date)=5)) or ((TdaysTillMonthEnd=0) and (Month(Date)=2)) then
Sell this bar at close;
if ((TdaysTillMonthEnd=0) and (Month(Date)=2)) or ((TdaysTillMonthEnd=0) and (Month(Date)=5)) then
Sellshort this bar at close;
if ((TdaysTillMonthEnd=0) and (Month(Date)=3)) or ((TdaysTillMonthEnd=0) and (Month(Date)=9)) then
Buytocover this bar at close;
{
Corn strategy (no 159B):
Buy on the sixth last trading day of the month if the close is above the close 20 days back.
Sell at the close of the month
It is necessary to import functions: TdaysTillMonthEnd, IsHoliday
}
if (TdaysTillMonthEnd=5) and (Close>Close[20]) then
Buy this bar at close;
if (Month(Date)<>Month(Date[1])) then
Sell this bar at close;
