TradeStation 9.5 - Strange strategy execution

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 ...

Hmm, but this is my exit code:


Code:
        If Close < Average(Close,50) and Close[1] > Average(Close,50) then
            Print("Selling") ;
            Sell next bar at market ;

So essentially I'm saying if we have an open position and then Close falls below the Average then we sell next bar at market which unless I'm mistaken (and I might be) that should sell an equal amount to what it bought and exit the trade?

Thanks
 
Hmm, but this is my exit code:


Code:
        If Close < Average(Close,50) and Close[1] > Average(Close,50) then
            Print("Selling") ;
            Sell next bar at market ;

So essentially I'm saying if we have an open position and then Close falls below the Average then we sell next bar at market which unless I'm mistaken (and I might be) that should sell an equal amount to what it bought and exit the trade?

Thanks
Try instead:-

Code:
If MarketPosition = 1 and 
Close < Average(Close,50) and Close[1] > Average(Close,50) then
            Print("Selling") ;
            Sell next bar at market ;
 
Same issue I'm afraid. I'm wondering if there is something wrong with the platform as I have to remove and add the strategy each time I want to test it as well, otherwise it won't appear on the chart. This kind of logic also works fine in other backtesting tools. I've submitted a ticket with TradeStation Global anyway.

Thanks for the help.
 
Your code is the issue, the conditional only worked on the print statement. Try it like this:
Code:
If Close < Average(Close,50) and Close[1] > Average(Close,50) then begin
    Print("Selling") ;
    Sell next bar at market ;
end;
 
Your code is the issue, the conditional only worked on the print statement. Try it like this:
Code:
If Close < Average(Close,50) and Close[1] > Average(Close,50) then begin
    Print("Selling") ;
    Sell next bar at market ;
end;

Aha thats fixed it! Thankyou! I’m new to EasyLanguage and should have checked the if syntax.
 
ok some of your problem is marketposition < it only occurs after the fact. if you want market position to work make it a variable

var:mp(0):

then define what mp is for example;

if average(c, 10) > average(c, 10)[1]then mp = 1;
 
1. Use Tradestation 9.5, NOT TS 10.0.
2. Learn at least the rudiments of Easy Language. There are many Youtube videos.
3. Create a strategy that has a chance of working. (Yours doesn't)

Best wishes...
 
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):

Code:
{ Simple Strategy }[/COLOR][/SIZE][/LEFT]
[SIZE=16px][COLOR=rgb(12, 18, 29)]
[LEFT]
[IntrabarOrderGeneration = false]

Inputs:
ProfitExit(20);

Vars:
TradeActive(False),
TradeSize(1),
CanTrade(False),
NetWorth(0.0),
Equity(0.0),
CashBalance(0.0),
LossLimit(0.0);

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:

https://prnt.sc/ux3u2x

Many thanks,
Eddy
 
Back
Top