Ichimoku strategy problem

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Ichimoku strategy problem

Postby tllewell » Thu Aug 01, 2013 9:42 am

I have been working on an Ichimoku strategy that uses the Chinkou (or Chikou or lagging) line. It is based on Tyler Yell's articles on DailyFX. So, I have some code like:

Code: Select all
if ich.CS[ich.CS:size() - 27] > ich.SL[ich.SL:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.TL[ich.TL:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.SA[ich.SA:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.SB[ich.SB:size() - 27] and
      MTF.close[MTF.close:size() - 1] > ich.SL[ich.SL:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.TL[ich.TL:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.SA[ich.SA:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.SB[ich.SB:size() - 1] then

... [do something, like open a trade] ...

In order to see the lagging line you need to look back to position 27 in the history because it lags by 26 periods. The problem is, when the stragegy starts, it generates an "index out of range" error on these tests. I am using the Lua helper script to get prices.

The error goes away if I just put in a dummy counter to burn up some time. However, you seem to need to cycle through 30-60 updates to get past the problem and that takes too long. I have tried to add combinations like Get Price History/Extend Price History and core.UpdateAll but this doesn't seem to work.

How do I get the indicator up and running completely so the strategy runs?
tllewell
 
Posts: 76
Joined: Thu Mar 01, 2012 4:06 pm

Re: Ichimoku strategy problem

Postby Victor.Tereschenko » Thu Aug 01, 2013 11:10 pm

Does it happen when you backtest strategy or when you run it "live"?
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am

Re: Ichimoku strategy problem

Postby tllewell » Fri Aug 02, 2013 6:57 am

Both. And in the debugger. Between the debugger and the backtester I found out I needed to run out way more than 27 cycles to get past the error.

We either need some way to preload the indicator or some way to catch the error so it doesn't just make the strategy die.
tllewell
 
Posts: 76
Joined: Thu Mar 01, 2012 4:06 pm

Re: Ichimoku strategy problem

Postby Victor.Tereschenko » Sun Aug 04, 2013 11:44 pm

The easiest way is to check for the ich size:
Code: Select all
if ich.CS:size() < 27 of ich.SL:size() < 27 or ich.TL:size() < 27 or ich.SA:size() < 27 or ich.SB:size() < 27 or MTF.close:size() < 1 then
      return;
end
if ich.CS[ich.CS:size() - 27] > ich.SL[ich.SL:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.TL[ich.TL:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.SA[ich.SA:size() - 27] and
      ich.CS[ich.CS:size() - 27] > ich.SB[ich.SB:size() - 27] and
      MTF.close[MTF.close:size() - 1] > ich.SL[ich.SL:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.TL[ich.TL:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.SA[ich.SA:size() - 1] and
      MTF.close[MTF.close:size() - 1] > ich.SB[ich.SB:size() - 1] then

Or you can request more data by using getSyncHistory in the indicator (you need to make a copy of ICH and modify it).
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am

Re: Ichimoku strategy problem

Postby tllewell » Mon Aug 05, 2013 9:01 pm

Sorry for the delay answering; I got tied up all weekend. But that is a good trick to know. You just test for the length of the output history array. I changed it slightly to

Code: Select all
local run = false;

...
Code: Select all
if not run then
     if ich.CS:size() > 27 then
           run = true;
      else
           return;
      end
end


Which I realize is the long way to go about it, but the test for run was already there so I just used it. However, that seems to work just fine.

Thanks! I've had similar issues with other strategies, and this little technique will be very useful.
tllewell
 
Posts: 76
Joined: Thu Mar 01, 2012 4:06 pm


Return to Discussions

Who is online

Users browsing this forum: No registered users and 18 guests