Easy language questions

Discussion in 'Strategy Development' started by DT-waw, Dec 6, 2001.

  1. I'm trying to learn EL - maybe someday I will have TS to test my ideas, but first I want to know is it possible to write them in EL.

    My questions are:

    1. Can I use "Q_Ask", "Q_Bid", "Q_Last" etc. for strategy backtesting using historical data?

    2. Can I use those "Qs" as a Stop order price? For example
    BUY NEXT BAR (Q_Ask) Stop

    I don't want to use specific, pre-defined symbol prices for stop orders. I want to use current ask, bid or last trade symbol prices for stop orders.

    3. I want to execute my order immediately when my Condition1 is true. ( Let's say I have tick data )
    IF (Condition1) THEN BUY next bar at MARKET
    But market orders ( next bar at market ) are executed only at the opening price of next bar... What if my condition is true inside the bar? For example:
    - bar opens at 1000.00
    - my condition becomes true at 1000.50
    - opening of the next bar is at 1003.00
    - my market order is executed at 1003.00 ... 2.5 pts slippage!

    How to solve this problem? The only solution is to use stop orders instead of market orders with stop price at the current price?

  2. m_c_a98


    You cannot use Q_Bid and Q_Ask to look at historical bid and ask records. you need to write or buy a DLL that lets you do what your talking about.
    Market orders are only next bar. Realize that you can have multiple data compressions, for example your condition can become true on a 5min chart and you then buy on a 1min, etc. Also, on stop and limit orders, they are executed when they are hit.
  3. thanks mca.

    I have another three questions.

    1) IF Condition1 THEN buy next bar at stop

    Hey, if my condition becomes true on bar #1, then buy stop order can be executed on the bar #2 (next bar) not on the #1 bar???

    2) Is it possible to "round down" numbers to specified "box-values"? For example I want to round numbers to full 20's. Examples:
    83 = 80 ; 87 = 80 ; 91 = 80 ; 101 = 100 ; 19 = 0 ; 21 = 20

    3) Is there some function returning the current price analyzed by backtesting engine on historical data?

    "Market orders are only next bar". Stop and limit orders also. I don't understand this. If my condition becomes true on some tick, I want to execute order as fast as possible, not on the next bar!!! TS can't execute orders at tick prices inside currently analyzed bar?

    Please help me, I thought TS is a great software for system testing with tick-by-tick condition testing and order executing.

  4. m_c_a98


    Let me put it this way, any idea that I can think of testing, can be tested(so far in my experience). However, just because its called easylanguage doesn't mean everything is "easy". Its a lot more powerful than first impressions.

    lets say you apply your strategy to a 5min chart and your looking at the previous days high.
    a)if you tell it to buy if the close is greater than the prev high, of course it will what until next 5min bar.
    b)but you can also have a statement to buy stop or limit at previous high+/ X, etc. and the buy will take place within this first bar in realtime by the tick.
    you can analyze tick data and I know there are a few rounding functions.
  5. WarEagle

    WarEagle Moderator


    You have to understand why TS requires entry on the next bar if a condition is required for entry that occurs on this bar. When backtesting, TS sees the open, high, low, and close of a bar. You can only know what time the open and close occurred, but you don't know when the high or low occurred or what happened during the bar. So, if you require that stochastics cross over 20 for a buy, TS doesn't know when, during the bar, that this happened and thus cannot determine a realistic entry. If it allowed this, you could say "If condition1 then buy at low", but in real-time you don't know when the low will occur and if it occured before or after condition1. Your results would look spectacular, but could never be reproduced in real-time. So, they do this "for your protection".

    Now, there is a feature in TS 6 called "Backtesting Resolution" under the "Format" section of a strategy. You can select as low as 1 minute intervals. Since my systems all enter on the next bar anyway, I have not used this so I don't know if its any good. Supposedly, TS can look "inside" a bar (although not on a tick basis) to give test results closer to reality. You might play around with this to see if it does what you need.

    As for stops, one quirky thing about TS is that even though in the syntax I have to say "buy next bar LongStop stop;" where "LongStop" is my stop level, it will still execute on this bar if my stop price is hit.

    I am by no means an EL expert, and still have much to learn myself, so I defer if anyone else here has a better explaination. But TS has worked well for me. One thing you should be cautious of is trying to design a system that must be super accurate in catching a buy or sell on a tick basis in order to be profitable. I like having a system that waits until the next bar to enter, just because if it is profitable, then I have some room for error when trading it real-time. A friend of mine taught me a technique for testing a system for robustness by delaying the entry by an extra bar. If it still does well, you may have a winner on your hands.

    Hope this helps a little...I know how frustating TS can be sometimes.

  6. cashonly

    cashonly Bright Trading, LLC

    You should get on the omega-list. All the experts are there.

    All subscription or unsubscription requests should be mailed either to:


    or to:


    depending on whether you want to subscribe or unsubscribe to/from the real-time list or the digest version of the list. The content of both lists is the same, but the digest is sent roughly once a day.

    In your mail's Subject: line, say either subscribe or unsubscribe.

    You will be asked to confirm your intention to subscribe, to prevent your being maliciously subscribed to unwanted lists.
  7. Thank you for your answers.

    WarEagle - I hope it works like you wrote! Why EL requires syntax "next bar" if it executes stop orders on this bar?

    I want to test systems on TS2000i, maybe it differs from TS6?
    I know about the function "Backtesting resolution". In EL Guide I read:

    "When you set this option to test to the tick level ( assuming that data is available ), The Trading Strategy Testing Engine behaves the same way for backtesting as it would for real-time trading."

    It wasn't clear for me. I saw another page

    Now it's finally clear, that TS2000i strategy testing is realistic. But still, market orders can be executed only on [this bar close] or [next bar open] ??? Only stop and limit orders can be executed inside the 1-minute bar with tick level resolution?

    It will be much easier to use just market orders for my strategy instead of stops with stop prices that are put as complicated formulas which identify [current price]. As m_c_a98 said, I can't use Q_Last. And there's no syntax for returning the current tick price analyzed by testing engine.

    WarEagle I agree of course, when you add some little slippage to your system and it returns much poorer results, then the system is worthless. But since there can be 12-point high 1-minute bars on NQ100 futures, it's better to use 1-point slippage than executing on close of the bar... Slippage is something that depends on order size.

  8. WarEagle

    WarEagle Moderator


    There are some differences between 2ki and TS6. I don't think in TS6 that I can backtest at the tick level, it seems that 1 min bars are as low as I can go under the backtesting resolution. So you will have an advantage there and may be able to do what you want. I am still relatively new to EL, and I wish I knew the answers to your questions, but I don't. If I learn anything new in the future that relates to our discussion I will be sure to let you know.

    Good luck with your testing,

  9. DaveN


    I wanted to add two ideas to this thread:

    The first is about exit orders being good for only one bar. Essentially that is true since all orders, except for entry on the close of the current bar, are executed on the next bar.

    One way to take advantage of some of the built in functions of Tradestation is to keep calling for it on each bar. If it's undefined but the syntax is correct, nothing will take place.

    Here's an example. At the end of your code, just add the line

    ExitLong at Low[2] Stop; {This is syntax for TS2000i, not TS6}

    If you are not in a long trade, then the line will execute without consequence on each subsequent bar of the chart. However, if you are in a long trade, it will act as a trailing stop based on the low two bars ago.

    You could also bracket your Exits within a statement like
    If MarketPosition >= 1 then begin

    The second point is with regards to using signals from other charts. This would allow you to take a signal from a tick based chart to trigger a trade intrabar on a time based chart. Now, I haven't used this solution yet because I haven't needed it, but anyone considering this should experiment with it to make sure it does what he/she is expecting both in backtesting and realtime trading.

    There's a free .dll available at www.traders2traders.com called PushPop. It allows you to "push" data from one chart or multiple indicators, and "pop" that into another chart--likely on a different timeframe. It acts as a global variable. So, let's say you have a 5 minute chart and you want to get the signal from a crossover in a 20 tick based chart. This would let you get around not being able to mix tick based charts with minute based charts.

    If you use this, definitely verify that Tradestation is backtesting this and running in realtime the way you expect. In backtesting, each bar will be evaluated when it closes, but in realtime each new tick causes the bar or indicator to be reevaluated if you have selected "update on every tick"under you chart setup. This could give you differing results.