SmartQuant Discussion

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

All times are UTC + 3 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Stock 2% gap
PostPosted: Wed Mar 21, 2007 1:43 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
This example watches for a stock to gap down 2%, then buys the gap (long) to close the position when the gap closes, or at the end of the next bar after the gap bar. So this strategy only holds a position open for 1 bar length of time. But we present the example here using daily bars, to make the explanation more intuitive. Here is the code for the entire component, including the boilerplate sections of (1) assembly references and (2) class headers. To save space, later examples will omit the boilerplate assembly references, strategy component attributes, and class headers. These bits of code are all essentially the same, for all examples.

Code:
using OpenQuant.API;

public class MyStrategy : Strategy
{
   [Parameter("Gap percent")]
   double Percent = 2;

   [Parameter("Order quantity (number of contracts to trade)")]
   double Qty = 100;

   double prevClose;
   Order sellOrder;

   public override void OnBar(Bar bar)
   {
      prevClose = bar.Close;

      if (HasPosition)
      {
         sellOrder.Cancel();

         Sell(Qty, "Exit");
      }
   }

   public override void OnBarOpen(Bar bar)
   {
      if ((prevClose - bar.Open) / prevClose > Percent / 100)
         Buy(Qty, "Entry");
   }

   public override void OnPositionOpened()
   {
      sellOrder = SellLimitOrder(Qty, prevClose, "Limit Exit");
      sellOrder.Send();
   }
}


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