Pine Script Tutorial
-
-
library - like modules in JS.
-
Otherwise using either indicator() or strategy()
-
Example of powerful built-in functions:
-
indicator Pine Script - designed for creating indicators & alerts. Oscillator or MA, etc.
- Has access to alert functionality.
- Shares all the same inbuilt functions & variables as strategy scripts.
- But can not execute buy / sell like strategy.
-
strategy Pine Script - A specialized Pine Script type for backtesting strategies.
- Does NOT have access to some indicator functions.
- Limited alert functionality compared to indicators.
- Better to use indicators for alerts/
- Has access to strategy.* functions for placing and managing mock trades.
- type
strategy.+ CTRL + SPACE (see full list of commands)
- type
-
library - re-usable code of libraries, like modules in JS.
- (~16:30).
-
-
- User HPotter mentioned in tutorial.
- Search People or Scripts to find useful indicators/strategies.
-
- set shape with
plotshape(_bool_, _title_, style=shape.*)
- set shape with
- From VWAP & VWMA
// Prepare filters
// Is the current bar the lowest of the last 4 || was the last bar the lowest bar of the last four?
swingLow = low == ta.lowest(low, 4) or low[1] == ta.lowest(low, 4)
// Is the current bar the highest of the last 4 || was the last bar the highest bar of the last four?
swingHigh = high == ta.highest(high, 4) or high[1] == ta.highest(high, 4)-
- (1) ATR, (2) RSI and (3) EMA
- mentioned in Ichimoku Cloud
- Using the zen library, we can tap into candle types like
hammerorstar - Example from Ichimoku Cloud
// Import zen library
import ZenAndTheArtOfTrading/ZenLibrary/2 as zen
// Get candle patterns from zen library:
hammer = zen.isHammer()
star = zen.isStar()
// Then combine with trade setups
longSignal = aboveIchy and hammer
shortSignal = belowIchy and star- Clear up clutter with user input and ternary operator on indicators to turn off
// user input:
displayFullCloud = input.bool(title="Show Full Cloud?", defval=true)
// ================== Clear up clutter with ternary operator on displayFullCloud == false =========================== //
plot(displayFullCloud ? conversionLine : na, color=#2962FF, title="Conversion Line")
plot(displayFullCloud ? baseLine : na, color=#B71C1C, title="Base Line")
plot(displayFullCloud ? close : na, offset=-displacement + 1, color=#43A047, title="Lagging Span")
// ================== Clear up clutter with ternary operator on displayFullCloud == false =========================== //-
- get the current timeframe (15m, 4h, 1D, etc) of the user's choice with
timeframe.period - use the
time(_timeframe, _period-to-check)function to see if a the current bar is within the defined time range. Here it's used in our custom functionisInSession()isInSession(_session) => not na( time(timeframe.period, _session) )
- get the current timeframe (15m, 4h, 1D, etc) of the user's choice with
-
-
array_shift() type method in pine. We get (potentially) a collection of bars and we want the FIRST bar in our "array" as follows:
- ``
-
array_shift() type method in pine. We get (potentially) a collection of bars and we want the FIRST bar in our "array" as follows:
- ``
-
How to Start and Stop a period to get the high and low in the desired period (8:05)
- X
-
// ==================================================================================================//- convert int to float.
- format open, high, low and close and inter into price param
- x
// ==================================================================================================//When you have local changes you don't care about that are preventing you from git pulling down the most recent copy, you can force to ignore local changes and pull down the newest remote version.
To remove local uncommitted changes (even if staged) run these commands: From this Stackoverflow Article
git reset --hard HEADgit pull
