How would you code this system? Let's compare platforms.

Discussion in 'Strategy Building' started by lindq, Aug 2, 2021.

  1. lindq


    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.
    shuraver and yc47ib like this.
  2. lindq


    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)
    Exit: BARSOPEN=0 (Exit same day if profit target is not reached)

    How would you code this system in your backtesting language?
    Last edited: Aug 2, 2021
  3. MarkBrown


    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?
  4. lindq


    I'm not looking for system results. Nor combining sessions. Write it down how ever you'd like.
  5. Old WealthLab. Clunky, but easy to read. :D

    var Bar, SPYClose: integer;
    SPYClose := GetExternalSeries('SPY',#Close);
    for Bar := 20 to BarCount - 1 do
    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
         if SellAtLimit(Bar, PriceOpen(Bar)*1.04, LastPosition, 'Exit At Limit') then
         SellAtClose(Bar, LastPosition, 'Exit At Close');
    Last edited: Aug 2, 2021
    shuraver, yc47ib and lindq like this.
  6. lindq


    Thanks for posting. I was one of the original Wealthlab users. My only (and last) experience in coding.
  7. 2rosy


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


    Okay, then post it. How would it look in python?
  9. tsznecki


    You are asking for free development work. It's pretty obvious.
  10. lindq


    How ridiculous. And sad.
    Last edited: Aug 2, 2021
    #10     Aug 2, 2021