Preventing Whipsaw: MA Gradients and trading with the Trend

Taking a quick look at the journal entries May 31st and June 10th showed that there is some benefit to calculating the gradient of the moving averages. This can be used in two places

  1. Can be used to discourage new trades if the trade direction is against the current gradient direction.
  2. Can be used as an indicator that we are stuck in a sideways market (gradient is fairly flat) and perhaps not a good time to open new trades

To see if this works, I developed a new oscillator that shows a histogram of the gradient of the curves. There was some difficulty in calculating the angle. Calculating an angle needs to perform the math.atan(opp/adj) however adj is a measure in time. Therefore, we can make the adj value anything we like. This is the same as changing the chart scaling, or zooming in and out, and watching the steepness of the curve change. Not only that, how many bars back do we go?

To solve this problem I did some experimenting. I defined something called GradientPeriods which is the number of bars to go back. Looking at the 1H chart for AUDJPY, over a 2-3 day period, showed me some gradients I would consider steep, and others not steep. This lead me to come up with a factor of 0.115 that can be used to multiply the GradientPeriods. This produced values that looked pretty good.

One other thing to keep in mind is the tan/atan functions operate in radians so this needs to be converted too.

Illustration of the first point.

The effectiveness of this is immediately seen by looking at the journal entry for June 10th. By looking at the screenshot it is clear that the new trade would not have been opened if it cross checked against the gradient. However, this needs to be tested as this depends on the number of periods used.

Looking at the image below, we can see the top histogram with a GradientPeriods of 10, and the bottom histogram with a GradientPeriods of 1. The lower one immediately responds which produces higher values (values at 23:00 are Upper-5 and Lower-25), but also immediately reports the direction. The upper one is much smoother however.

Need to do some testing to see what GradientPeriods would be better for preventing the loss trades in this scenario.

Illustration of the second point.

Backtesting Omar (6,19) shows two loss trades on 21st of May 2013 and 23rd of May 2013. Looking at what the gradient of the slow curve was at these times, it was very low, less than 5 degrees using a GradientPeriod of 10.

By optimizing, it should be possible to find a gradient value which can be used as a floor to prevent new trades from opening unless the gradient is steeper. Hopefully this can prevent loss trades in a sideways market.

Posted in Backtesting, Indicators, Research, Trend and tagged , , , , .

One Comment

  1. Pingback: Preventing Whipsaw using a Gradient Calculation | MooMoo Forex Trading

Leave a Reply

Your email address will not be published. Required fields are marked *