spy 3 lines of code equity curve

SPY "3-Lines-of-Code" Swing Trading Strategy


An educational trading strategy designed as a sandbox for testing your trading ideas. 

This lays the foundation of good strategy design and can be further developed by the curious student.

Buy Now


This SPY "3-Lines-of-Code" swing trading strategy is for demonstration purposes only.

This is not an "out-of-the-box" trading solution. 

The code lays a solid foundation for understanding the functions that comprise a successful strategy.

However, with further development and testing, it can eaisly be made into a world-class strategy.

How It Works

The strategy operates on fundamental principles of trend following and mean reversion.

  • SPY must be in a confirmed uptrend or downtrend (trend following).
  • SPY must have made a new daily closing low in a variable number of days.
  • Positions are exited when SPY makes a new daily closing high in a variable number of days.
SPY 3-Lines-of-Code Example


  • A launching point for the curious student into the world of tested-analysis (not technical analysis)
  • Easy to understand code
  • Variables to tweak for trend and mean reversion parameters
  • Full transparency with no "black boxes"

What's Included

  • Quick start guide
  • EasyLanguage source code (.eld format)
  • TradeStation Workspace (.tsw format)
  • Full code (.txt format)
  • Life-time strategy updates
SPY 3 Lines of code swing trading strategy

Strategy Specifications

Trading Platform

TradeStation or MultiCharts

Programming Language


Ticker Symbol


Trade Types


Trade Execution

Manual only

Stop-Loss Orders


Average Trade Duration

11 days

Trades per Year


Percent Profitable


Profit Factor


Learning From My Code

I think you'll find the following functions of interest to start coding and testing your own strategies!

Implemented Sub-Functions In This Strategy:

  • Trend determination
  • Basic mean reversion demonstration
  • Average true range determination
  • Automatic position size calculation based on volatility

Happy Trading!

Buy Now


Do I need a brokerage account to execute the code?

Yes, you'll need an account with either TradeStation or MultiCharts.

Both platforms offer free tier accounts. Simply copy and paste the code into your account to begin.

Is there a quick start guide available?

Yes, I provide a quick start guide that details how to set up the strategy for either manual or automated trading, based on your preference.

Is it necessary to fund the account with real money?

No, real money is not required to utilize the strategy.

It operates in live or simulation mode (your choice), allowing you to analyze trades or use another broker to execute them.

Can I place trades in advance, before the market opens?

Yes, all strategies, except for day trading, generate trade signals at the close of the current trading day.

This feature allows you to set up trades the evening before the market opens, freeing you from having to be at your computer.

Do I need programming skills to use this strategy?

No programming skills are needed. The strategy is ready to use right out of the box.

If you have an interest in learning how to program or have previous coding experience, the open-source code may be of interest to you.

What if I prefer manual trading over auto-trading?

That's perfectly fine. All strategies can toggle between automated and manual trading modes, allowing you to switch anytime according to your preference.

Do trade alerts only occur at the close of a trading bar?

Yes, trade alerts are issued at the close of each trading bar, which triggers a buy or sell order for the next bar.

The length of a bar depends on your trading style: one day for swing trading and a specified number of minutes for day trading.

How are trade alerts provided during manual trading?

In manual trading mode, a notification window appears to inform you of potential trades, allowing you to accept or reject them with a simple click.