Announcement

Collapse
No announcement yet.

paper trading

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

  • paper trading

    I'm new to esignal and looking for some step by step instructions for paper trading my efs program.

    I took the sample_targetstop.efs program I found on the knoweldge base modified it for the moving average indictors I wanted in my strategy. See attached program.

    Then I went to menu option trade -> order ticket designer and choose "execute efs" for the action and typed in my efs study and typed in the name of my efs formula in the efs textbox.

    Then I loaded my formula and went to menu option trade -> attach order ticket

    I not sure what to look for or what else to do beyond this or if the types of orders my code places do not work for paper trading and would appreciate some assistance.

    Thanks,
    Pete
    Attached Files

  • #2
    Hello Pete,

    The formula you have posted is a back testing study. It is only intended to be used with the Strategy Analyzer. Aside from that, the formula is not set up to be used with the execute efs button type in the Attached Order Ticket. That feature is used execute a specific function that exists in your formula. Such a function could be used to draw an image on the chart as well as send a trade using the Generic Broker Functions.

    If the study you posted operates in real time to your liking, what you could then do is set up the buttons in the Order Ticket Designer as trade buttons. When your formula generates an alert, click on the corresponding trade button to submit the trade. If the Paper Broker under Trade-->Preferences is set as your default broker, you should see the trade in the Paper Broker Window.
    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
      Jason,

      So I should replace code like Strategy.doSell() with the generic broker functions like SellMarket(). Please confirm.

      And if I use these functions can I just call the SellStopLimit() and SellShortStopLimit() functions once right after the code to get me into a trade to set my stop loss.

      Also instead of setting up trade buttons that I have to click on is there a way to automate placing the paper trades. If so how can I do this?

      Thanks,
      Pete

      Comment


      • #4
        Hello Pete,

        Originally posted by petec
        So I should replace code like Strategy.doSell() with the generic broker functions like SellMarket(). Please confirm.
        That is correct.

        And if I use these functions can I just call the SellStopLimit() and SellShortStopLimit() functions once right after the code to get me into a trade to set my stop loss.
        Yes.

        Also instead of setting up trade buttons that I have to click on is there a way to automate placing the paper trades. If so how can I do this?
        Yes, just call those functions directly in your formula similar to how you call the Strategy functions for a back testing formula.
        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
          paper trading

          Jason,

          I finally had some time to try putting some of your sugestions to use and ran into a snag.

          You confirmed that in order to paper trade my efs strategy I can replace code like Strategy.doSell with generic broker functions like SellMarket(). But what about other code like Strategy.isInTrade() or Strategy.isShort that gives me info about my current position. What are the equivilant functions I need to use for paper trading? I searched the knowledge base and forum but did not find anything other than mehtods of the strategy object.


          Thanks,
          Pete

          Comment


          • #6
            My solution..

            I create logical control variables for those... Like this...

            var StrategyisInTrade = false;
            var StrategyisLong = false;
            var StrategyisShort = false;

            Then, when I trigger orders, I set these variables (as needed) to true/false...

            That way I can use them in my code - like this...

            if (StrategyisInTrade) {
            if (StrategyisLong) {

            }
            if (StrategyisShort) {

            }
            }

            if ((BuyTrigger) && (!StrategyisLong)) {
            // Do Long Entry
            }
            if ((SellTrigger) && (!StrategyisShort)) {
            // Do Short Entry
            }
            Brad Matheny
            eSignal Solution Provider since 2000

            Comment


            • #7
              paper trading

              I continue to have problems figuring out how to paper trade my efs program.

              I thought that paper trading would execute trades on a go forward basis. But when I ran the program it ends up executing trades when a buy/short condition occurs on a previous bar as that historical date is loaded.

              The first solution that comes to mind is to add conditional logic to only execute trades if the getCurrentBarIndex()=0. This seems like a cludgy work around so I figured I'd ask if their was a better way to do it.

              What I really need is a basic efs framework where all I need to do is add my logical conditions to the section that sets the value of the:
              1) buy trigger
              2) short trigger
              3) sell long trigger
              4) cover short trigger

              I started by taking a sample EFS backtesting framework and trying to modify it. Is there another sample efs program that you can recommend I start with as a base framework.

              I have attached a copy of my efs program.

              Thanks,
              Pete
              Attached Files

              Comment


              • #8
                Re: paper trading

                Hello Pete,

                Originally posted by petec
                I continue to have problems figuring out how to paper trade my efs program.

                I thought that paper trading would execute trades on a go forward basis. But when I ran the program it ends up executing trades when a buy/short condition occurs on a previous bar as that historical date is loaded.

                The first solution that comes to mind is to add conditional logic to only execute trades if the getCurrentBarIndex()=0. This seems like a cludgy work around so I figured I'd ask if their was a better way to do it.
                That is indeed what the paper broker will do for you. The problem you're having is two-fold. There are a couple minor logic errors in your code. The other problem you have already identified. For the logic errors, there are a couple instances where you have a "." in the middle of the variable name. Remove the period from the instances where you see Strategy.isShort or Strategy.isLong. This will actually add to your short position. Use buyMarket() instead. As you have noticed, the trade calls will be executed while the formula is loading. You need to incorporate some logic into the formula code to prevent this. One way is to add the condition you described before each trade call.

                PHP Code:
                if (getCurrentBarIndex() == 0buyMarket(getSymbol(), 100); 
                This is the probably the quickest solution. You could also change the code logic so that you check for the bar index at the beginning of main and set a Boolean flag to true once the formula starts processing at bar 0.

                PHP Code:
                var bTrade false;

                function 
                main(nProfitAmtnStopAmt) {
                    if (
                bTrade == false && getCurrentBarIndex() == ) {
                        
                bTrade true;
                    }

                ... 

                Then pull all of the trade calls out into a separate function and have that function check against the flag before submitting a trade. That way all the logic for the trade signals can still be formatted on the chart for viewing without any trades being sent to the broker. Replace the trade calls with a custom function name such as doTrade(type). For type, enter a string for the trade type you want to execute. For example, replace the trade calls such as buyMarket(getSymbol(), 100) with doTrade("buyMarket"). Then in the doTrade() function, you could do something like the following.

                PHP Code:
                function doTrade(type) {
                    if (
                bTrade) {
                        switch (
                type) {
                            case 
                "buyMarket" :          // go long or cover short
                                
                buyMarket(getSymbol(), 100);
                                break;
                            case 
                "sellMarket" :         // exit long
                                
                sellMarket(getSymbol(), 100);
                                break;
                            case 
                "sellShortMarket" :    // go short
                                
                sellShortMarket(getSymbol(), 100);
                                break;
                        }
                    }
                    
                    return;

                There are many ways to accomplish this task. This is just one suggestion. You could also take a look at the code in the formula examples listed in the EFS Knowledgebase article, Generic Broker Functions (see IB.efs). This formula uses some buttons drawn on the chart that require the user to click on to enable the trades to be sent but you could incorporate the Enabled/Disabled logic into your formula. See the editParameters function in the IB.efs formula.


                What I really need is a basic efs framework where all I need to do is add my logical conditions to the section that sets the value of the:
                1) buy trigger
                2) short trigger
                3) sell long trigger
                4) cover short trigger

                I started by taking a sample EFS back testing framework and trying to modify it. Is there another sample efs program that you can recommend I start with as a base framework.

                I have attached a copy of my efs program.

                Thanks,
                Pete
                The formula you started with is as good an example as I can think of. You are on the right track with your current formula. After making some of the changes I've suggested you'll see that more clearly. You probably have some additional strategy logic to work out, but this should get you going in the right direction. For other examples, you could try searching the forums for other formulas with trading logic. There are many examples out there.
                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


                • #9
                  Question for Jason

                  Hi Jason,

                  I have written an AutoTrade Program and testing it first in PaperTrader.

                  In PaperTrader, If I code in a Stop, for an example,
                  PTtradeSell(getSymbol(), DefContracts, PaperTradeBroker.STOP, nStopPrice),
                  what is the needed EFS Script to "cancel" the order automactically ? I looked in the "EFS for PaperTrader" file, and i see no "Cancel" funtion.

                  My Program moves too fast to "physically" remove the orders manually from the Order Ticket window.

                  Any help would be greatly appreciated!

                  Angelo
                  ang.

                  Comment


                  • #10
                    Hello Angelo,

                    Try one of the Generic Broker Functions, cancelOrder() or cancelAllOrders().
                    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
                      Jason,

                      Thanks for the Solution. That was what i was looking for.

                      I take it by the nature of this function, (cancelOrder() ), that there is no way to cancel any particular individual orders??

                      If there is , can you show a way to do it? If I want to keep a constant fail safe stop in, say 10 pts away, do i have to reinsert that stop everytime I cancel orders by the use of cancelOrder()?


                      Thanks again for your help !!

                      Angelo
                      ang.

                      Comment


                      • #12
                        Re: My solution..

                        Almost 2 weeks ago I asked how to go about changing my efs program to go from backing testing to paper trading. Part of the advice I got was to set variables after the code that executes trades to track my long and short positions. See below.

                        Originally posted by Doji3333
                        I create logical control variables for those... Like this...

                        var StrategyisInTrade = false;
                        var StrategyisLong = false;
                        var StrategyisShort = false;

                        Then, when I trigger orders, I set these variables (as needed) to true/false...

                        That way I can use them in my code - like this...

                        if (StrategyisInTrade) {
                        if (StrategyisLong) {

                        }
                        if (StrategyisShort) {

                        }
                        }

                        if ((BuyTrigger) && (!StrategyisLong)) {
                        // Do Long Entry
                        }
                        if ((SellTrigger) && (!StrategyisShort)) {
                        // Do Short Entry
                        }
                        My question is whether there are any efs functions I can use to get specific information about open orders (ie - is pending order buy, sell, cover short, order size, etc) and current positions (ie - am I long, short, position size, average price) instead of using flags. I did some searching in the knowledge base to no avail. This is necessary because I can not totally rely on settings flags since I can not be absolutlely sure that when I place an order my order is filled and that is was for the full order amount.

                        There is also the problem of holding positions over night. When I turn the efs program back on the next day I need it to determine my current position so it manages that position instead of executing code to buy or sell that stock.

                        Thanks,
                        Pete

                        Comment


                        • #13
                          Hello Pete,

                          The use of such flags is a common programming practice. There really isn't a way to avoid using them altogether. Especially when designing complex logic that revolves around auto-trading systems.

                          Currently not all of the functionality that you're looking for is available through stand alone functions. This area of true two-way communication between EFS and the broker accounts will receive more attention in future releases, possibly as early as 8.0. There has been some groundwork done in this area that exposes some of the broker information to EFS, but it's not supported by all brokers. Furthermore, it requires an advanced level of programming knowledge to work with this feature as you will need to create those custom functions to retrieve the necessary information you need from the exposed broker arrays. Feel free to take a look at the brokerage integration SDK in the Active X Development file share group.
                          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


                          • #14
                            Auto-trading...

                            I've developed LOTS of fully automated trading solutions using the following...

                            eSignal's integrated brokers
                            Dynaorder
                            TradeMaven
                            NinjaTrader
                            others (using MENT TS)...

                            The fact is, everyone supports the common features differently..

                            Dynaorder is a great solution for using IB (interactive brokers). It has many of the features you are needing currently. It also does a good job with FXCM, but there are some tricks to placing LIMIT orders with FXCM.

                            NinjaTrader and TradeMaven require access (read/write) to files in order to get the information you want.. It can be tricky, but can be done.

                            The only other solution is to "work around" the limitations right now. A simple solution would be to "write the current information to a file" so you can reload it when needed.. I've done this in the past too...

                            Bottom line is every solution has some issues you have to deal with. The best (and in some cases ONLY) solution is to "write around these issues" to get the best results..

                            B
                            Brad Matheny
                            eSignal Solution Provider since 2000

                            Comment


                            • #15
                              Auto Trade

                              I have been trying to set up a basic auto trading system and have been frustrated. I have read all the posts and still have problems. Finally, I tried to boil it down to the very basics so I started with a simple EFS Wizard program and attemted to identify the problem and what would work using all the things I have read about here and still no luck. The problem is I can get it to trade but I can't get it to know not to go long when I'm already long and not to short when I'm already short. when the conditions are right to go short it will sell over and over until the condition changes then it will buy over and over. When I put in a flag to tell what the last trade was and whether I am already in trade then it would trade at all. Is there a simple fix for this?

                              if ( getGlobalValue("flag",true && //with it won't go, without won't stop**
                              close > MAStudy )
                              trade.Buy(getSymbol(),100,PaperTradeBroker.MARKET) ;

                              Comment

                              Working...
                              X