Skip to content
Wildflower
Join free

Level 7 · Course 7.4

Coding strategies in Pine Script

  • 16 lessons
  • 3 modules
  • Free
  • Course quiz at the end

0 of 16 lessons done

Join free to tick off each lesson as you go and get your certificate.

Or start lesson 1 now.

Module 1

Pine Script basics

  1. What Pine Script isA small language that runs on TradingView charts.
  2. The Pine Editor and your first scriptOpen the editor, add a script to a chart and read what it does.
  3. Variables, numbers and true or falseStoring values and asking yes or no questions in code.
  4. Reading price dataUsing open, high, low, close and the bar before this one.
  5. Plotting lines and shapesDrawing a moving average and marking bars on the chart.

Module 2

Indicators and conditions

  1. Built-in indicatorsCalling moving averages, RSI and average true range with one line.
  2. If statements and conditionsTurning a rule such as "close is above the average" into code.
  3. Crossovers and signalsDetecting when one line crosses another.
  4. Sessions and timeLimiting a script to certain hours and days.

Module 3

The strategy tester

  1. Strategy versus indicatorA strategy script places test trades that the tester can count.
  2. Entries, exits, stops and targets in codeTurning your written rules into entry and exit calls.
  3. Position size and futures contract valuesSetting size so the test uses real tick values and contract counts.
  4. Costs and slippage settingsAdding commission and slippage so the test isn't too kind.
  5. Reading the strategy tester reportWhere to find the list of trades, drawdown and the equity curve.
  6. Coding mistakes to look forRepainting, using the bar that hasn't closed yet, and peeking at the future.
  7. Coding one strategy from start to finishTake one written rule set from Level 3 and turn it into a working test.

Course quiz

10 questions on the whole course. Pick your answers, then check them. You pass with 80% or more.

  1. 1. A script averages the last 3 closes on every candle. What does it show on candles 1 and 2?

  2. 2. On a 5-minute chart, the script runs on the 10:15 candle. Which candle's close is close[1]?

  3. 3. The rule is close > ma, and ma is 5,018.25. A candle dips to 5,017.00 but closes at 5,019.00. If the if branch sets green, what color shows?

  4. 4. Fast was below slow on candle 1 and above it on candles 2 to 5. On how many candles is ta.crossover(fast, slow) true?

  5. 5. A script uses the window 0930-1030 on a 15-minute chart, in New York time. How many candles are inside it?

  6. 6. A strategy places an entry on a candle that closes at 5,030.25. The next candle opens at 5,030.75. With default settings, where does the test order fill?

  7. 7. A long fills at 5,016.00 on MES, with loss = 12 and profit = 24 in strategy.exit. Where is the target?

  8. 8. A strategy risks $100 a trade with an 18-tick stop. A tick is $1.25. Using math.floor, how many contracts?

  9. 9. A strategy has commission_value = 1 per contract each fill and slippage = 1. A market entry ends at a limit target on 1 MES contract. What does the trade cost?

  10. 10. In the Strategy Tester, winners made $1,200 and losers lost $800. What is the profit factor?

0 of 10 answered.

Every lesson is free and open. Sign up free to save your progress

Next course

Backtesting in Python (optional)

Level 7: Advanced · 15 lessons

When you’re ready

Test your own ideas with Trade

Write down your own strategy and backtest it on your own charts. The school stays free either way.

See what Trade includes

Trading futures carries risk. You can lose money.