Announcement

Collapse
No announcement yet.

Object Oriented EFS Programming

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Object Oriented EFS Programming

    Greetings,

    In an effort to make my complex strategies more structured, I have decided to work on trying to make them Object Oriented.

    It seems a lot of routines used in EFS are objects, such as the IBBroker object, or the Strategy object that many people use for backtesting, for example.

    But what about creating our own classes to instantiate during runtime? For me, this is becoming almost invaluable; with lots of orders being sent off with different stops and profit targets, it would make my life a whole lot easier; as well as the people who read my code.

    I recently compiled a javascript interpreter in order to test my theories on the FreeBSD platform, as ESignal would make debugging them a little difficult (which is not a big deal). After this was done, I composed a small bit of testing code. Take a look at the following if you will.

    PHP Code:
    function whatever(id)
    {
        
    this.id id;
        
        function 
    bob()
        {
            return 
    this.id;
        }

        function 
    dobbs()
        {
            
    debugPrintln(this.id);
        }
    }

    function 
    main()
    {
        var 
    huh = new whatever(1);
        var 
    ehh huh.bob();
        
    debugPrintln(ehh);

        return 
    1;

    In this short example, I've created the class 'whatever'. It's instantiated inside the main(), as the object 'huh'. Inside the class I also defined two methods/functions, bob() and dobbs(). However, something goes wrong when I try to call them; But there are no syntax errors reported.

    When running this, you'll notice that no debug window output is given, when there clearly should be. Also, note that main() returns the value of 1; but there is never anything returned to the chart. This leads me to believe that either the execution is hung up somewhere, or that execution terminates completely.

    When calling a similar (obviously not exactly, as some of these routines are propriatary to EFS) routine in my own javascript interpreter, it outputs accordingly; as it should.

    Any input ESignal crew?

    Once I figure this out I'd like to write up a series of tutorials pertaining to this subject. I imagine a lot of people would find it very useful in developing their own custom trading systems.

    Cheers,
    Joshua C. Bergeron
    jcb@othernet / #ESignal
    Last edited by jbergeron; 03-08-2003, 09:30 PM.

  • #2
    Joshua,

    Here are some resources that may be of use:

    http://wsabstract.com/javatutors/object.shtm

    http://www.objenv.com/cetus/oo_javascript.html

    l
    Matt Gundersen

    Comment


    • #3
      Matt,

      Thanks for the information... Did you have a chance to look into the problems I was running into at all? Or am I just missing something?

      Thanks,
      Joshua C. Bergeron

      Comment


      • #4
        Hi Joshua,

        Nope, I didn't have a chance to look into the issues you listed. My guess is it may be syntax related. I'm not all that familiar with the OO approach you are taking in JS. But, from looking at other examples on the web, it looks like it can be done...

        m.
        Matt Gundersen

        Comment


        • #5
          Matt,

          I'm still trying to figure out what's going wrong, and was just wondering if you could answer a few questions about the javascript interpreter that ESignal uses...

          What version/release is it based off of? Any specifics like this available?

          As long as we're on the subject, I was also wondering if you ever had any plans to implement compilation of EFS sources into byte-code. I imagine it would increase performance significantly.

          Thanks,
          Joshua

          Comment


          • #6
            Joshua,

            What you are trying to do is an approach I haven't tried before.

            As to the version/release, it conforms to ECMA 262, Edition 3.

            As to byte-code, EFS does become byte code. When you add your script to the chart, it is interpreted once. During that interpretation (aka parsing) it becomes tokenized. Part of the tokenization includes optimization and making it 'byte code'.

            The script is not being interpreted every execution.

            m.
            Matt Gundersen

            Comment


            • #7
              Cool. Thanks for the information Matt. Keep up the good work.

              I will look into this further and see if I can rule out exactly what the problem I'm running into is. After I figure it out I'll explain a little more how I'm using an object oriented approach to EFS.

              Has anyone else tried this? Feel free to join in on this thread and give some input, eh?

              Obviously, EFS is designed to be a little more procedural, but I think applying an object oriented feel may help to increase capabilities. Hey, this is after all javascript, right? I realize of course that it's not truly OO, but it's close enough for me.

              Imagine an object that has some basic properties and methods like the following...

              PHP Code:
              var id 0;

              function 
              order(idsymbolpriceprofit_targetstop)
              {
                  
              this.order_id id;
                  
              this.symbol symbol;
                  
              this.price price;
                  
              this.profit_target profit_target;
                  
              this.stop stop;
                  
                  function 
              buy()
                  {
                       
              // dynaorder buy function whatever
                       // iborder buy function whatever
                       // strategy backtesting function whatever
                       // custom DLL calls, and the like.

                       
              return fill_price;
                  }

                  function 
              sell()
                  {
                      
              // etc etc etc
                  
              }

                  function 
              check_profit_target()
                  {
                      
              // etc etc etc
                  
              }

                  function 
              check_stop()
                  {
                      
              // etc etc etc
                  
              }
              }

              function 
              main()
              {
                  
              //buy and sell paremeters etc etc etc...
                  
              if (true false)
                  {
                      var 
              = new order(id++, getSymbolName(), close(), close() + 3close() - 1);
                      var 
              fill o.buy();
                  }

              Obviously this is just a quick thing I whipped up to help make people aware of the goal I'm looking to accomplish...From there we can take the concept much further, with profit target checking methods, stop price methods, support for all the common brokers that provide API's, like Dynaorder, IB, etc. whatever you want. Take it even further and have an array of order objects for all your orders... the possiblities are endless... for me a structure like this would be greatly beneficial

              Personally, I use Dynaorder for my order entry, and if anyone has worked with it before, I think they might agree when I say that it would definately be useful to have a system like this. Especially if you're shooting off lots of orders with varying profit targets and stops, trails, and the like, for positions when you're playing with multiple contracts. It would at very least beat having 45 global variables for all of your order_id's, entry price's, exit price's, stops, profit targets, etc.

              Further more, this is the kind of thing that a lot of people could copy/paste into their own code and re-use easily. All they would have to code is the buy and sell setup...

              I'm normally not too big about object oriented programming (I'm actually one of those silly UNIX / C people), but I certainly see some good benefits in using EFS like this.

              Just my two cents... Maybe some of the other coders have some input? I'd like to hear what you guys have to say.

              Cheers,
              Joshua C. Bergeron
              jcb@othernet / #ESignal
              Last edited by jbergeron; 03-09-2003, 08:25 PM.

              Comment


              • #8
                Welp, I think I figured out the problem, and as I'm sure we were both hoping, it was a simple error on my end.

                When the constructor function is called at the time the object is instantiated, I simply wasn't calling 'return' at the end of the function. Obviously, I shouldn't be returning a value, as that would give problems when instantiating the class, so I'm simply calling 'return;' at the end of the constructor. It is odd that it completely halts execution though?

                So, try this for example, and it should work.

                PHP Code:

                var some_id 0;

                function 
                bah(id)
                {
                    
                this.id id;

                    function 
                hi(message)
                    {
                        
                debugPrintln(message+" "+this.id);
                    }

                    return;
                }

                function 
                main()
                {
                    var 
                = new bah(some_id);
                    
                bah.hi(hellooo);
                    
                some_id++;

                Neat! So I guess I can get back to work now

                Cheers,
                Joshua C. Bergeron
                jcb@othernet / #ESignal

                Comment

                Working...
                X