SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Sep 15, 2019 1:11 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: QQQ Crash, QQQQ Trade
PostPosted: Wed Mar 21, 2007 1:38 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
The Nasdaq 100 (QQQ) index is fairly volatile because it contains so many technology stocks whose prices move around so much more than average non-technology stocks. The volatility of the QQQ has many sources, including rapid technological advances, competition, and sudden news that can affect stock prices. The strategy below waits for a big “crash� in the QQQ, where a crash is defined as QQQ prices moving below a lower Bollinger band set 1.5 standard deviations away from a 10-day moving average. While using 1.5 standard deviations is not unusual for Bollinger bands, the use of 1.5 with a short 10-day moving average is an unusual combination. To move below a lower Bollinger band that is based on a 10 day average requires a pretty drastic price move, because a fast 10-day average will stick closely to price movements. So this strategy looks for drastic drops in QQQ, buys long the morning after the crash (in OnBarOpen), and then trades the gap back up as usual. It exits when a profit is made, or after 30 days. We put this strategy under the volatility section because it uses methods that deliberately select volatile moves (1.5 standard deviations, 10 day average). In contrast, our other Bollinger band examples are listed under the range trading section, because they focus on slower moving averages and less volatile price moves.

Code:
using OpenQuant.API;
using OpenQuant.API.Indicators;

using System.Drawing;

public class MyStrategy : Strategy
{
   [Parameter("Order quantity (number of contracts to trade)")]
   double Qty = 100;
   
   [Parameter("Length of BBL")]
   int BBLLength = 10;
   
   [Parameter("Order of BBL")]
   double BBLOrder = 1.5;   
   
   [Parameter("Max number of bars, while position is active")]
   int MaxDuration = 20;
   
   // bollinger band, 10 days, 1.5 std deviation
   BBL bbl;
   // remember what you paid on entry
   double entryPrice;
   // exit after 20 days
   int barsFromEntry = 0;   
   // orders and quantity
   Order buyOrder;   

   public override void OnStrategyStart()
   {
      // set up bollinger bands
      bbl = new BBL(Bars, BBLLength, BBLOrder);
      bbl.Color = Color.Yellow;
      Draw(bbl, 0);
   }

   public override void OnBar(Bar bar)
   {
      // if we don't have a position and we have some bars
      // in the bollinger series, try to enter a new trade
      if (!HasPosition)
      {
         if (bbl.Count > 0)
         {
            // if the current bar is below the lower bollinger band
            // buy long to close the gap
            if (Bars.Crosses(bbl, bar) == Cross.Below)
            {
               buyOrder = MarketOrder(OrderSide.Buy, Qty, "Entry");               
               buyOrder.Send();
            }
         }
      }
      else
      {
         // else if we DO have an existing position, and if
         // today's bar is above our entry price (profitable),
         // then close the position with a market order
         if (entryPrice < bar.Close)
         {
            barsFromEntry = 0;
            
            Sell(Qty, "Exit (Take Profit)");
         }
         else
            barsFromEntry++;
      }
   }

   public override void OnBarOpen(Bar bar)
   {
      if (barsFromEntry == MaxDuration)
         Sell(Qty, "Sell");
   }

   public override void OnPositionOpened()
   {
      // when a position is opened, remember what we paid for
      // the instrument. Notice we use the average price of
      // all the partial fills that we might have received.
      entryPrice = buyOrder.AvgPrice;
   }

   public override void OnPositionClosed()
   {
      barsFromEntry = 0;
   }
}



Top
 Profile  
 
PostPosted: Thu May 19, 2011 5:22 pm 
Offline

Joined: Tue May 10, 2011 2:14 am
Posts: 23
Thanks Anton! I was looking for this one. It is referenced in the Strategy Guide but it doesn't come preloaded in OQ.

"QQQQ Gap Down 0.5%, Stock Down, Stock Gap 5" is also mentioned in the Strategy Guide but it is not preloaded in OQ and I can't find it.


Top
 Profile  
 
PostPosted: Thu May 19, 2011 6:23 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Hi,

I can see "QQQQ Crash, QQQQ trade" among other sample strategies on OQ Start Page... It's the last strategy there.

If it's not on the Start page, you can load it using File -> Open -> Solution...

Regards,
Anton


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

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