Announcement

Collapse
No announcement yet.

PaperTrader

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

  • PaperTrader

    I have a new question about this feature. Yesterday morning, the code I'm developing for a client was firing orders and doing thing properly. In the afternoon yesterday, it was not firing orders because it was rejecting them (for some reason).

    Today, it's doing the same thing. It keeps rejecting orders because it thinks I'm trying to CLOSE a position when I have no positions open in the PaperTrader. Every time I try to fire a buyMarket() or sellMarket() it gives me an error...

    "New order ID = 70, Account = 473851, Symbol = ES #F, Exchange = AccountManager, Type = Market, Action = Sell, Quantity = 10"

    "Order 70 has been rejected. You cannot place closing order at the moment, you need to have an open position at the corresponding side first."

    Now, I'm not currently showing any position for the ES #F in the Papertrader and I don't know why it would stop taking orders. I've added debug lines into the code to see if it is anything I'm doing and I can't see anything in the EFS that would be causing this not to work.

    I've tried firing an order manually into the papertrader and it works perfectly. It even closes the position properly.

    Is there a way to reset the papertrader and start over with a new account? Can anyone assist me as to why these orders are being rejected from EFS when they worked (for a while) yesterday?
    Brad Matheny
    eSignal Solution Provider since 2000

  • #2
    I think I figured it out. I needed to use sellShortMarket() to execute the short triggers. Still testing.

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      I have another question I need answered..

      Do the paper trader MARKET orders go off at the CURRENT PRICE or at the BAR's OPENING PRICE?

      I'm watching the code I created and I have conditionals in the code to only fire the order when the current bar's CLOSE is at or above the specific price for entry/exit (and of course at or below for shorts). But what I'm seeing is these markets orders go off at the OPEN OF THE CURRENT BAR - not the actualy price the market is at now.

      Can anyone confirm this??
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Hi Brad,

        It should be at the current price. Make sure you're not using compute on close or enclosing the order inside a BARSTATE_NEWBAR condition.
        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
          Since you are paper trading you probably know the answer to this. How do you prevent it from ordering over and over once a condition is met? I defined a variable as vIsLong=0 then the expression says if vIsLong != 1 && so on to buy. The buy action then sets vIsLong =1 so that the expression won't execute until you change vIsLong to 0. But it doesn't work. It orders over and over on each tick.

          Comment


          • #6
            Hello marvslater,

            You would simply set a flag once your signal has triggered and add a check for the flag to your conditional statement. The first time during the bar that your signal triggers set the flag to true. Your condition should be looking for a value of false for this flag. At BARSTATE_NEWBAR or some other condition that you design, you can reset the flag back to false, which would allow your conditional code to trigger again if desired.

            You may want to look at the code sample in the library called, AlertOncePerBar.efs. This contains the coding process I've described.
            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


            • #7
              I use the "strategy" system. If you are using control variables, those will work too.

              An example of what I'm doing is like this.

              PHP Code:

                
              if ((!Strategy.isLong()) && (BuyNow)) {
                  
              Strategy.doLong("LE"Strategy.THISBARStrategy.LIMITContract2Tradeclose());
                  
              buyMarket(Contract2Trade);
                } 
              This way, the Strategy system acts as my control variable for the trading system status. Just trying to take advantage of items that are available within EFS to make things easier.
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment


              • #8
                I'm a real amateur. Still having trouble. When I put in flag it stops all trades. Won't trade at all. Without it, it racks up continous trades. I want it to buy 100 shares and hold it until it reaches a sell condition then just sell the 100 shares. Then wait until the next buy condition comes along and start all over again. Sorry to be such a dolt but I can't seem to get it to do that.

                Comment


                • #9
                  Marv,

                  That's probably because you need to add the opposite strategy triggers when you exit a trade.

                  You use

                  Strategy.doLong() - to go long
                  Strategy.doSell() - to go exit a long
                  Strategy.doShort() - to go short
                  Strategy.doCover() - cover a short trade.

                  These functions control the internal strategy features and if you use them properly, you can use them to control a trading system's operation.

                  The parameters for each of these are the same. You can control how and when the strategy system gets in and out of a trade.

                  If you review the knowledge base and other training info, you'll see more examples.

                  B
                  Brad Matheny
                  eSignal Solution Provider since 2000

                  Comment


                  • #10
                    I have tried to use the Strategy system in Simulated trading during real time (not the back tester), and failed to get them to work. Should they work in an EFS in real time, or are they only workable within the back tester?

                    In particular, the Strategy.isInTrade is most desireable. Appreciate any reply.

                    Cheers

                    Merv

                    Comment


                    • #11
                      it does work in realtime too. The only trick is HOW you place your order and what types of error checking you do when placing your orders..

                      For example, if you fire your orders PROPERLY, you only need to use the strategy system to control the trading system conditions.

                      Here is some sample code to see how I do it.

                      PHP Code:
                      var contracts2trade 1;

                      //  Going Long
                       
                      if (timetogolong) {
                               
                      Strategy.doLong("LE"Strategy.CLOSEStrategy.THISBAR);
                               if (
                      vPTONOFF) {  
                                 if (
                      ActivePosition 0) {
                                  
                      closePosition(getSymbol());
                                  
                      ActivePosition 0;
                                 }
                                 
                      buyMarket(getSymbol(), (ActivePosition+contracts2trade), "Account Manager"473851SB_DAY);
                                 
                      ActivePosition contracts2trade;
                               }
                               
                      drawShapeRelative(-1low(), Shape.UPARROW""Color.greennull"LE" getValue("time"));
                        }

                      //  Going Short
                       
                      if (timetogoshort) {
                               
                      Strategy.doShort("SE"Strategy.CLOSEStrategy.THISBAR);
                      //  This controls the paper trader functions. vPTONOFF is a logical to tell if paper trading in ON or OFF
                               
                      if (vPTONOFF) {  
                                 if (
                      ActivePosition 0) {
                                  
                      closePosition(getSymbol());
                                  
                      ActivePosition 0// tracks our current position
                                 
                      }
                                 
                      buyMarket(getSymbol(), (ActivePosition+contracts2trade), "Account Manager"473851SB_DAY);
                                 
                      ActivePosition contracts2trade;
                               }
                               
                      drawShapeRelative(-1high(), Shape.DOWNARROW""Color.rednull"Se" getValue("time"));
                        } 
                      Brad Matheny
                      eSignal Solution Provider since 2000

                      Comment


                      • #12
                        [QUOTE]Originally posted by Doji3333
                        [B]it does work in realtime too. The only trick is HOW you place your order and what types of error checking you do when placing your orders..

                        For example, if you fire your orders PROPERLY, you only need to use the strategy system to control the trading system conditions.

                        Thank you, Doji. Your code has given me heaps to research. Can't wait til market open on Monday to begin. Thanks for your help.Saved me days of "experimenting"

                        Cheers

                        Comment


                        • #13
                          Multiple Trades

                          Thanks Doji. I used the backtrade/Wizard commands. At first I still had a problem with it placing multiple orders. It would run the instruction over and over. Problem was I constructed it using ETF Wizard and then added the paper trade instruction buyMarket to it. It still bought over and over until I removed the Wizards Strategy commands. Makes sense. Can't have paper trade orders and back test orders in same program. Duh!

                          Comment


                          • #14
                            Actually, you can have both in one program. You simply have to create code to handle the BT mode vs. the RT PT mode.

                            EFS provides everything you need to develop very complex analysis systems. It's simply a matter of "conditionalizing" the triggers for BT vs. RT mode.

                            If you need more help, just let me know?
                            Brad Matheny
                            eSignal Solution Provider since 2000

                            Comment


                            • #15
                              I envy your knowledge. Though new to EFS, I have found my way around the language reasonably well, and have found it simple to place and close orders in real time. I have not as yet been successfull in using the BT commands. The commands I miss most are the ability to confirm my entry request was successful and I am actually in a trade, and the price I actually entered at. If I persist with Back Testing commands, am I going to be able to achieve either of these conditions?

                              To date I have entered/exited at market, which always works. Not much sense in placing a limit order if I have no way of knowing if it has been filled. Can you help with a sample of code that achieves this? Ideally a sample that places a limit order, confirms when the order was filled, fill price, closes the order, and confirms the order was closed, and exit price.

                              What is possible?

                              Thanks

                              Mervk

                              Comment

                              Working...
                              X