Home Advanced Forex Education Forex System Design Designing a Trading Strategy – Part 2

Designing a Trading Strategy – Part 2

87
0

Introduction

Our previous article presented the three key elements of a trading strategy, which is the base of a trading system. In this second part of the designing process of a trading strategy, we will present the first component of a trading strategy corresponding to the entry and exit.

Trade Positioning and Trading Strategy

trade is made of at least by a buy order and a sell order. In other words, when, for example, the trader places a long position (buy), he should close it using a sell (cover) order.

On the other hand, a trading strategy with a positive expectation can identify and provide both long and short trading opportunities under a specific condition. Similarly, the strategy must be able to determine when to close the trading position and exit the market.

Generating Trading Opportunities

As we have seen in previous articles, a trading strategy is born from an idea that we believe might generate profits in any financial market. In this regard, the entry signals can vary from the simplest to the most complex requirement.

A buy position will arise when the price meets a condition for a bull market. On the contrary, a short position will activate if the market accomplishes the conditions for a bear leg. Some examples of long entries are:

  1. The 5-period fast moving average crosses over the 55-period slow moving average.
  2. The 65-period RSI oscillator closes above a reading of the 52-level.
  3. The price surpasses and closes above the high of the previous day.
  4. The price breaks and closes above the high of the 55-day range.

The definition of the exit rule of the trade must be considered from the basis that an open position in one direction must be closed with a position of equal size and opposite direction. For example, if the trader has opened a long trade, it will be closed with a selling trade. In this way, the developer should define a set of criteria that allow the execution of the closing of the trade. For example:

1) Closing the trade if the price advances 1.5 times the risk of the transaction.
2) The price reaches 3 times the ATR of 14 periods.
3) The rolling average of 5 periods crosses the average of 21 periods.

An example of Trading Signals using Metatrader 4

Metatrader 4 is one of the most popular trading platforms in the retail trading segment. Despite other trading platforms, such as TradeStation, Multicharts, or VisualChart, we will use Metatrader for our example. This platform includes the MetaEditor application, with which the creation of trading strategies can be developed through the programming of custom indicators.

In the following example, we show the creation of a custom indicator based on the crossing of two moving averages. This trading strategy uses a 5-period Weighted Linear Moving Average (Fast LWMA) and a 55-period Simple Moving Average (Slow SMA). 

Now it is time to define the entry and exit rules of our trading strategy as ideas and code rules for MetaEditor of MetaTrader 4.

The setting of each moving average period is as follows:

extern int Period1 = 5;
extern int Period2 = 55;

The entry criterion will occur as follows:

  • buy position will be activated when the LWMA(5) crosses above the SMA(55).
//Open Buy Order, instant signal is tested first
   if(Cross(0, iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_LWMA, PRICE_CLOSE, 0) >
 iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 0)) 
//Moving Average crosses above Moving Average
   )
     {
      RefreshRates();
      price = Ask;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
     }
  • sell position will trigger when the LWMA(5) crosses below the SMA(55).
//Open Sell Order, instant signal is tested first
   if(Cross(1, iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_LWMA, PRICE_CLOSE, 0) <
 iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 0)) 
//Moving Average crosses below Moving Average
   )
     {
      RefreshRates();
      price = Bid;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_SELL, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
     }
  }

The exit criterion will occur as follows:

  • buy position will be closed if the LWMA(5) crosses below the SMA(55).
//Close Long Positions
   if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_LWMA, PRICE_CLOSE, 0) <
 iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 0) 
//Moving Average < Moving Average
   )
     {   
      if(IsTradeAllowed())
         myOrderClose(OP_BUY, 100, "");
      else //not autotrading => only send alert
         myAlert("order", "");
     }
  • sell position will be closed if the LWMA(5) crosses above the SMA(55).
//Close Short Positions
   if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_LWMA, PRICE_CLOSE, 0) >
 iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 0) 
//Moving Average > Moving Average
   )
     {   
      if(IsTradeAllowed())
         myOrderClose(OP_SELL, 100, "");
      else //not autotrading => only send alert
         myAlert("order", "");
     }

Until now, we have not defined a money management rule or the position size for our trading strategy, just entries, and exits.

Conclusions

Entry and exit criteria are the basis of a trading strategy, which arises from an idea. The trading strategy’s essential objective is to obtain an economic profit from applying specific rules in both long and short positioning in the financial market.

In this educational article, we presented the case of a trading strategy based on two moving averages crossovers. In particular, we used the LWMA(5) as the signal moving average with an SMA(55) as the slow m.a.

In the following article, we will present some filters to avoid false signals.

Suggested Readings

  • Pardo, R.; The Evaluation and Optimization of Trading Strategies; John Wiley & Sons; 2nd Edition (2008).
  • Jaekle, U., Tomasini, E.; Trading Systems: A New Approach to System Development and Portfolio Optimisation; Harriman House Ltd.; 1st Edition (2009).

LEAVE A REPLY

Please enter your comment!
Please enter your name here