SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Dec 15, 2019 1:33 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Wed Sep 16, 2009 6:36 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
Hi, I am completely new to the software. I am using TTAPI and managed to receive real time quotes. I would like to start with a very simple strategy, i.e. go long if volume of 3 trades in a row is higher than 50 ... or short if the same conditions are met...

Additionally, I am also eager to test entry in the event of volume on bid (or ask) in order book getting lower than 50, but have only bleak idea of how this could be done...

Could someone help me with the code for this please? Or at least redirect me to an example of something similar on the web?

Thanks in advance

All the best
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 16, 2009 7:26 pm 
Offline

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

have you looked through the Strategy Development Guide?

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 16, 2009 10:40 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
Hi Anton,
I have studied references but the only thing I can find are strategies based on bars ... and the problem is - I don't want to use bars, just process every single trade ...
Hope someone will be able to help me ... obviously reply to this thread does not have to contain whole code but I just need the structure, so I could follow with expanding the code further to my needs ...
thanks
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 10:03 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
There is no big difference between bars and trades or quotes from strategy programming point of view. All programming tips and techniques are the same, except it's a bit easier to program with bar arrays since they offer more helper methods.

Here is an idea for your entry rule.

Code:
OnTrade(Trade trade)
{
  int count = Trades.Count;

  if (count >= 3)
  {
   int volume = 0;

    for (int i=count-3; i=count-1; i++)
      volume += Trades[i].Size;

    if (volume > 50)
      Buy(100, "Entry")
  }
}


Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 11:29 am 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
Thank you Anton so much, you helped me so much... Do you mind showing similar piece of code for order book example?
Thanks so much once again
All the best
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 5:53 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
Based on above, Ive got this simples code to start with, but somehow, I am not getting the right price (returns 0). Volume is ok ... maybe I am confusing data types?


Code:
using System;
using System.Drawing;

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

public class MyStrategy : Strategy
{
   private double lastPrice;
   
   public override void OnStrategyStart()
   {
      
   }

   public override void OnTrade(Trade trade)
   {
      int count = Trades.Count;
      
      if (count >= 3)
      {
         int volume = 0;

         for (int i=count-3; i<=count-1; i++)
            volume += Trades[i].Size;
            lastPrice = Trades[count].Price;

         if ((volume > 100) && (!HasPosition))

            BuyLimit(1, lastPrice, "Entry");
      }
   }
   
   public override void OnPositionOpened () {
      // issue a target limit order whenever a position is opened
      SellLimit(1, lastPrice, "Exit");
   }

}




Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 6:14 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
ok, the problem with price was definition of lastPrice ... changed to public and works now


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 18, 2009 2:22 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
and I have one more question regarding this topic. Is it possible to have access to whole order book (i.e. 10 bids and 10 offers) instead of just best bid/offer?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 18, 2009 3:12 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
I think you should look at Strategy.OrderBook class in the API / docs and then search this forum for OrderBook.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 21, 2009 3:09 pm 
Offline

Joined: Wed Sep 16, 2009 6:26 pm
Posts: 27
Dear Anton,
I went through some sample codes from this forum, and finally managed to write some working strategies ... to be honest, this software is amazing. Congrats for such a great tool and your help too.
All the best
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 21, 2009 8:54 pm 
Offline

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 10, 2009 10:22 pm 
Offline

Joined: Sat Sep 26, 2009 12:08 am
Posts: 62
Location: Ireland
The above sample does not work.
I get 'index out of range' error on line
Code:
            lastPrice = Trades[count].Price;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 11, 2009 11:37 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Of course, the code should look like:
Code:
lastPrice = Trades[count - 1].Price;


Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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:  
Powered by phpBB® Forum Software © phpBB Group