JForex Example: Multiple-time frame strategy

The key to my July JForex strategy is the use of multiple time frames. As Dr. Alexander Elder demonstrates in his famous book, Trading For A Living, a proper technical analysis should at least consider time frames five-times faster and slower than the one in which you trade. For example, if you trade on a 30 minute chart, the one faster is 30/5 = 6 minutes, which can be rounded as the five-minute chart. And the one slower would be 30 * 5 = 150 minutes. The closest standard time frame of which is a 4-hour chart.

For my July JForex strategy, it trades on the 30 minute chart and monitor the 4-hour chart in addition to the 30-minute chart. The strategy doesn't make use of a faster time frame for simplicity. This is surprisingly easy to do in Dukascopy's JForex API.

Referring to lines 81 to 87 of my strategy source code.

if (period == PERIODINT) {
    setSentiment(instrument, bidBar, askBar); 
if (period != PERIODSHR) return; // skip all other periods

This chunk of code appears in the onBar() method. Since onBar() is called at the beginning of every price bar across all possible standard periods (from tick to weekly), it's just a matter of filtering out the redundant periods and/or catching the method when the period is correct. I have done both in the sample code. Line 81 is to catch the longer period, PERIODINT = Period.FOUR\_HOURS (line 54, not shown), in an if statement block. It calls my function setSentiment() and exits onBar() with the return, skipping everything in onBar() afterward. Line 87 is to skip all other periods that I'm not using. I could have used if (period == PERIODSHR) and put everything in an if block as in lines 81-85. But since the strategy is doing a lot more work in PERIODSHR, there would be a lot of codes in that IF block. So I am doing the reverse for the same result but simpler-looking codes. With this cleared, I can go over my dual moving average entry signal setup in the next post later this week.