In the DukasCopy Wiki we can see a simple strategy for JForex platform, based on crossing of two SMAs. The SMAStrategy strategy based on two SMA (Simple moving average): SMA with time period 10 and SMA with time period 90. The strategy logic can be described as 2 actions:
  • If SMA 10 cross SMA 90 from up to down, then the strategy closes existing short position and open a buy order if long position does not exist
  • If SMA 10 cross SMA 90 from down to up, then the strategy closes existing long position and open a sell order if short position does not exist
But you can’t use this strategy to get profit because the purpose of it is educational, and the results are not very good. All what you can get is slow decreasing of depo (fig. 1) for the random strategy parameters
  • instrument - EURUSD;
  • period – one hour;
  • filter – weekends;
from 01.01.2012:

Fig. 1. But can we improve this strategy to get a profit? Let’s see…
How many hourly bars do we have from 01.01.2012 till now? It is approximately 21300 hourly bars. DukasCopy tester generated 375 orders in this period. So, the average trade length is 57 hours. How can we use this information to improve our strategy?
Let’s think about the waves of the price moving around slow SMA(90) from our strategy. Can we say that the price goes from the SMA in the first half of the time, and it goes to the SMA in the rest half of the time? It is very approximately, but we can try to use this feauture. We can use time-stop for our open orders. If an order`s life is more than 23 hours, we will close it!
Time-stop filter in code is:
IBar stopBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 23);
for (IOrder orderInMarket : engine.getOrders()) {
if (orderInMarket.getFillTime() > stopBar.getTime()) {
orderInMarket.close();
}
}

You can see the result of a time-stop filter on fig. 2.

Fig. 2.
The result of the improvement is that we decrease our losses twice.
But it`s not the end of the story. Let`s go further.
All we know that the Forex market has the seasonality. Every exchange in the World has its own rhythm of the work, every trader has its own comfortable hours of work. Thus we have several periods of activity in the Forex. There are three most known sessions of activity in the world: European, American and Asian. And every session has its own effect on the movement of each instrument. So, what if we`ll try to analyze the orders from this simple strategy?
Let`s try to analyze the time of entry. We can summarize the profit of orders, which were opened in each hour of the day. You can see the result of the analysis on fig. 3.
Fig. 3.
As we can observe, only the entering in hours 00:00, 14:00, 16:00, 18:00, 20:00, 21:00 and 22:00 can get us a good result. That’s why we can insert the time filter in our simple strategy to get absolutely different total result: we decrease the quantity of orders, increase the cumulative profit, decrease the commissions and increase the profit factor.
We must use two imports:
import java.util.Calendar;
import java.util.TimeZone;

After that we can input the time filter into the code of the strategy:
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
long currtime = tick.getTime();
calendar.setTimeInMillis(currtime);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
boolean trading = false;
if (hour == 0 || hour == 14 || hour == 16 || hour == 18 || hour == 20 || hour == 21 || hour == 22)
trading = true;
You can see the result of this simple modification on fig. 4.

Fig. 4
You can`t use this strategy for trading, but you can use this filters for your strategies. This is one of many ways of every strategy improvement.
Use your imagination, logic and knowledge to generate clever trading rules, in that way you can get profitable strategy. Use right filters for your orders to improve your strategy, and you`ll succeed!
Translate to English Show original