SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Sep 26, 2018 4:24 am

All times are UTC + 3 hours




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

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6808
This example is just like the one above, except that it also requires that the previous bar (the previous day) was a down day for the stock, in addition to gapping down 2% at today’s open.

Code:
using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   [Parameter("Order quantity (number of contracts to trade)")]
   double Qty = 100;

   [Parameter("Percent")]
   double Percent = 2;   
   
   private Order sellOrder;
   
   private double prevClose;
   
   private bool downDay = false;
   
   public override void OnBar(Bar bar)
   {
      prevClose = bar.Close;
      
      downDay = (bar.Open > bar.Close);
      
      if (HasPosition)
      {
         sellOrder.Cancel();
         
         Sell(Qty, "Exit");
      }
   }

   public override void OnBarOpen(Bar bar)
   {   
      if (downDay)
      {
         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