SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Jul 22, 2018 7:11 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Sun Jun 24, 2007 10:16 pm 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
Dr. Anton Fokin wrote:
actually most of people are lazy :wink:


I agree with you to certain extent. Hence, if you have more strategy examples implemented in OpenQuant, you will sure increase your sales many times.

The following link has many strategies in MT4. If you go to the forum and offer them the code in OpenQuant, your sales will increase immediately. You can code one that is the most popular one first and see the effect.

http://www.forexfactory.com/forumdisplay.php?f=71


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 4:04 pm 
Offline

Joined: Fri May 06, 2005 1:40 am
Posts: 520
TickJob wrote:
Hence, if you have more strategy examples implemented in OpenQuant, you will sure increase your sales many times.


Many companies promote their trading products the same way once a month over at Stocks & Commodities Magazine www.traders.com which has a code section in response to each months articles . OQ code submissions over there would also raise its visibility considerably as TickJob points out. (If SQ were to start raising OQ's visibility in this manner in various places, it would be great to hear about it via the news release section so existing customers could also benefit :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 6:15 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
here has tons of sample strategies code example in MT4:
http://www.forexmt4.com/_MT4_Experts/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 4:06 pm 
Offline

Joined: Sun Mar 05, 2006 6:29 pm
Posts: 65
Location: England
I do think krn_2k has a good point in mentioning Stocks & Commodities Magazine. This appears to be a simple, cheap yet effective method for raising OQ's profile to serious traders. It would also provide yet more example code - of which there can never be too much ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 4:26 pm 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
in volatile market, any how choose two price levels and start rolling also can win, I guess Anton is not keen in marketing OpenQuant. :lol:

Image

I have modified the code as follows, basically to adjust the range to account for slippage and also change the lot size to 1, 3, 7, 15, 21....

Code:
using System;
using System.Drawing;

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

public class MyStrategy : Strategy
{   
   [Parameter("High")]
   public double High;
   
   [Parameter("Low")]
   public double Low;
   
   [Parameter("Close positions on strategy stop")]
   public bool CloseOnStop;
   
   
   
   
   private double slippageAdjust = 1;
   private double Range = 10;
   private double delta = 10;   
   private int ocaCount = 0;   
   private double High_dyn = 0;
    private double Low_dyn = 0;
   
   private int n = 1;
   private double nQty = 0;
   private int ntrade = 0;
   private double tickSize = 0.01;
   private double profitmultiply = 1;
   private double filledprice = 0;
   private int Qty = 1;   
   private int longshortdecimals = 1;
   private int rangedecimals = 5;
   private int qtydecimals = 1;
   private int slippagedecimals = 1;
   private int smadecimals = 30;
   private double sma1length = 100;
   private int longshort = 1;
   private bool getDecimals = false;   
   
   Order order1;
   Order order2;
   Order limitOrder;
   Order stopOrder;

   private bool started;
   
   public override void OnStrategyStart()
   {
      if (Instrument.TickSize != 0)
         tickSize = Instrument.TickSize;       
   
      getDecimals = int.TryParse(Instrument.Description.Substring(0,1), out longshortdecimals);
      if (getDecimals)
      {
         longshort = longshortdecimals;      // 1 is long, 0 is short
      }
      
      getDecimals = int.TryParse(Instrument.Description.Substring(2,2), out rangedecimals);
      if (getDecimals)
      {
         Range = tickSize*rangedecimals;     
      }      

      High_dyn = High;
      Low_dyn = Low;
      High_dyn = Math.Round(High_dyn/tickSize) * tickSize;
      Low_dyn = Math.Round(Low_dyn/tickSize) * tickSize;         
      Range = High_dyn - Low_dyn;
      Range = Math.Round(Range/tickSize) * tickSize;                     
      delta = profitmultiply*Range;            
      delta = Math.Round(delta/tickSize) * tickSize;      
      
      
      
      getDecimals = int.TryParse(Instrument.Description.Substring(5,5), out qtydecimals);
      if (getDecimals)
      {
         Qty = qtydecimals;     
      }      
      
      getDecimals = int.TryParse(Instrument.Description.Substring(11,1), out slippagedecimals);
      if (getDecimals)
      {
         slippageAdjust = slippagedecimals;   
      }      

      getDecimals = int.TryParse(Instrument.Description.Substring(13,3), out smadecimals);
      if (getDecimals)
      {
         sma1length = smadecimals;   
      }            
      
      
      started = false;
   }
   
   public override void OnStrategyStop()
   {
      if (CloseOnStop)
      {
         if (HasPosition)
         {
            if (Position.Side == PositionSide.Long)
               MarketOrder(OrderSide.Sell, Position.Qty).Send();
            else
               MarketOrder(OrderSide.Buy, Position.Qty).Send();
         }
      }
   }

   public override void OnBar(Bar bar)
   {
       
      if (!HasPosition && !started)
      {
         started = true;
         
         order1 = StopOrder(OrderSide.Buy,  Qty, High_dyn);
         order2 = StopOrder(OrderSide.Sell, Qty, Low_dyn);
         
         ocaCount++;
         
         string id  = Clock.Now.Ticks.ToString();
         
         order1.OCAGroup = id  + ": " + Instrument.Symbol + " " + ocaCount;
         order2.OCAGroup = id  + ": " + Instrument.Symbol + " " + ocaCount;
         
         order1.Send();
         order2.Send();
      }
   }
   
   public override void OnPositionChanged()
   {
      if (HasPosition)
      {         
         
         ntrade++;
         
         if (ntrade == 1)
         {
            if (order1.AvgPrice > order2.AvgPrice)
            {
               filledprice = order1.AvgPrice;
               if (filledprice > High_dyn)
               {
                  High_dyn = filledprice;               
               }                     
            }
            else
            {
               filledprice = order2.AvgPrice;
               if (filledprice < Low_dyn)
               {
                  Low_dyn = filledprice;
               }               
            }
         }
         else
         {
            if (limitOrder.AvgPrice > stopOrder.AvgPrice)
            {
               filledprice = limitOrder.AvgPrice;
               
               if (filledprice > High_dyn)
               {
                  High_dyn = filledprice;               
               }                           
               if (filledprice < Low_dyn)
               {
                  Low_dyn = filledprice;
               }                  
            }
            else
            {
               filledprice = stopOrder.AvgPrice;
               if (filledprice > High_dyn)
               {
                  High_dyn = filledprice;               
               }                                 
               if (filledprice < Low_dyn)
               {
                  Low_dyn = filledprice;
               }                  
            }
         }
         
         High_dyn = Math.Round(High_dyn/tickSize) * tickSize;
         Low_dyn = Math.Round(Low_dyn/tickSize) * tickSize;         
         Range = High_dyn - Low_dyn;
         Range = Math.Round(Range/tickSize) * tickSize;                     
         delta = profitmultiply*Range;            
         delta = Math.Round(delta/tickSize) * tickSize;   
         filledprice = Math.Round(filledprice/tickSize) * tickSize;   
         n++;   
         nQty = (Math.Pow(2, n)-1);
         Console.WriteLine("{0}     ntrade: {1}  nQty: {2}  filledprice = {3}    High: {4}     Low: {5}     Range: {6}     delta: {7}     Qty: {8}", DateTime.Now, ntrade, nQty, filledprice, High_dyn, Low_dyn, Range, delta, Position.Qty);
         

         
         
         if (Position.Side == PositionSide.Long)
         {
            ocaCount++;
         
            limitOrder = LimitOrder(OrderSide.Sell, Position.Qty, High_dyn + delta);
            stopOrder  = StopOrder (OrderSide.Sell, Position.Qty + (Qty * nQty), Low_dyn);
         
            string id  = Clock.Now.Ticks.ToString();
             
            limitOrder.OCAGroup = id  + ": " +  Instrument.Symbol + " " + ocaCount;
            stopOrder.OCAGroup  = id  + ": " +  Instrument.Symbol + " " + ocaCount;
         
            limitOrder.Send();
            stopOrder.Send();   
         }
       
         else
         {
            ocaCount++;
         
            stopOrder  = StopOrder (OrderSide.Buy,  Position.Qty + (Qty * nQty), High_dyn);
            limitOrder = LimitOrder(OrderSide.Buy, Position.Qty, Low_dyn - delta);

            string id  = Clock.Now.Ticks.ToString();

            limitOrder.OCAGroup = id  + ": " + Instrument.Symbol + " " + ocaCount;
            stopOrder.OCAGroup  = id  + ": " + Instrument.Symbol + " " + ocaCount;
         
            limitOrder.Send();
            stopOrder.Send();
         }

         

      }   
      else
      {
         
         if (limitOrder.AvgPrice > stopOrder.AvgPrice)
            filledprice = limitOrder.AvgPrice;
         else
            filledprice = stopOrder.AvgPrice;            

         filledprice = Math.Round(filledprice/tickSize) * tickSize;                                 
         Console.WriteLine("{0}     ntrade: {1}  nQty: {2}  filledprice = {3}    High: {4}     Low: {5}     Range: {6}     delta: {7}     STOP", DateTime.Now, ntrade, nQty, filledprice, High_dyn, Low_dyn, Range, delta, Position.Qty);
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 10:37 am 
Offline

Joined: Mon Oct 22, 2007 6:59 am
Posts: 17
Hi,guys,I have just copy and paste above code to test it in the latest version of openquant (1.0.50) in simulation mode and pompt up following error warning :

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at MyStrategy.OnStrategyStart() in d:\Program Files\SmartQuant Ltd\OpenQuant\Projects\Double Side Breakout\code.cs:line 56
at OpenQuant.Trading.StrategyRunner.Online()
at OpenQuant.Runner.Do()

I guess something wrong with this line :
getDecimals = int.TryParse(Instrument.Description.Substring(0,1), out longshortdecimals);

can somebody hlp me to figure this out?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 12:31 pm 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
See the picture below, in each of the Instrument->Property->Description field, I have the following input parameters, and there is segment of code to read these parameters. You can design your own. But for quick testing, just use what are shown in the following picture.

X(1 digit): longshort (0=short, 1=long)
XX(2 digits): Range (number of ticks)
XXXXX(5 digits): Qty (number of units in forex, number of lot in future)
X(1 digit): slippageAdjust (number of ticks)
XXX(3 digits): sma1length (length of simple moving average)


Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 2:08 pm 
Offline

Joined: Mon Oct 22, 2007 6:59 am
Posts: 17
Great ,TickJob,It get to work.Thanks a lot for your hlp man!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 5:26 am 
Offline

Joined: Tue Sep 11, 2007 6:36 am
Posts: 28
I'm having trouble using Forex with IB.

I've defined the Instrument exactly as you have in your picture. When I try to download historical data from IB using Data > Import > Historical data (beta) > IB, then select the instrument (GBP USD) and then choose 1 minute bars, I get the error message:

Historical Market Data Service error message:No historical market data for GBP/CASH@IDEALPRO Last 60

Any clues as to how to enter the instrument properly for use with IB?

TIA,
- AO


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 8:59 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
see picture below, use "MidPoint".

Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 9:04 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
and make sure you enter the correct instrument parameters as shown below example GBP USD.

Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 01, 2007 2:13 am 
Offline

Joined: Tue Sep 11, 2007 6:36 am
Posts: 28
Thanks, that worked! I'm now having a look at what your strategy does...

TIA,
- AO


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 15, 2008 2:18 pm 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
Hi Tickjob,

I recently had a look at your first post where you describe the breakout strategy, and I tried to do the same thing with FDAX. The equity curve looks almost like yours (btw: the pic(s) with the equity curve do not show up anymore in this thread).

BUT: As you already mentioned, these DrawDown peaks are the biggest problem. For example, in my backtest from Dec07 - Feb08 there is a big DD spike at the beginning of December as you can see on the attached pic. The DD was 160.000 and therefore would ate up the whole account. I tried all kind of stop loss strategies to prevent this to happen, but nothing worked.

So I came to the conclusion, that this kind of strategy produces nice equity charts, but does not work with real trading. Because somewhere in time, the strategy will not stop to change direction and double the lots/contracts until you run out of money.


Attachments:
Breakout_smaller.JPG
Breakout_smaller.JPG [ 120.43 KiB | Viewed 6916 times ]
Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 22, 2008 3:50 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
Hi flotschie,

You can go through those high DD trades to see whether there are some "patterns" so that you can avoid them. For example, you may want to avoid certain quiet trading hours. Another way is to find some patterns to start the run.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 22, 2008 11:33 am 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
ok thx for the reply, i will have a look on that, although i am not really convinced. Because - once you are involved in a trade, you can not jump off until the bitter end...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

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