StraTrader
Search:

Strategy Workflow

The StraTrader strategy is a DLL that contains class implementing ITickerStrategy interface (and optionaly a class implementing IProjectStrategy interface). Usualy you would create a class based on TickerStrategy and ProjectStrategy, which are abstract classes so you have to implement some methods.

Empty Ticker Strategy class looks like this:

000: using System;
001: using StraTrader;
002: using StraTrader.Lib;
003: using StraTrader.Strategy;
004: using System.Drawing;
005: using System.Collections;
006: using System.Collections.Generic;
007:
008: public class MyTickerStrategy : TickerStrategy
009: {
010:     protected override void DoInit()
011:     {
012:     }
013:     protected override void DoProcessBar()
014:     {
015:     }
016:     protected override void DoProcessTrade()
017:     {
018:         ITrade lastTrade = Ticker.Trades.Last;
019:
020:         if (LastTrade != null)
021:         {
022:             ... do_something ...
023:         }
024:     }
025:     protected override void DoReset()
026:     {
027:     }
028: }
  • DoInit function is called only once when strategy starts running. Strategy initialization should be done here. Typically you would create indicators here
  • DoProcessBar is then called on every bar. You shuold have your buy/sell logic in this function.
  • DoProcessTrade is called once a new order was filled and a new trade was generated. The trade is always the last one in the Trades collection of current ticker, in strategy code it can be accessed as Ticker.Trades.Last.
  • DoReset this function is called once in the end of strategy run. You can have your custom cleanup code in this function.

StraTrader strategy can also have a class implementing IProjectStrategy interface. Project Strategy filters orders placed by Ticker strategies. It can cancel them, change order prices, order volumes, etc.

Empty Project Strategy class looks like this:

000: using System;
001: using StraTrader;
002: using StraTrader.Lib;
003: using StraTrader.Strategy;
004: using System.Drawing;
005: using System.Collections;
006: using System.Collections.Generic;
007:
008: public class MyProjectStrategy : ProjectStrategy
009: {
010:     protected override void DoInit()
011:     {
012:     }
013:     protected override void DoBeforeBar()
014:     {
015:     }
016:     protected override void DoAfterBar() 
017:     {
018:         IOrders thisBarOrders = Project.Orders.GetSubset(true);
019:
020:         foreach (IOrder order in thisBarOrders)
021:         {
022:             ... adjust_or_cancel_this_order ...
023:         }
024:     }
025:     protected override void DoReset()
026:     {
027:     }
028: }
  • DoInit function is called in the beginning of the strategy run before DoInit functions in Ticker Strategies. You can do your initialization here.
  • DoBeforeBar function is called on every bar before DoProcessBar functions in Ticker Strategies. In this function you can adjust some parameters of Ticker Strategies that would affect Tickers on current bar.
  • DoAfterBar function is called on every bar after DoProcessBar functions in Ticker Strategies. You can analize orders placed on this bar in all ticker and cancel or adjust some of them. You can cancel order by calling Cancel function on order object; you can adjust order by changing its Volume or Price properties.
  • DoReset is called in the end of the strategy run after DoReset functions in Ticker Strategies. You can place your cleanup code here.


About Us   Contact Us   Download   ©2007-2009 Mike Kramarenko in association with SmartProj.com