SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Sep 17, 2019 10:04 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Mar 21, 2007 2:07 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
The rationale behind this simple breakout strategy is to take advantage of a big (4%) daily move upward that would likely squeeze all those short sellers who were hoping the stock would go down. This strategy thinks that moving 4% up in a single day is such a big move that it would scare all the short sellers into covering their positions by buying long, thereby driving the price up even further the next day. (Of course, contrarian traders would be thinking of going short the next day, to take advantage of a price recovery to lower levels.) This strategy uses the OnBarOpen event handler, so that all trading events take place at the beginning of the day, at market open (on the leading edge of the daily bar). As each day begins, the strategy calculates an entry price 4% higher than yesterday’s close, and issues a limit order to open a long position if that price is reached. The next morning, if a position exits (opened during yesterday’s trading), the strategy issues a market order to close the position.

Code:
using OpenQuant.API;

public class MyStrategy : Strategy
{
   [Parameter("Order quantity (number of contracts to trade)")]
   int Qty = 100;
   
   // enter trade on 4 breakoutPercent breakout
   [Parameter("Percent")]
   double BreakoutPercent = 4;
   
   // orders and trade quantity
   Order buyOrder;
   // for calculating breakout price limit
   double prevClose;

   public override void OnStrategyStart()
   {
      prevClose = -1;
   }

   public override void OnBarOpen(Bar bar)
   {
      // we need to let the first bar go by before we can
      // calculate the breakout limit
      if (prevClose != -1)
      {
         // if we do not have a position, then cancel the
         // previous limit order (it is out of date)
         if (!HasPosition)
         {
            if (buyOrder != null)
               buyOrder.Cancel();

            // now try to enter a trade by setting a limit order
            // to automatically buy in if the big 4% jump arrives.
            // This order will reside on the exchange servers, and
            // will execute during the day if the limit is triggered.
            double breakout_fraction = 1 + (BreakoutPercent / 100);
            double breakout_price = prevClose * breakout_fraction;
            buyOrder = BuyStopOrder(Qty, breakout_price, "Entry");   
            buyOrder.Send();
         }

            // if we have a position open, then close it now.
            // Now (which is the leading edge of today's daily bar)
            // is the start of the day after the trade was opened.
         else
            Sell(Qty, "Exit");
      }
   }

   public override void OnBar(Bar bar)
   {
      // update the prevClose value for the breakout calculation
      prevClose = bar.Close;
   }
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group