Level 7 · Course 7.4
Coding strategies in Pine Script
0 of 16 lessons done
Join free to tick off each lesson as you go and get your certificate.
Module 1
Pine Script basics
- What Pine Script isA small language that runs on TradingView charts.
- The Pine Editor and your first scriptOpen the editor, add a script to a chart and read what it does.
- Variables, numbers and true or falseStoring values and asking yes or no questions in code.
- Reading price dataUsing open, high, low, close and the bar before this one.
- Plotting lines and shapesDrawing a moving average and marking bars on the chart.
Module 2
Indicators and conditions
Module 3
The strategy tester
- Strategy versus indicatorA strategy script places test trades that the tester can count.
- Entries, exits, stops and targets in codeTurning your written rules into entry and exit calls.
- Position size and futures contract valuesSetting size so the test uses real tick values and contract counts.
- Costs and slippage settingsAdding commission and slippage so the test isn't too kind.
- Reading the strategy tester reportWhere to find the list of trades, drawdown and the equity curve.
- Coding mistakes to look forRepainting, using the bar that hasn't closed yet, and peeking at the future.
- 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. A script averages the last 3 closes on every candle. What does it show on candles 1 and 2?
2. On a 5-minute chart, the script runs on the 10:15 candle. Which candle's close is close[1]?
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. 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. A script uses the window 0930-1030 on a 15-minute chart, in New York time. How many candles are inside it?
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. A long fills at 5,016.00 on MES, with loss = 12 and profit = 24 in strategy.exit. Where is the target?
8. A strategy risks $100 a trade with an 18-tick stop. A tick is $1.25. Using math.floor, how many contracts?
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. 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
Trading futures carries risk. You can lose money.