Announcement

Collapse
No announcement yet.

Problem With Generic Broker Functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem With Generic Broker Functions

    Hi All,

    Help, attached is my current EFS. The stop loss generic broker functions work great, but for some reason neither buy() or buyMarket() are not working, same for sell.

    The alerts and debugs seem to work fine but no order is being submitted to the paper broker on a tick replay.

    Its odd, the trailing stop functionality works great.

    Could somebody please spare me the benefit of their wisdom ?

    Many Thanks

    Roger
    Attached Files
    Last edited by rogerha; 08-09-2007, 05:06 AM.

  • #2
    Hello Roger,

    The central problem with your formula code is that you are using back testing logic for real time analysis (or tick replay) with the use of the Strategy object. The Strategy object is for back testing only for the strategy analyzer report. You need to track your position states used in conditional statements with your own custom global variables to replace all instances of the Strategy object methods (i.e. Strategy.xxxx() ).
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Hi Jason,

      Thanks for the response. I see what you are saying, but can that affect the script in the following way (because this is what is happening):

      In the following block of code, every line is successfully being executed except the buy() or buyMarket() including crucially the alert and the debug:

      if (Strategy.isInTrade() == false) {

      if ( (high(0) > nU) ) {

      drawShape(Shape.UPARROW, BelowBar2, Color.black, nCntr);
      buyMarket( getSymbol(), lotsize );
      buy(getSymbol());
      Alert.addToList( "Euro", "Long", Color.green, Color.black );
      debugPrintln("Long");
      Strategy.doLong("Long Signal", Strategy.LIMIT, Strategy.THISBAR, lotsize, nU+0.0001 );

      nStop = Math.max( low(-1), (open(0)-xATR.getValue(0)) )
      }
      }

      The same problem is happening for the short entry.

      However in this block of code, everything including the cancelallOrders() and sellStop() are working absolutely fine:

      if (Strategy.isLong() == true && getBarState()==(BARSTATE_NEWBAR) ) {

      //if (close(-1)>open(-1) && (low(-1) - 3* xATR.getValue(-1))>nStop ){
      if ( Math.max ( (low(-1) - 3* xATR.getValue(-1)), (low(-1)-0.0030) ) > nStop ){
      nStop = Math.max ( (low(-1) - 3* xATR.getValue(-1)), (low(-1)-0.0030) );
      }
      //}

      if (isLastBarOnChart()==true){
      cancelAllOrders();
      sellStop(getSymbol(), lotsize, nStop );
      }
      }

      So whilst I am not disputing what you are saying, I am failing to understand why if the logic is working fine (and yes there is backtesting functionality included in the logic), that only the broker functions are not working ? And even then, only the broker functions on the trade entry ? Are you saying the existance of the backtesting functionaility itself can affect the submission of generic broker orders ?

      Can you please clarify your thinking ?

      Thanks again for your time.
      Last edited by rogerha; 08-10-2007, 02:15 AM.

      Comment


      • #4
        Hello Roger,

        The buyMarket() function is working properly. It does get executed by your current code and submits trades to the paper broker when the corresponding conditions evaluate to true. The debugPrintln() statement and pop up alert also executes when the rest of the code block executes. The conditions may not be evaluating as you are expecting them to due to logic issues I described in my previous reply. I would recommend implementing my suggestion and move forward from that point.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          I hope this helps...

          If you are trying to create a single piece of code to execute in real-time and also produce historical backtest results, then you have to handle things a bit differently...

          first, for all realtime operations, you have to make sure you are running in the esignal adv. chart on the current bar "in realtime". I use this ...

          (getCurrentBarIndex() == 0) // this is the current bar in RT

          You would have one set of code to manipulate the "Strategy" functions, execute your trades to the paper broker, set your variables and draw graphics/alerts.

          Then, you have a different set of code to handle "historical backtests". I use.

          (getCurrentBarIndex() < 0) // anything other than 0 is a historical bar.

          So, by comtaining your logic within these two conditions should allow you to build what you want. I can look at your code if you want, but basically, you want to "organize" your logic and functions..

          For example..

          PHP Code:

          if (time_toTrade) {
           if ( (
          buysignal) && (!Strategy.isLong()) ) {
              
          drawshaperelative...
              
          drawtextrelative
             
          if (getCurrentBarIndex() == 0) & (AutoTrade)) {
                
          fire orders to broker
             
          }
               
          Strategy.doLong("LE"Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, );
              
          set other variables here
           
          }

          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Thanks Jason/Doji,

            Well I thought Doji that was nearly what I had. I had prevously separated the Generic Broker functions with a little isLastBarOnChart()=true function, but had removed it for testing.

            However what I will do is make use of the template you have suggested and go through it again. I notice that you use the Strategy.isLong() functionaility in nearly the same way as me, but I have seen some nuances between what I have done and what you have suggested.

            I'll review the code later today and see if I can find the problems.

            Thank you both once again for your continued help and interest. I will provide the revised code later today.

            Roger

            Comment


            • #7
              I got to the bottom of the problem. The entry logic was fine, although Doji I have put it into your format because it looks a lot clearer and is much more logical.

              The problem was with the trailing stop routine, it was being executed straight after the entry routine (staring me in the face), and the entry order was immediately being cancelled by the cancelAllOrders() in the trailing stop routine.

              Anyway I have fixed that which has given me a couple of smaller problems which look to be of a similar issue, so I will gradually work through those.

              I just wanted to thank Jason/Doji though for their time !

              Comment


              • #8
                Roherha,

                Could you tell me whether closeOrders(symbol) works or not on your computer? Thanks.

                - Clearpicks

                Originally posted by rogerha
                I got to the bottom of the problem. The entry logic was fine, although Doji I have put it into your format because it looks a lot clearer and is much more logical.

                The problem was with the trailing stop routine, it was being executed straight after the entry routine (staring me in the face), and the entry order was immediately being cancelled by the cancelAllOrders() in the trailing stop routine.

                Anyway I have fixed that which has given me a couple of smaller problems which look to be of a similar issue, so I will gradually work through those.

                I just wanted to thank Jason/Doji though for their time !

                Comment


                • #9
                  Hi Clearpicks,

                  I have never even heard of that, I have heard of cancelOrder() and closePosition().

                  Sorry.

                  Comment


                  • #10
                    Mike,

                    I haven't forgotten that I said I would test that out for you. But I've not been able to test those functions yet as I'm having problems getting this version of the plugin going. Soon as I get this up I'll let you know.

                    Glen
                    Glen Demarco
                    [email protected]

                    Comment


                    • #11
                      It was a typo. It should be cancelOrders(symbol).


                      Originally posted by rogerha
                      Hi Clearpicks,

                      I have never even heard of that, I have heard of cancelOrder() and closePosition().

                      Sorry.

                      Comment

                      Working...
                      X