My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
LessonParamPrompt  
Prompting the user for parameters
Updated Jan 1, 2011 by j...@pracplay.com

Often times you want to tweak or play with parameters of your strategy, either in testing or sometimes on per day/week/symbol basis.

To do this you use ParamPrompt.

Steps

You can look at the box GreyExit in Box-Examples for a demonstration of how to use ParamPrompt.

Assignment :

  1. Add a using statement for 'System.ComponentModel'
  2. Add a reference to System.Windows.Forms Assembly to your project (if not already there)
  3. Setup Properties with get/set accessors for all the variables you want to prompt for
  4. add descriptions for these variables
  5. load a paramprompt and show it to the user

If you want to do this yourself for your own project, get started. Otherwise we'll walk you through it.

Walkthrough

lets take our lesson 3 and expand it with prompting

    public class LessonParamPrompt : ResponseTemplate
    {
        BarListTracker _blt = new BarListTracker();
        PositionTracker _pt = new PositionTracker();
        int MINBARS = 10;
        [Description("Minimum bars this strategy needs to trade.")]
        public int MinBars { get { return MINBARS; } set { MINBARS = value; } }
        decimal MAXVOL = .5m;
        [Description("Maximum average HL range allowed for trading.")]
        public decimal MaxVolatility { get { return MAXVOL; } set { MAXVOL = value; } }
        public override void GotTick(Tick tick)
        {
            // create bars from ticks
            _blt.newTick(tick);
            // make sure we have enough bars our indicator
            if (!_blt[tick.symbol].Has(MINBARS)) return;
            // get highs from our bar
            decimal[] highs = _blt[tick.symbol].High();
            // get lows
            decimal[] lows = _blt[tick.symbol].Low();
            // compute high low ranges
            decimal[] hlrange = Calc.Subtract(highs, lows);
            // compute average range
            decimal avghl = Calc.Avg(hlrange);
            // ignore volatile symbols
            if (avghl > MAXVOL) return;
            // compute MA
            decimal ma = Calc.Avg(_blt[tick.symbol].Close());
            // trading rule
            if (_pt[tick.symbol].isFlat && (_blt[tick.symbol].RecentBar.Close > ma))
                sendorder(new BuyMarket(tick.symbol, 100));
            // exit rule
            if (_pt[tick.symbol].isLong && (_blt[tick.symbol].RecentBar.Close < ma))
                sendorder(new MarketOrderFlat(_pt[tick.symbol]));

        }

        public override void GotFill(Trade fill)
        {
            _pt.Adjust(fill);
        }
        public override void GotPosition(Position p)
        {
            _pt.Adjust(p);
        }
    }}}}

Now you're set.  

Sign in to add a comment
Powered by Google Project Hosting