liam800
Pine Script Scholar
Pine Script Scholar
Posts: 1
Joined: December 22nd, 2021
Contact: TradingView Profile

Starting the PSMC

Hello everyone

I have just joined the PSMC and very happy. Thanks to Matt and his great lessons, I can tidy up my code.
This is where I am currently from the youTube channel, basic pinescript lessons and starting the PSMC.
Good luck everyone
Liam

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © liam800
// Last updated: 23rd December, 2021
// Created by Liam Cain
//@version=5
indicator("(2021v5) Moving Average Code - LC", "MA Code - LC", overlay=true)

// Get user inputs for ma type, length & ability to switch each ma on:off

maType = input.string(title="MA Type",
defval="SMA", options=["SMA", "EMA"],
tooltip="Select simple or exponential moving average",
group="Moving Average User Inputs")

maLength1 = input.int(title="MA Length 1", defval=10, minval=1)
maLength2 = input.int(title="MA Length 2", defval=20, minval=1)
maLength3 = input.int(title="MA Length 3", defval=50, minval=1)
maLength4 = input.int(title="MA Length 4", defval=150, minval=1)
maLength5 = input.int(title="MA Length 5", defval=200, minval=1)

showMA1 = input.bool(title="Show MA1", defval=true, inline="1")
showMA2 = input.bool(title="Show MA2", defval=true, inline="1")
showMA3 = input.bool(title="Show MA3", defval=true, inline="1")
showMA4 = input.bool(title="Show MA4", defval=true, inline="1")
showMA5 = input.bool(title="Show MA5", defval=true, inline="1")

// Get colors for ma's

colMA1 = color.new(color.white,40)
colMA2 = color.new(color.red,40)
colMA3 = color.new(color.purple,40)
colMA4 = color.new(color.green,40)
colMA5 = color.new(color.yellow,40)

// Get switch to choose moving average type

movingAverage1 = switch maType
"SMA" => ta.sma(close, maLength1)
"EMA" => ta.ema(close, maLength1)

movingAverage2 = switch maType
"SMA" => ta.sma(close, maLength2)
"EMA" => ta.ema(close, maLength2)

movingAverage3 = switch maType
"SMA" => ta.sma(close, maLength3)
"EMA" => ta.ema(close, maLength3)

movingAverage4 = switch maType
"SMA" => ta.sma(close, maLength4)
"EMA" => ta.ema(close, maLength4)

movingAverage5 = switch maType
"SMA" => ta.sma(close, maLength5)
"EMA" => ta.ema(close, maLength5)

// Draw moving averages

plot(showMA1 ? movingAverage1 : na, title="MA 1", color=colMA1, linewidth=1)
plot(showMA2 ? movingAverage2 : na, title="MA 2", color=colMA2, linewidth=1)
plot(showMA3 ? movingAverage3 : na, title="MA 3", color=colMA3, linewidth=1)
plot(showMA4 ? movingAverage4 : na, title="MA 4", color=colMA4, linewidth=1)
plot(showMA5 ? movingAverage5 : na, title="MA 5", color=colMA5, linewidth=1)
]

Return to “Share Your Scripts”