Introduction: MA Crossovers

Trading SM is very powerful because you can start creating trading robots very fast. In this Getting Started tutorial we see how simple it is to create an Expert Advisor.

Prior to start creating robots in Trading SM, we need a trading strategy in mind. In this tutorial we use a trading strategy that relies on Moving Average crossovers. Trading signals in this type of strategies come from crossovers between two Moving Averages: a Moving Average with shorter period (25) called Fast MA and a Moving Average with longer period (100) called Slow MA.

We want to open a Buy position when a new candle just opens and if in the previous candle (the one that just closes) the Fast MA closed above the Slow MA after being below. Also, we want to see a consistent cross and for that purpose we include a condition that checks the distance between Moving Averages in the candle that just closes (the first candle where Fast MA closes above Slow MA). The distance needs to be greater than some specific value (5 pips). We want to open a Sell position when the opposite conditions met. The chart below shows this Buy scenario.


From Trading SM perspective, each bar has a number. The bar that is being formed (the one that hasn’t already closed) is 0. The previous consecutive bars are 1, 2 and so on. Look at this in the above chart. Whenever you need to specify in Trading SM from which bar you need some specific value you need to bear this in mind.

Trading robots require some trading logic. In the end, every trading robot performs some trading actions based on some trading rules. So, the first thing we need to do is to describe the rule that will trigger a buy trading action and the rule that will trigger a sell trading action.

In the following lines, we see a simple description of this strategy indicating every trading rule that we use in this trading robot and the corresponding trading actions that each trading rule triggers. Each rule is made up of several trading conditions.

Trading Rules

1. Long


  • Long Condition 1: Is new bar equals true (A new bar just opens).
  • Long Condition 2: Total buy orders open equals 0 (we only want one order open at a time).
  • Long Condition 3: Fast MA in 2 less than Slow MA in 2
  • Long Condtion 4: Fast MA in 1 minus Slow MA in 1 is greater than 5 pips.


  • Long Action 1: Close Sell orders (if there is any).
  • Long Action 2: Open a Buy order.

2. Short


  • Short Condition 1: Is new bar is true (A new bar just opens).
  • Short Condition 2: Total sell orders open is 0 (we only want one order open at a time).
  • Short Condition 3: Fast MA in 2 greater than Slow MA in 2
  • Short Condtion 4: Slow MA in 1 minus Fast MA in 1 is greater than 5 pips.


  • Short Action 1: Close Buy orders (if there is any).
  • Short Action 2: Open a Sell order.


In the next chapter we’ll see how to create the Long rule with its conditions. So, if you haven’t already, open Trading SM and go to File -> New.