Announcement

Collapse
No announcement yet.

stop price must be greater than 0

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

  • stop price must be greater than 0

    I got the error message "Stop price must be greater than 0".
    What is wrong with my code? The current price is about 142.50 in edemo.


    function preMain() {
    setPriceStudy(false);
    setStudyTitle("ATS_IBBridge_Testing");
    setShowCursorLabel(false);
    //setComputeOnClose();
    }

    function main( ) {

    if ( getBarState() == BARSTATE_ALLBARS ) {

    setStudyMax(100);
    setStudyMin(0);

    displayBuySellButtons();
    }

    }



    function clickBuyMkt() {
    buyMarket("SPY", 100);
    sellStop("SPY", 100, formatPriceNumber(140.00)*1);
    //sellStop("SPY", 100, formatPriceNumber(140.00));
    }

    function clickSellMkt() {
    sellMarket("SPY", 100);
    buyStop("SPY", 100, formatPriceNumber(145.00)*1);
    }
    Last edited by clearpicks; 01-17-2007, 04:11 AM.

  • #2
    Stop price must be greater than 0

    I got the error message "Stop price must be greater than 0".
    What is wrong with my code? The current price is about 142.50 in edemo. I tried various ways to pass the stop price, such as

    sellStop("SPY", 100, formatPriceNumber(140.00)*1);
    sellStop("SPY", 100, formatPriceNumber(140.00));
    sellStop("SPY", 100, 140);

    But none of them works.

    - Clearpicks




    function preMain() {
    setPriceStudy(false);
    setStudyTitle("ATS_IBBridge_Testing");
    setShowCursorLabel(false);
    //setComputeOnClose();
    }

    function main( ) {

    if ( getBarState() == BARSTATE_ALLBARS ) {

    setStudyMax(100);
    setStudyMin(0);

    displayBuySellButtons();
    }

    }



    function clickBuyMkt() {
    buyMarket("SPY", 100);
    sellStop("SPY", 100, formatPriceNumber(140.00)*1);
    //sellStop("SPY", 100, formatPriceNumber(140.00));
    }

    function clickSellMkt() {
    sellMarket("SPY", 100);
    buyStop("SPY", 100, formatPriceNumber(145.00)*1);
    }

    Comment


    • #3
      Hello Clearpicks,

      First, try assigning the stop price to a variable outside the function and then pass the variable to the parameter.

      var nStop = formatPriceNumber(140.00)*1;
      sellStop("SPY", 100, nStop);
      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


      • #4
        Jason,

        This method does not work either.

        - Clearpicks

        Originally posted by JasonK
        Hello Clearpicks,

        First, try assigning the stop price to a variable outside the function and then pass the variable to the parameter.

        var nStop = formatPriceNumber(140.00)*1;
        sellStop("SPY", 100, nStop);

        Comment


        • #5
          Hello clearpicks,

          I just tested the following method on my end using the attached formula, which worked. The code method used is as follows.

          sellStop(getSymbol(), vSize, close(0)-nStopLimitAmt);



          Try removing formatPriceNumber() from the scenario for now and see if that changes anything.

          Also, I'm assuming you are using the latest IB plug-in and TWS versions with eSig 8.0 (build 782)? Please confirm.
          Attached Files
          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


          • #6
            Jason,

            Thanks very much for that very useful piece of code that no automated strategy should be without!

            Can you please tell me the purpose of the Global "Trade" variable?

            What do you think of the feasibility of using a stop order to initiate an position on a non-standard chart type (P&F, PB, renko), as a means of circumventing the lag/slippage issue where normally a market order is sent only after the boxes, bricks are painted?

            The problem that I'm seeing for many strategies is that the backtester using these alternative chart types records prices that
            show unrealistic profits compared to results seen in tick replay?

            I thought about getMostRecentTrade() but as you know if a brick doesn't get build encompassing that price range, then a strategy can get stopped into a position, outside the "awareness" of the EFS and outside of a methodology to manually reset the EFS with the position status I can't think of a way to resync?

            Thanks Glen.
            Glen Demarco
            [email protected]

            Comment


            • #7
              Jason,

              Thank you. It works now.

              It didnot work when i first time ran it. After I upgraded eSignal from build 799 to build 782 and reinstalled IBBridge which I installed two days ago, your testing script is working seemlessly.

              Could you explain the difference between sellStop() and sellShortStop()? I think in case of Interactivebrokers, there is no difference, right? Maybe it is only related to up tick short rule?


              - Clearpicks



              Originally posted by JasonK
              Hello clearpicks,

              I just tested the following method on my end using the attached formula, which worked. The code method used is as follows.

              sellStop(getSymbol(), vSize, close(0)-nStopLimitAmt);



              Try removing formatPriceNumber() from the scenario for now and see if that changes anything.

              Also, I'm assuming you are using the latest IB plug-in and TWS versions with eSig 8.0 (build 782)? Please confirm.

              Comment


              • #8
                Jason,

                Do these APIs also work under FA account?

                - Clearpicks

                Comment


                • #9
                  Hello Glen,

                  Originally posted by demarcog
                  Jason,

                  Thanks very much for that very useful piece of code that no automated strategy should be without!
                  You're most welcome.

                  Can you please tell me the purpose of the Global "Trade" variable?
                  That is a switch that is used to enable or disable the buttons. You should see a button in the lower left corner that initially says "disabled." Right click on the button to enable the trading buttons. This routine is not necessary for this particular study as each trade event requires a mouse click to invoke. I included it anyway to illustrate how to disable the functions so that when a formula is loading or reloading it will automatically become disabled so that unwanted trades are not sent off to the broker. You would want to include this routine in any real time formulas that are automatically submitting trades based on formula conditions.

                  What do you think of the feasibility of using a stop order to initiate an position on a non-standard chart type (P&F, PB, renko), as a means of circumventing the lag/slippage issue where normally a market order is sent only after the boxes, bricks are painted?
                  This is not something I can advise you on. You will have to try some of these things to see if it will suit your needs. However, I would not recommend using EFS on the renko chart type due to the known drifting bug.

                  The problem that I'm seeing for many strategies is that the backtester using these alternative chart types records prices that
                  show unrealistic profits compared to results seen in tick replay?
                  This is because back testing formulas can only process completed bars whereas tick replay evaluates each tick. You cannot expect these two scenarios to match up.

                  I thought about getMostRecentTrade() but as you know if a brick doesn't get build encompassing that price range, then a strategy can get stopped into a position, outside the "awareness" of the EFS and outside of a methodology to manually reset the EFS with the position status I can't think of a way to resync?

                  Thanks Glen.
                  I'm not sure I understand what you're asking here. Remember that in back testing you cannot use getMostRecentTrade() as that is a real time only function. Instead, you would need to use close(0). Hope that helps.
                  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


                  • #10
                    Hello Clearpicks,

                    Originally posted by clearpicks
                    Jason,

                    Thank you. It works now.

                    It didnot work when i first time ran it. After I upgraded eSignal from build 799 to build 782 and reinstalled IBBridge which I installed two days ago, your testing script is working seemlessly.
                    You're most welcome. Thank you for the update.

                    Could you explain the difference between sellStop() and sellShortStop()? I think in case of Interactivebrokers, there is no difference, right? Maybe it is only related to up tick short rule?


                    - Clearpicks
                    The sellStop() function would be used to close an existing long position. It would be placed below the market. The sellShortStop() would be used to enter a short position, which is also placed below the market. They have nothing to do with the up tick short rule specifically. That is a general rule that would apply to any short trade. The order would simply remain pending until the up tick rule can be satisfied. That's my understanding anyway.

                    Also, what is FA account? At any rate, you could try the GBoker_Tester.efs with it to see if the GB functions work on it.
                    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


                    • #11
                      Hello Jason,

                      FA account means Financial Advisor account in IB. It is used as a master account to manage multiple subaccounts. When trade within a master account, the shares or contracts bought would be distributed to those subaccounts according to the allocation profile being used.

                      Regarding to sellStop() and sellShortStop(), since IB TWS does not have the order type "Sell Short Stop", basically if there is no position in the account, the sell stop order is considered as sell short stop, otherwise it is a sell stop. I do see some other brokers request to specify whether an order is a sell short order or sell order (to liquidate existing positions).

                      - Clearpicks


                      Originally posted by JasonK
                      Hello Clearpicks,



                      You're most welcome. Thank you for the update.



                      The sellStop() function would be used to close an existing long position. It would be placed below the market. The sellShortStop() would be used to enter a short position, which is also placed below the market. They have nothing to do with the up tick short rule specifically. That is a general rule that would apply to any short trade. The order would simply remain pending until the up tick rule can be satisfied. That's my understanding anyway.

                      Also, what is FA account? At any rate, you could try the GBoker_Tester.efs with it to see if the GB functions work on it.

                      Comment


                      • #12
                        FA Accounts

                        Originally posted by clearpicks
                        . . . Do these APIs also work under FA account?
                        - Clearpicks
                        Hi Clearpicks,
                        Our trading interface doesn't currently support FA Accounts, but we're planning to include the necessary logic in the next maintenance release.
                        We don't have a date yet, but we are planning to add free charts to QuoteTrader using IB data, sometime in Q1 - which may be an opportunity.


                        I'll let you know if we do the work then,

                        Brent
                        Trading Services Product Management
                        QuoteTrader
                        Trading Services email

                        Comment


                        • #13
                          Originally posted by JasonK
                          [B]Hello Glen,



                          This is because back testing formulas can only process completed bars whereas tick replay evaluates each tick. You cannot expect these two scenarios to match up.
                          I can understand some difference between the backtester and real time, but I'm using a 1 minute .10 brick on GOOG and routinely seeing a .50-1.00 difference between the Paperbroker fill price and the recorded backtested fill price when I compare the trades at the end of the day.



                          I'm not sure I understand what you're asking here. Remember that in back testing you cannot use getMostRecentTrade() as that is a real time only function. Instead, you would need to use close(0).
                          I was referring to realtime or tick replay I was wondering if somehow I could send out a stop order to initiate a position for a price that may or may not occur at some future point. If I have a SAR strategy on a Renko chart for example, I can't wait unitl the bars get painted to execute my order because it can be way beyond the stop price.

                          I can however once the SAR is calculated send out an order to be stopped into a position at some future time.

                          The problem is how do you inform the EFS that you were filled on an order that was sitting there for some length of time. Especially on a Renko chart where the bars may not even be build encompassing that range?

                          I thought perhaps using the getMostRecentTrade() would in that event at least give me a reasonable certainty that I was filled.

                          Anyway I don't want to monopolize anymore of you time and am actually partially answering my own questionas I write this.

                          As always all your help is greatly appreciated.

                          Glen
                          Glen Demarco
                          [email protected]

                          Comment


                          • #14
                            Hello Glen,

                            Originally posted by demarcog
                            I can understand some difference between the backtester and real time, but I'm using a 1 minute .10 brick on GOOG and routinely seeing a .50-1.00 difference between the Paperbroker fill price and the recorded backtested fill price when I compare the trades at the end of the day.
                            If the trades that are being recorded in the Paperboker are generated by intra-bar real time signals, they cannot be expect to match up with the back test results that are based on completed bar signals.

                            I was referring to realtime or tick replay I was wondering if somehow I could send out a stop order to initiate a position for a price that may or may not occur at some future point. If I have a SAR strategy on a Renko chart for example, I can't wait until the bars get painted to execute my order because it can be way beyond the stop price.

                            I can however once the SAR is calculated send out an order to be stopped into a position at some future time.

                            The problem is how do you inform the EFS that you were filled on an order that was sitting there for some length of time. Especially on a Renko chart where the bars may not even be build encompassing that range?
                            At this time we do not have any functions available to check the status of pending orders by order ID. The exit strategy in this case will need to be managed manually.

                            I thought perhaps using the getMostRecentTrade() would in that event at least give me a reasonable certainty that I was filled.
                            This function simply returns the same as close(0) in real time. It has nothing to do with any orders placed by GB functions.

                            Anyway I don't want to monopolize anymore of you time and am actually partially answering my own questionas I write this.

                            As always all your help is greatly appreciated.

                            Glen
                            Thank you. You're questions are always welcomed. Others will most certainly benefit from your threads as well.
                            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


                            • #15
                              Jason,

                              Originally posted by JasonK




                              If the trades that are being recorded in the Paperboker are generated by intra-bar real time signals, they cannot be expect to match up with the back test results that are based on completed bar signals.



                              I'm using close(0) on a renko chart and at times multiple bars can be built simultaneously with the same time stamp, and the backtester records what after the fact looks like the correct price, but in realtime the price recorded is actually sometimes several timestamped bars in the future.



                              This function simply returns the same as close(0) in real time. It has nothing to do with any orders placed by GB functions.


                              I thought for Renko charts this time and sales functions would reflect current trade information which can be outside the range of Barindex(0) which is not possible with a normal bar or candle chart. My objective was to see if I could determine price range outside the scope of the current bar's range.


                              thanks very much....
                              Last edited by demarcog; 01-19-2007, 01:07 PM.
                              Glen Demarco
                              [email protected]

                              Comment

                              Working...
                              X