Description of Trading SM questions and actions.
Many traders draw support and resistance lines in Metatrader charts and trade when prices breach those levels. We can automate these trades with Trading SM.
Let’s draw support and resistance lines and give them some easy to remember name.
The Line Price question of the Misc panel retrieves a line price. The question requires the line name and the bar from which we want to know the price.
You may find useless the bar number in horizontal lines but it makes sense for trend lines. The question works with both type of lines.
We are going to automate the following strategy:
- Long Condition 1: Buy Orders Open equal 0
- Long Condition 2: Bid price less than Support line in bar 0.
- Close Sell
- Short Condition 1: Sell Orders Open equal 0
- Short Condition 2: Bid price greater than Resistance line in bar 0.
- Close Buy
In the next short video, I show you how I create this robot.
Note the importance of Condition 1 in each rule. Without this condition, the Expert Advisor will keep opening orders whilst prices site above support line or below resistance line.
The Martingale Size question of the Misc panel calculates the trading volume relying on the martin-gale mechanics. It is helpful when you want to increase the trading volume after a losing trade. The idea is to increase the trading volume in a new trading action. The Martingale Size question would check whether the last closed trade was a losing one. If it were a losing trade, the answer would be the increased trading volume. Otherwise, the answer would be the default trading volume. This default volume should be specified in the Martingale Size settings.
Martingale Size Settings
In the following image we see all the setting options available in this question.
There are two options: multiplication or addition. This way we determine how the trading volume is increased.
The number by which the volume of the last closed trade will be multiplied or added.
Here, we specify the symbol in which the last closed trade will be searched. So, if the last closed trade in this symbol is a losing one, the new trading volume will be calculated based on the two previous settings.
If you leave this setting empty, the chart symbol in which the Expert Advisor runs will be used.
In case we also want to filter by magic number, we provide the number here. This way the last closed trade of the symbol previously specified that also has this magic number will be used to calculate the next trading volume.
Leave it empty and it will use the last trade no matter what magic number has.
Same logic as Magic Number. When we want to filter by comment.
In case you want to limit the number of times the trading volume is increased.
For example, if you set the Limit to 5, the last consecutive losing trade at which the trading volume is increased is the 6th one. Trade 1 has the default volume and the next 5 consecutive trades will be increased. After these 5 increments, the next trade will use the default trading volume and the process starts again.
If you leave this setting empty, trading volume will increase infinitely while losing trades occur consecutively.
You need to provide the default trading volume we get from this question when the last trade is a winning one or after the limit trade has been reached.
You shouldn’t leave this setting empty. Otherwise, no trading volume will be provided to the trading action and thus the trading action will fail.
Example: MA Crossovers System With Martingale
In order to see this mechanics in action, we show you in the next video how to implement the martin-gale logic in the MA Crossovers system we developed in the Getting Started tutorial of this documentation.
Now, if you run this Expert Advisor in the Strategy Tester, you will see that the trading volume is doubled when the previous trade was a losing one. Because we set the limit to 3 consecutive trades, after 4 losing trades in a row the next trade opens with the default volume.
Martingale Immediately After Closing
Many traders want to start the martin-gale logic right after a losing trade closes. They do not wait till a new trading signal takes place. For this type of trading logic, we can use the Order Closed Losing question of the Misc panel.
This question detects when a losing trade just closes. The question has the next setting options:
Here, we specify the symbol of the trade that just closes. If the trade that closes is not of this symbol, then the closing won’t be detected.
Leave this setting empty if you want to use the chart symbol in which the Expert Advisor runs.
If you also want to specify the magic number of the trade. Leave it empty if the magic number doesn’t matter.
If you also want to specify the magic comment of the trade. Leave it empty if the comment doesn’t matter.
Example: MA Crossovers System With Martingale After Closing
Let’s modify the MA Crossovers system to trade in the opposite direction when a losing trade just closes. We limit the number of trading volume increments to 3.
For those that want to control the exact amount risked in each trade, there are two questions in the Misc panel that are of great help: Trading Volume and Stop Loss Distance.
The Trading Volume question has the following fields: stop loss distance, amount risked (in Metatrader account currency) and trade symbol. If the symbol filed is empty, the chart symbol is used.
This question is very helpful when the trader already knows the stop loss distance and wants to trade the maximum volume based on the specified amount risked. Let’s suppose we want to calculate the trading volume to risk $100 in a 10 pips stop loss for EURUSD.
By using variables, we can accomplish more advanced calculations. For example, a trader may decide to risk 2% of the account balance in each trade. In that case, the trader would create the next items in Trading SM:
- A variable holding the account balance,
- An operation calculating the 2% of the previous variable,
- A stop loss distance variable.
- A variable using the Trading Volume question.
Stop Loss Distance
The Stop Loss Distance question is good for knowing the maximum stop loss distance based on the trading volume and the amount risked. The value obtained from this question can be used in a trading action.
A group of conditions make up a Rule. We use the Rules Creator to create rules. There, we add conditions by right-clicking the first item in the tree.
Once you have added all the conditions to the tree, you may decide whether all the conditions should be met at the same time or just one of them would be enough.
The “at least one” rule type is of great help when your trading strategy relies on several alternatives to trade. For example, you may trade when some indicator 1 arrow shows up or when some other indicator 2 arrow shows up. It does not matter which one shows up. Then, you would create an “at least one” rule with two conditions (one per indicator) and in the Actions Creator you would associate the corresponding trading action that would be activated every time an arrow shows up in either indicator.
But there is too much more you can do in the Rules Creator, you can create even more powerful trading strategies.
Now, suppose you rely your trading strategy on 4 different arrow indicators. Indicators 1 and 2 print green arrows and when show up in the same candle you want to buy. Indicators 3 and 4 print blue arrows and when show up in the same candle you want to buy.
Basically, you want to trade when indicators 1 and 2 give a trading signal at the same time or when indicators 3 and 4 give a trading signal at the same time. Instead, any other combination like indicators 1 and 3 or 1 and 4 do not imply a trading action. Note that, if we were using just the indicators 1 and 2, we would create an “all met” rule with two conditions (one per indicator). On the other hand, if we were using just the indicators 3 and 4, we would also create an “all met” rule with two conditions (one per indicator). Instead, both combinations are valid and we want to add them in the same rule.
We can create a single rule that will hold all this logic. First, we create an “at least one” rule and add two Subrules. In the first subrule, we add two conditions. Indicators 1 and 2 related conditions. In the second subrule, we add the indicators 3 and 4 conditions.
Finally, we associate a buy trading action with this rule.
That way we have added a more advanced logic to our trading.
This is just an example of what you can do with the Rules Creator but if you practice a little bit, you will find that you might also add subrules inside subrules and create complex trees with endless subrules and conditions.
Sometimes we want to use indicators that are not available in a default Metatrader installation. Metatrader refers to those indicators as custom indicators. We can also use those indicators in Trading SM but first we need to add them to the Indicators Panel. Let’s see an example of how we can add a custom indicator to Trading SM.
First of all, open Metatrader, select one custom indicator and attach the indicator to any chart. We will use the following Custom indicator: Calmed-Averages (Download). Open the inputs tab of your indicator.
The Inputs tab shows the parameters of the indicator. We need these parameters to add this custom indicator to Trading SM. Keep that window open, you will need to come back later.
Now, in Trading SM go to Tools -> Add Indicator. We need to introduce the name of the indicator. The name should be equal in TS Maker and Metatrader, otherwise the program will fail to get values from the indicator. A good approach in order to avoid possible mistakes is to copy and paste the name.
It is time to add the parameters of the indicator. This process is very simple but we need to pay attention to two important things: we need to respect the order of parameters as it is in the Inputs tab of Metatrader and select the right parameter type.
In Trading SM, we select the parameter type from a choice box. We have 3 options: Number, Text and True/False. Which one we select depends on the parameter icon in the Inputs tab of Metatrader.
- Number if icons are: or
- Text if icon is:
- True/False if icon is:
In contrast with what happened earlier in the name of the indicator, it doesn’t matter now whether the name of the parameter matches or not whilst you respect parameter order and type. Anyway, it is a good practice to assign the same names.
Using Custom Indicators
Once we have added the custom indicator to the Indicators Panel, we can create strategies that rely on that indicator.
If you come back to Metatrader and you look at the Calmed-Averages indicator, you see that the indicator prints two lines in the chart. In the Data Window, we can see the name the indicator assigns to those lines: Fast Line and Slow Line. If you mouse over the different bars, you see the different values of Fast Line and Slow Line in the Data Window.
From Trading SM, we can get those values. When we need to refer to these different values from Trading SM, we need to specify the order number. The first value is referred with the number 0, the second value with the number 1, the third with the number 2 and so on. In the Calmed-Averages indicator the Fast Line is the number 0 and the Slow Line is the number 1. Let’s create variables for getting Fast Line and Slow Line values of bar 1.
The same for bar 2.
Now, we can create a simple long crossover rule.
Getting Arrow Signals
Some custom indicators show arrow signals. For those that want to create Expert Advisors that rely on those signals, we are going to show you the best approach to accomplish this task.
We will use the Trend-Arrows custom indicator in this explanation. Download and install this indicator in Metatrader (Download). Once installed, add it to Trading SM.
Note that this indicator does not have parameters and so no parameters were added in Trading SM.
If you look at the Data Window in Metatrader, this indicator only shows values in bars where arrows are printed.
So, we need to detect when an arrow is printed in the last bar (bar 1). The first thing we do is create variables for each signal (buy and sell).
And then we use the Is Arrow Signal question to acknowledge whether there is a value or not.
Finally, we can create the corresponding conditions.
In the upper right hand corner of Trading SM, there is a General Settings button.
Right-click the General Settings button and a new dialog shows up. In the Mode tab, we can define the operation mode of the Expert Advisor. This is very helpful for Expert Advisor sellers that want to send testing or demo versions to their customers.
First, we can determine the account type in which the Expert Advisor will run: demo and real. Metatrader accounts can be demo or real. Check the corresponding boxes to enable/disable the Expert Advisor by account type.
Second, we can determine the Working Mode. In this section we limit the Expert Advisor usage to the Strategy Tester or to Live mode. By checking both boxes, it will run in both modes.
Metatrader users have an account number. You can see your account number in the upper left hand corner of Metatrader.
In the Account Protected tab you can limit the account numbers in which the Expert Advisor will run. Just click the Add button and introduce the account number.
Every time you attach an Expert Advisor to a chart in Metatrader a window shows up. In the About tab appears a link. Typically links to the owner’s website.
You can set the link text and URL in the Properties tab in the General Settings of Trading SM.
The documentation is formed by a Getting Started tutorial, chapters of several topics and a reference containig all the information related to questions and actions available in Trading SM.
Begin with the Getting Started tutorial to start creating trading robots.
Prior to compilation we need to specify two directories in Trading SM. Go to Tools -> Options.
There you need to specify the Metatrader 4 directory. It is the directory where your Metatrader terminal is installed. Usually at C:\Program Files (x86)\MetaTrader 4. Go to your “Program Files (x86)” directory and look for some Metatrader installation there.
Also you need to specify the “MT4 Experts” directory. This is the directory where your Metatrader terminal saves Expert Advisors. Usually at C:\Users\UserName\AppData\Roaming\MetaQuotes\Terminal\SomeWeirdFolderName\MQL4\Experts. You can get this directory from Metatrader.
Every time we are ready with our trading strategy we need to first save it.
And once saved, we can compile the program.
After compilation, the new Expert Advisor with the name assigned will be available in our Metatrader terminal.
The process of creating the Short Rule and its actions is very similar to the one used in the Long Rule.