Introduction

I'm a litle indecise what about what will be this article. I have several choices at the moment about other important aspects, but as some readers are expecting i write about how build strategies, i  will do their will. There are too much to talk about this, and this article i will talk only about two strategies i made and the steps to make them: one i used on last month contest only for fun and to see how contest works and the other will be present on this month contest. To help you to keep on track, if needed, read my last articles:


All needed files to follow this articles are placed at Dukascopy forum and you can access them here.

Blind Game

Blind Game is a very simple strategy. I made it just for fun and to understand how Strategy Constest work as i never participate in this. Basicaly what this strategy do is "toss a coin" and gets what side of the coin is up and places one order at the market with a predefined Stop Loss and Take Profit in the direction gived by the "side of the coin" that it gets.
Image 2: The "brain" of Blind Game placed on the onBar method/function. This code is responsible to do the direction of the trade and place it on the market at market price with Stop Loss and Take Profit.

As you can see the code is very simple. With Math.random() we simulate a "toss coin", calculate the value for Stop Loss and Take Profit and place the order. One thing i see in contest in great number of strategies is the lack of multi-order submition check. In my point of view that is against the contest rules as stated in paragraph 6 point b, and paragraph 3 point d of programming rules. The contest platform refuses more than one order and this type of strategy takes this as advantage, if you try to backtest it you get some weird results in the backtesting platform because you can have multiple orders. Thats why some people complain that they can't get the same results in backtesting that the strategy gets in contest. We control this in Blind Game with one boolean variable "myCanTrade". I explain later how i control this variable. I like to make reusable code, that's why i made a method/function specifically to place the orders called "placeBuyorSell()".

Image 3: placeBuyorSell method/function. Very simple, only places the order with predefined position value , Stop Loss and Take Profit in the direction provided with the method/function parameters.

Image 4: Here we control if the strategy can place orders setting the myCanTrade variable according the received messages from the server.

And that's all about this strategy. The rest is the needed methods/functions required by IStrategy interface and some predefined variables. With this strategy i never get a margin call and sometimes get good results in backtesting it monthly about 50 times. You can try this strategy by yourself and you can get it at my Strategy Contest page or at the forum thread.

myRSI strategy

This is my strategy at Dukascopy Strategy Contest this month. RSI is one of the first indicators i read about (i'm thinking also about sma, but i think the market is too volatile to use this indicator) and this is why i chosed it as it gives some good signals. This Strategy have more complexity than the last one and is far way from perfect, but is promising as you can see on 6 month backtest with the dafault parameters of the strategy. In this period we don't have a significant drawdown (related to initial capital) and almost all the time it stays above the initial capital. You can get this results by yourself if you repeat the backtest (no surprises here )

Image 5: bactesting results on EUR/USD on 6 month data and correspondent parameters.

One thing i'm trying to do is a strategy to use in LIVE accounts, and thats why you don't see here the questionable Stop Loss we see usualy on the strategies at Dukascopy Strategy Contest, but you can use some weird values for it if you want. I don't have too much time available to do backtests but i builded it extremely configurable to avoid the need to recompile it every time we want to try with different parameters. We have parameters for pair and period to use, position value (later i'm thinking to include money management and risk  ratio parameters and of course, all the logic), Stop Loss, Take Profit, lock profit, time control, indicator parameters and order direction choice. I only have done backtests with EUR/USD but you can use it with what pair you want and hopefully get some great results tweaking the parameters. The possibility to have this parameters at our disposal  is achieved with the @Configurable annotation i have talked in one of my last articles.

Image 6: Configurable parameters in code and the resulting window on historical backtests.

In this area we set some more needed variables, but can see the code, i don't talk about them. In onStart method/function we will see below we initialise the strategy objects, subscribe the instrument, initialise some variables and close all orders if any open at strategy start. To close all orders i made a method/function as i do this in more than one place on the strategy. Also  if we have time control checked (we define the interval when the strategy can trade) we have an method/function to do this check. Also, if we get outside of time window we define, if we have any open order, it is closed.

Image 7: onStart method/function and others methods/functions referred before. Also a method/function for order inversion. 

Almost all the strategy logic is on onTick method function (i don't put here a image with the code as it will be too big but you can have access to all the code downloading it on Strategy Contest or in the forum). On this method/function we filter the instrument and period in use, see if we are inside the time window to trade if activated, see if we have any open order. If we have a order we do Stop Loss adjustments if needed (trying to have the less loss possible) and also lock profits if we have profits above defined value (the order maybe can't hit Take Profit and is better to have less profit than a loss - unfortunatly this also avoids some bigger profits). If we don't have any trade, we can see if we can have one if the RSI indicator values match our criteria. If the results pass our limitations we trigger the trade. Also i don't allow more than one trade at any bar, but you can change this if you want.

The visual logic behind this strategy

As a picture woths more than a thousand words, i made a picture with the logic behind this strategy. In this way is easier to understand what the code do and also see the flexibility of this strategy with RSI indicator.

Image 8: Visual logic behind myRSI strategy.

In the previou image we can see how the strategy works relatively to trigger entry trades with default parameters. If RSI  value hits myRSIMax + myRSITrigger and the value gets bellow myRSIMax a SELL entry is triggered. If RSI  value hits myRSIMin - myRSITrigger and the value gets above myRSIMin a Buy entry is triggered. But this is only one part of what you can do with this strategy (yes, you read it well). You can play with all this values and you can inverse the orders!!! This means that you can have the trigger bellow myRSIMax and above myRSIMin if you use negative numbers for myRSITrigger and decide the direcction of the trades. The possibilities of the flexibility of this parameters are endless and you can adjust them for any market flow type and try to find the perfect setup. The only drawback is the time spent to find.

Final words

PLEASE DON'T USE THIS STRATEGY ON LIVE ACCOUNTS!!! It's not ready for that, LACKS the slippage management, risk mangement and money management. If you implement this missing features, that's ok. Anyway, use it for what you want, but i'm not responsible for any losses or winnings with this strategy. Consider yourself warned. 

I hope you like this article and the last ones (i'm expecting more interaction from the readers but that's ok) and stay tunned for the next ones. As usual, feel free to comment here or in the forum in the associated thread whatever you want. You can access directly this thread here where all the code files are present.

Trade well and prospers in your way.

JL