Documentation > StrategyQuant > Developing strategies using custom strategy templates

Developing strategies using custom strategy templates

Author: Mark Fric

June 16th, 2017

Rating:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

One of the main features of new StrategQuant 4 is ability to generate strategies with your own custom “format”.

Standard strategy in SQ3/SQ4 has a fixed “format” consisting of four rules:

Long Entry Rule: IF (Conditions) THEN EnterAtMarket/Stop/Limit to Long;
Short Entry Rule: IF (Conditions) THEN EnterAtMarket/Stop/Limit to Short;
Long Exit Rule (optional): IF (Conditions) THEN Close Long position;
Short Exit Rule (optional): IF (Conditions) THEN Close Short position;

This fixed format cannot be altered in SQ3. You can select that you want Short rules symmetrical to Long rules, or you don’t want Exit rules at all, but you cannot extend it to something else.

But what if you want your strategy to have a different structure?

For example, you want to have three or more different Long entry rules to build your position over time or to use Martingale / grid ?

This is now possible in SQ4 by building strategies from your custom template.

How to use this feature

Telling SQ to generate strategies using your own strategy template is simple – you just configure it in What To Build -> Strategy Type section.

There choose the option Build strategy from template and choose the template you want to use.

There’s nothing more to it, SQ will then use your own templates to build the new strategies. Of course, you need to have some custom template created.

Creating custom templates

Custom strategy templates can be created in Wizard. It means that your strategy can have any possible form that you are able to create in Wizard – it can:

  • have unlimited rules
  • open or close multiple orders at once or after some time
  • contain fixed parts that will not be generated

The only limitations are your imagination and flexibility of Wizard.

To create your own custom template open Wizard and enable random placeholders in Full Editor -> Properties:

This will add placeholders blocks to the choice of your building blocks:

Placeholder blocks have red color to be easily distinguished from normal blocks, they are in all four categories (Comparisons, Conditions, Actions, Values) and there are three types of them:

  • Random blocks – these blocks are generated randomly according to the building blocks settings in SQ
  • Same blocks – they are clones of specific random blocks. This allows you (for example) to have two rules that uses the same conditions or actions , duplicated using the Same block element.
  • Opposite/Negated blocks – they are negations of specified random blocks. This allows you to have a Short rule whose conditions are negation of Long rule

You can build your own strategy template by combining normal blocks and these block placeholders. SQ will then keep the normal blocks in the strategy untouched, generate randomly all the Random block placeholders, and create appropriate Same or Opposite blocks.

After you have build your strategy template, just save it to a file and you can use it in SQ as a template for your Building process.

An example – a “standard” symmetric strategy template

So how an example of strategy template could look like?

Let’s look at the template of a standard symmetric strategy – this template is internally generated and used by SQ if you choose Simple strategy option in What To Build -> Strategy Type.
The template is generated also in respect to the build options – for example whether SL & PT are required or not, etc.

Long rule looks like this:

Please note that first two rules – IsBarOpen and NoTradeRecentlyClosed are fixed, they will be in every generated strategy.
RandomCondition part will be generated randomly by SQ, and despite its name it can be composed of more than one condition – this depends on further settings in SQ. The conditions that will replace RandomCondition will be generated according to the Building blocks and other settings configured in SQ.

The same applies to RandomAction – it is too replaced by action generated by SQ using the chosen Building blocks.

So the final strategy might look like this:

Long entry
————————-
IF
IsBarOpen
and  NoTradeRecentlyClosed(…)
and (CCI(…) > 0
   or    RSI(…) > 50)
THEN
EnterAtMarket(…,Long,…)

The parts of the strategy marked in red were generated randomly.

Short rule looks similar, but because it is symmetric strategy, conditions and action of a short rule should be opposite/negation of  the ones generated in Long rule:

So in our example, the Short rule of generated strategy will be:

Short entry
————————-
IF
IsBarOpen
and  NoTradeRecentlyClosed(…)
and (CCI(…) < 0
   or    RSI(…) < -50)
THEN
EnterAtMarket(…,Short,…)

Placeholders on a block parameter level

Please note that not only you can choose the random blocks, but you are able to specify which of the parameters of the block are random and which are fixed by clicking on the blue […] button.

So  EnterAtMarket block in our example will have no Stop Loss and Profit target generated – because it is set to a fixed None value in our template, and it will have Bars Valid parameters generated randomly.

Note!
If you set some parameters of block defined as having a fixed value – for example Stop Loss and Profit Target being None in our example above, these parameters will be not generated by SQ, despite having SL & PT required. SQ is able to generate only blocks and parameters that are marked as random.

When you are in Random placeholders mode this applies also to normal blocks. So you can have a template that contains fixed conditions, like CCI(Period) > 0 and you can choose to generate only some parameters of CCI randomly as in the example below:

In this case SQ will generate strategies that will all be based on CCI > 0 and only value of CCI parameter Period will be generated randomly.

Conclusion

  • This was a brief introduction to templates in SQ4. It is a very powerful new option, and even we cannot anticipate what everything can be done with it. There are so many combinations and so many different formats of strategies that can be used.
  • Building using strategy templates can create strategies that match your own desired format or help you improve your existing strategies by adding new conditions or only some parameters of your conditions randomly.
  • There is a maximum flexibility, but it also means “responsibility” on your side – you have to think about your custom strategy format, SQ will not prevent you from creating strategies that make no sense – for example they open new trade every milisecond making the new strategies impossible to backtest or trade.
  • It is advised to use IsBarOpen and NotradeClosedRecently blocks with your rules, because they will make backtesting process faster and more reliable.

I’m attaching links to two example strategy templates – both are a variation of standard template:

4
Leave a Reply

Please Login to comment
Phillip van Coller
Member
Phillip van Coller

This is truly amazing. Gonna play with it today.

PJ Chen
Guest
PJ Chen

How can I get SQ4?

Kris
Guest
Kris

SQ4 will use custom templates to build the new strategies but what with others settings in builder? Will be used in building process or not? e.g building blocks?How to set building blocks?Tthe same like in own template or not?