I'm interested in seeing how various traders would code a simple trading system with their platforms and language. Whatever coding system or platform you use, take a few minutes and share how you'd write a simple system which I'll detail. I'm guessing that we'd all find some interest in seeing how various languages and platforms would put this together, so how about taking a few minutes to make your contribution? Here are the details, which I'm keeping simple. I'll then post how I'd go about it. System backtesting conditions: 1. Daily bars 2. Entry: Buy TQQQ at the open...if the open is 2% below the close 2 days prior...and if the close of the prior day was below a 5 period simple moving average... and if SPY was down the prior day...and if the day is not Friday. 3. Exit: If the trade has gained 4% on the same day...or exit at the end of the same day if profit target has not been reached.
My backtesting platform is InvestorRT, which provides its own relatively simple coding language. Entries, exits, and confirming rules, are written as separate trading rules, then placed into a menu and saved as a 'system.' Here's how I'd code these conditions, which I call signals. Submenus are used to set values for techical indicators, and for accessing another instrument or time period, in this case SPY. System is set for daily bars and instrument TQQQ. Entry: OP<CL.1*.98 AND CL.1<MA.1 AND MPD#SPYOP.1<MPD#SPYCL.1 AND DAY!=5 Exit: SET(V#1, ENTRY*1.04) AND HI>ENTRY*1.04 (Set variable #1 at 4% gain from entry, exit if high exceeds the variable) or Exit: BARSOPEN=0 (Exit same day if profit target is not reached) How would you code this system in your backtesting language?
but wait daily bars? what session or sessions combined? now days you have to be very specific what is a daily bar toy you. you will find HUGE differences in the backtesting. i guess you would mean regular day session hours. if so how do you justify ignoring the overnight?
Old WealthLab. Clunky, but easy to read. Code: var Bar, SPYClose: integer; SPYClose := GetExternalSeries('SPY',#Close); for Bar := 20 to BarCount - 1 do begin if PriceOpen(Bar) < PriceClose(Bar - 2)*0.98 then if PriceClose(Bar - 1) < SMA(Bar - 1, #Close, 5) then if @SPYClose[Bar - 1] < @SPYClose[Bar - 2] then if DayOfWeek(Bar) <> #Friday then BuyAtMarket(Bar, 'Entry'); if LastPositionActive then begin if SellAtLimit(Bar, PriceOpen(Bar)*1.04, LastPosition, 'Exit At Limit') then begin end else begin SellAtClose(Bar, LastPosition, 'Exit At Close'); end end; end;
Thanks for posting. I was one of the original Wealthlab users. My only (and last) experience in coding.
you're asking how to test a strategy not really how to code a system. I would just use python and pandas...a few lines for ad hoc results