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):
And here is what I'm seeing when I add the strategy to the chart:
https://prnt.sc/ux3u2x
Many thanks,
Eddy
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 }
[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