Four Down Day and Long

Discuss about Rules based Trading Strategies: Trend, No-trend, Mean Reversal...

Four Down Day and Long

Postby anh.do » Mon Mar 30, 2009 3:28 am

The rationale behind this simple pattern matching strategy is to enter a long position after a major market index has had 4 down days in a row. Theoretically, it is hard to maintain the down trend after four days in a major market, and an up day is soon to follow.

Thus, in this strategy, a buy order is issued at the market open on day 5 after 4 down days. Then, it just automatically issues a market sell order at the end of day 6 (when day 6 bar is received). The sell order will actually be executed by the exchange when the market opens on day 7.

In this daily bars trading strategy, the daily bar is received at the end of each trading day, in the OnBar event handler. The OnBar event handler is executed on the trailing edge of each bar, at time that corresponds to the end of the trading day for daily bars.


If you want to customize the strategy to do something at the market open before the daily bar is constructed then you should put your code in an OnBarOpen event handler.

Code: Select all
#region usings
/*
* Auto generated by Quant Solution - Quant Edge Corp
* Do not remove any items in this region 
*/
using System;
using System.Drawing;
using QuantEdge.BackTest;
using QuantEdge.BackTest.Base;
using QuantEdge.BackTest.Common;
using QuantEdge.BackTest.Common.Enums;
using QuantEdge.BackTest.Common.Attributes;
using QuantEdge.BackTest.Common.CurveOperator;
using QuantEdge.IDE.Entities.Solution;
using QuantEdge.TradeEdge.ChartLibrary.TechnicalAnalysis;
using QuantEdge.TradeEdge.ChartLibrary.TechnicalAnalysis.Indicator;
#endregion

public class Four_Down_Day_And_Long : BaseStrategy
{
   [Parameter("Order quantity (number of contracts to trade)")]
   int quantity = 100;

   [Parameter("Number of consecutive down closes")]
   int consClosesCount = 4;

   int count;
   Order buyOrder;
   Order sellOrder;


   public override void OnStrategyStart()
   {
      count = 0;
   }

   public override void OnBar()
   {
      if (PrevClose != -1)
      {
         // if we don't have a position open, increment the count of down days (or reset it to zero)
         if (!HasPosition)
         {
            if (PrevClose > bar.Close)
               count++;             
            else
               count = 0;
               
            // if this is the fourth (consClosesCount is equal to 4 by default) down day,
            // issue a market order to open a long position tomorrow morning, on day 5
            if (count == consClosesCount)
            {
               Buy(quantity, "Entry");
            }

         }
         else
            Sell(quantity, "Exit");
      }
   }

}
Attachments
Solution Result.JPG
Solution Summary.JPG
anh.do
 
Posts: 3
Joined: Wed Mar 25, 2009 5:48 am

Return to Strategies Place

Who is online

Users browsing this forum: No registered users and 1 guest

cron