Trailing Stop Entry for TradeStation

Discussion in 'Automated Trading' started by Norm, Dec 21, 2005.

  1. Norm



    I have searched, but cannot find a trailing buy stop in Easy Language. That is, I want to follow a price down and then purchase when the price moves up slightly (the opposite of a trailing stop for selling a position).

    If anyone knows where I can find trailing buy stop code for Easy Language, please let me know. Or, if you have a hint on how to write such code, that would be great as well.

    Happy Holidays,
  2. What kind of trailing stop? moving average, ATR, percent, breakout,etc, etc. You need to define your "trailing stop" buy!

    Also, if you find some exit short code that says for example...if condition xxx then exitshort...

    You can usually modify it and write something like "if condition xxx then BUY next bar at....
  3. Norm


    Thanks for the reply risktaker. I am not sure which, if any, of the categories that you mentioned apply.

    As you know, a normal trailing stop simply sells a position when the price of a stock stops moving upward and dips enough to trigger the stop.

    What I want is just the reverse. I want to trigger a buy when the price of a stock stops falling and moves upward slightly. Many brokers offer this as an execution option. For example, I use both trailing buy stops and trailing sell stops with IB frequently. They frequently (but not always) increase the profitability of a trade.

    TradeStation offer two EasyLanguage reserve words for a trailing stop sell (SetDollarTrailing and SetPercentTrailing). It appears that both of these can only be used to sell a position and that there is no corresponding reserve word(s) for buying.

    So, I am looking for an EasyLanguage reserve word or a strategy for buying a stock after it stops moving down and moves up slightly.

    Thanks Again,
  4. Like I said, you need to define this "trailing stop" better.
    What's your meaning of "moves up slightly"?

    Moves up 10 cents?
    Moves up above some mov average?
    Moves up by some ATR multiple?
    Moves up by X percent?
    Move up to highest 4 bars?
    Moves up by some whatever condition?
    Should the trailing stop use only TODAY'S prices for this calculation or last few days?
    You tell me.

    Also, will this entry stop be used on DAILY bars or intraday bars?
    In many cases, intraday setups won't work properly on daily bars and vice-versa.

  5. Assume you had 2 contracts when "sellshort" and price move
    up, use keyword "buy" and double up the contracts (4 contracts) to buy just 2 cotracts.

    You also don't HAVE to be in any previuos position to do this
    Again, i'm not sure if i understood your question well, hope
    it helped


    inputs: ATRLength( 10 ), NumATRs( 3 ) ;
    variables: ATRCalc( 0 ), MP( 0 ), PosLow( 0 ) ;

    ATRCalc = AvgTrueRange( ATRLength ) * NumATRs ;
    MP = MarketPosition ;

    if MP = -1 then begin
    if MP[1] <> -1 or Low < PosLow then
    PosLow = Low ;
    Buy 4 contracts ( "AtrSX" ) next bar at PosLow + ATRCalc stop ;
    buy 4 contracts ( "AtrSX-eb" ) next bar at Low + ATRCalc stop ;
  6. Norm


    Hi risktaker,

    What I am considering is a trailing buy stop that requires the entry of two parameters (inputs). The first would be where the trailing stop is invoked. It could be a delta or offset from the current price (as of the time that the trailing buy stop instruction is executed) or it could be an offset from the close of the current bar. It doesn't really matter what the offset references.

    For example, if the first parameter is 1, then the trailing stop could go into effect when the price of the stock moves to 1 point lower than the closing price of the current bar.

    The second parameter would be the stop price. This is the price increase required to trigger a market order. For example, if the stop price was .25, then a market order would be generated when the price of the stock increased by .25 points.

    Thus, a typical scenario would be that the trailing stop buy instruction with parameters of 1 and .25 was executed in the current bar. Then the price fell more than 1 point so as to invoke the trailing stop (which is what I am hoping for). Then, the price bounced back (went up) by at least .25, so that a market order was placed. In this example, the stock would be purchase at around .75 points less than simply placing the market order in the first place.

    I do this frequently in manual trading. On average, it pays off. Occasionally, it pay off very well. It is merely the same as using a conventional trailing stop for exiting a position, but in reverse (for entering a position).

    I strongly suspect that there is either a reserve word or a strategy that handles this. It is a basic execution method that is built into many much less sophisticated platforms. For instance, with IB a stop can be used to either exit or enter a position. The software simply doesn't care. But with the TS reserve words that I found so far, they must be used only to exit a position - or so it appears.


  7. Tradestation has two words "buytocover" which only
    exits positions and "buy" which can exit and reverse
    the position, depanding on the number of contracts
  8. Norm,
    Again , the problem is you are still not clear on what your "buy stop" definition is!

    Imagine for a minute this scenario...

    XYZ...9:30am price = 34.50
    XYZ...9:40am price = 34.40
    XYZ...9:50am price = 34.30
    XYZ...10:00am price = 34.20
    XYZ...10:10am price = 34.10
    XYZ...10:20am price = 34.00
    XYZ...10:30am price = 33.90
    XYZ...10:40am price = 33.80
    XYZ...10:50am price = 33.70
    XYZ...11:00am price = 33.60
    XYZ...11:10am price = 33.50
    XYZ...11:20am price = 33.40------LOW PRICE HERE FOR TODAY
    XYZ...11:30am price = 33.50
    XYZ...11:30am price = 33.60
    XYZ...11:40am price = 33.70
    XYZ...11:50am price = 33.80
    XYZ...12:00am price = 33.90
    XYZ...12:10am price = 34.00

    As you can see, the low for this stock today so far is 33.40 at 11:20am.

    Now, in order to invoke your "buy traling stop" what is your condition? I imagine the stock has to go up a bit, right?

    My question to you is HOW MUCH UP? Or do you have some particular technique to define what the trailing stop should be?
    What does the price need to do? If you give a vague answer, I can't help you and neither can anybody else!

    I've got several of these types of buy trailing stops that I use. It is nothing new. They're also easily modified. But you need to be more precise in the logic in order to write it.

    For example here's an intraday percent-based trailing system which uses the logic you're after in percent terms to get in and out.

    This is for ts2000i
    I think ts8.0 may be *slightly* different. It buys on a x% up trailing stop and sells on a x% down trailing stop. But again, the logic is clear. Go ahead and apply it to some chart and see if it's remotely close to what you're looking for.

    PS, I just notice this editor does not let some of the characters be written like in easylanguage. I'll try to attach a word document then.
  9. ok, here's the percent up n down easylanguage code which may be of use for trailing stop entry/exits.
  10. Norm


    Hi risktaker,

    Thanks for your patience!

    The trailing buy would be initiated by a setup. It doesn't really matter what the setup is. When a predefined pattern is recognized, the the trailing stop buy will execute.

    That is, I am not looking to code the specific condition that invokes the trailing stop buy. Rather, I am looking for the specific code that follows the stock down after the trailing stop is invoked and then issues a market order after the stop is met with an upturn.

    How much up is not important. That would be an input to the system that could be optimized with backtesting.

    It is the code that actually follows the stock then then performs the buy that I am interested in.

    So, a setup occurs. Say, it is a shorter term average crossing under a longer term average. The assumption (or hope) here is that the price is declining and I can pick up a bargain. I appreciate that this has its own risks, but I have been successful at practicing such methods manually.

    Then the crossover could trigger the the trailing stop buy. I don't want to buy right away, because there is some likelihood that the stock will continue to decline. So, the trailing stop follows the stock downward until there is a pre-define upturn (such as .25 point entered into the strategy as an input ).

    Once the .25 point upturn occurs, then a market buy order is entered by the trailing stop buy.

    Thanks again. I appreciate the time that you have put into responding to my posts.

    #10     Dec 21, 2005