예제 #1
0
        // initialization routine, called once before ticks are sent
        // if multiple tick sources are used, will get called several times
        // during the lifetime of the object, once per tick source change
        public override void Init(string pParameters)
        {
            // save parameters sent in case they contain optional parameters
            RealParameters = pParameters;
            // a Parameter Parser can be instantiated to check optional parameters
            RParser = new ParameterParser(pParameters);

            // this is a mandatory list of parameters.
            // Optional parameters are not specified here
            // they need to be checked before DParser.Merge is called
            // or checked from the RealParameters variable
            DefaultParameters = "PERIODLONG:17;PERIODSHORT:2;MINUTES:10;DELTA1:0.0005;DELTA2:0.0016;";

            // parameters as specified by the user
            PParser = new ParameterParser(pParameters);
            // mandatory parameter list and default values
            DParser = new ParameterParser(DefaultParameters);

            // make a list of parameters from mandatory list
            // merge user values if existing, otherwise use defaults
            Parameters = DParser.Merge(PParser);

            // build a new parameter parser with sanitized parameter and values
            // now user values have been merged with desired parameters
            // extraneous, or optional parameters eliminated.
            PParser = new ParameterParser(Parameters);

            // get periods to use for the indicator(s)
            PeriodsLong  = (int)PParser.GetDouble("PERIODLONG", 0);
            PeriodsShort = (int)PParser.GetDouble("PERIODSHORT", 0);;
            Delta1       = PParser.GetDouble("DELTA1", 0);
            Delta2       = PParser.GetDouble("DELTA2", 0);

            // now indicators must be instantiated

            // your indicator instantiation goes here

            // end of indicator instantiation

            // instantiate candlebuilder with desired timeframe
            Minutes = (int)PParser.GetDouble("MINUTES", 0);
//			cbx = new cCandleBuilder(Minutes,PeriodsLong+PeriodsShort+1);
            cbx = new cCandleBuilder(Minutes, PeriodsLong + PeriodsShort + 20);

            // register candlebuilder as a tick listener, name unimportant
            Framework.TickServer.RegisterTickListener("cbx", "*", cbx);
            // register this object as a candle listener
            // the candle name is important since we might receive
            // several candles with same period.
            cbx.RegisterCandleListener("cbx", this);
            // multiple candlebuilders can be setup by using previous 4 lines.

            // register this object as a tick listener, name unimportant
            // this is an optional step to receive ticks in between candles
            Framework.TickServer.RegisterTickListener("System", "*", this);

            // start header line of numerical output file
            Framework.WriteGraphLine("InTrade,Margin,AvgMRLong,AvgMRShort,Der2,MaxAbsDer2");
        }
예제 #2
0
        public static void ParameterParser()
        {
            Framework.Logger(2, "Parameter Parsing Test");

            /*
             *      MACDF:8-16,2; MACDS:12-24,2; MACDSG:7-9; EMA:26; STOK:3; STOKS:2; STOD:3;
             *      MACDF:12; macds:26; MACDSG: 9 ; EMA: 26 ; STOK:3 ; STOKS:2 ; STOD:3
             *      P: 14
             *      IN: *.CSV ; OUT: *.CSV
             */

            string opt  = "MACDF:8-14,2; MACDS:12-16,2; MACDSG:7-9; EMA:26; STOK:3; STOKS:2-3,0.2; STOD:3; FLAG:TRUE";
            string val1 = "MACDF:12; macds:26; MACDSG: 9 ; EMA: 26 ; STOK:3 ; STOKS:2 ; STOD:3; TRUE-RANGE:TRUE";

            ParameterParser pp1 = new ParameterParser(opt);
            ParameterParser pp2 = new ParameterParser(val1);
            ParameterParser pp3 = new ParameterParser("IN: *.CSV ; OUT: *.CSV");

            double v1 = pp1.GetDouble("flag", -1);
            string v  = "";

            Framework.Logger(0, "started opt with: " + opt);
            while (pp1.GetOptimizationParameters(ref v))
            {
                Framework.Logger(0, v);
            }

            Framework.Logger(0, "started opt with: " + val1);
            while (pp2.GetOptimizationParameters(ref v))
            {
                Framework.Logger(0, v);
            }

            string infile  = pp3.GetString("in", null);
            string outfile = pp3.GetString("out", null);
        }