TradeStation 9.5 - Strange strategy execution

Discussion in 'Strategy Building' started by eddyb, Oct 11, 2020.

  1. eddyb


    Hi all,

    I'm new to TradeStation and I'm using the IB TSW 9.5 platform to test a strategy but it's behaving strangely in that it seems to be executing the strategy on every bar despite my code logic and disabling IntrabarOrderGeneration.

    I'm no doubt missing something fundamental, so asking for help on here.

    Here is my code (I've stripped out some logic to simplify things):

    { Simple Strategy }
    [IntrabarOrderGeneration = false]
    CashBalance = GetRTCashBalance(GetAccountId) ;
    Equity = GetRTAccountEquity(GetAccountId) ;
    NetWorth = GetRTAccountNetWorth(GetAccountId) ;
    LossLimit = (NetWorth / 100) * -1 ;
    CanTrade = True ;
    Print("CB: ", CurrentBar, " NetWorth: ", NetWorth, " Equity: ", Equity, " CashBalance: ", CashBalance) ;
    { SetStopLoss() SetProfitTarget() MarketPosition }
    if CurrentBar > 50 then begin
        Print("Close: ", Close, " Average close: ", Average(close,50)) ;
        If MarketPosition = 0 then
            If Close > Average(Close,50) and Close[1] < Average(Close,50) then
                Print("Buying") ;
                Buy next bar at market ;
        If MarketPosition = 1 then
            print("Trade PNL: ", GetPositionOpenPL(GetSymbolName, GetAccountId)) ;
            If Close < Average(Close,50) and Close[1] > Average(Close,50) then
                Print("Selling") ;
                Sell next bar at market ;
    And here is what I'm seeing when I add the strategy to the chart:

    Many thanks,
  2. I'm not EL savy but if you don't get a good answer here, Why don't you post Your Question at tradestation Sub Forum " easylanugage and software Support" or send them email to support .
  3. Handle123


    Isn't TS on version 10?
  4. eddyb


    Yes but I signed up through Tradestation global for the cheaper trading commissions and thats what it comes with unfortunately.
  5. Fonz


    I am not a coder, but when you say " If Close > Average(Close,50)... then Buy next bar at market " you will have a buy at every single bar after the Close is > at average... because the condition is still true at every bar until market reverse to "close < average..."
    You could say "if close crosses under average... "

    Like others, I agree that you should take the time to look at Tradestation easylanguage forum. This is a great way to learn.
  6. eddyb


    Thats a good plan, I will do that, thanks.
  7. eddyb


    That would be true if I didn’t have the market position conditional in there, which means only buy if no position. So it shouldn’t be entering in each bar unless something is happening within the bar.

  8. Maybe you have to indicate how many bars Ago,.... If Close > Average(Close,50)[2]

    and then use "Bars since Entry" so it will not trigger a new signals everytime that condition is True, as long as you are in a position and you wish not to add new Position again.
  9. yes ... nearly a year. But unfortunatly Many people use a crack version of Tradestation 9.5 , for TS 10 it is not available yet.

    That's main reason, most people don't help traders ask for EL code help, specially Tradestation Rep stop supporting Non-TS forums.
    Last edited: Oct 12, 2020
  10. SunTrader


    No the unfortunate part is if you were on TS Ver 10. Ver 9.5 is much less glitchy much more stable.

    Nonetheless your code has entries but no exit. So it enters and enters and ...
    #10     Oct 12, 2020