Indicator · Pine Script v4 · On the chart

[Pirate] Deconstructed FMAs + Crosses

by hiPirate· code credited to Pirate

This indicator calculates fast and slow moving averages based on predefined Fibonacci ratio pairs, such as 89/144 or 21/34, along with a combined Golden Ratio moving average.

View on GitHub

GitHub stars33on the repository
Pine versionv4older, still runs
Lines of code158
Settings10inputs
LicenceUnlicense
Last update5 years ago8 Jul 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

158 lines of Pine Script v4 from Indicators/[Pirate] Deconstructed FMAs + Crosses.pine, published under Unlicense. Keep the author's credit and licence lines when you reuse it.

[Pirate] Deconstructed FMAs + Crosses.pine
// © Pirate
//@version=4

study("[Pirate] Deconstructed FMAs + Crosses",shorttitle="DFMA + Crosses",overlay=true)

//---------------------------------------------------------------------------------------------------------//
//-- Global Variables
//---------------------------------------------------------------------------------------------------------//
INVISIBLE=color.new(#ffffff, 100)
GREEN=color.new(#3faac0, 0)
RED=color.new(#c0553f, 0)
GOLDEN=color.new(#fbc02d, 0)
IVORY=color.new(#eaeae0, 0)
LIMIT=500
MA_GROUP="Long/Short Moving Averages"
RATIO_GROUP="Golden Ratio = Long MA + Short MA"
BAR_GROUP="Colored Bars"
SOURCE=input(title="Source",type=input.source,defval=close)
WEIGHT=input(title="Weight",defval="Weighted",
     options=["Exponential","Simple","Running","Weighted","Volume-Weighted"])
RATIO_DEFAULT="89/144"
RATIO=input(
     title="Long/Short Ratio",
     group=MA_GROUP,
     defval=RATIO_DEFAULT, 
     options=["1/2", "2/3", "3/5", "5/8", "8/13", "13/21", "21/34", "34/55", "55/89", "89/144", "144/233"])

//---------------------------------------------------------------------------------------------------------//
//-- Menu Options
//---------------------------------------------------------------------------------------------------------//
// Toggle Attribues On/Off
Long_io=input(title="[Enable/Disable] Fast",group=MA_GROUP,type=input.bool,defval=true)
Short_io=input(title="[Enable/Disable] Slow",group=MA_GROUP,type=input.bool,defval=true)

Ratio_io=input(title="[Enable/Disable] Golden Ratio",group=RATIO_GROUP,type=input.bool,defval=true)
Gcross_io=input(title="[Enable/Disable] Golden Cross",group=RATIO_GROUP,type=input.bool,defval=true)
Dcross_io=input(title="[Enable/Disable] Death Cross",group=RATIO_GROUP,type=input.bool,defval=true)

// Set Cross Text Color
Gcross_text_color=input(title="Golden Cross Text Color:",group=RATIO_GROUP,type=input.color,defval=GOLDEN)
Dcross_text_color=input(title="Death Cross Text Color",group=RATIO_GROUP,type=input.color,defval=IVORY)

//---------------------------------------------------------------------------------------------------------//
//-- Functions
//---------------------------------------------------------------------------------------------------------//
// Set Short MA Period
var Short_period = 
     RATIO == "1/2" ? 1 :
     RATIO == "2/3" ? 2 :
     RATIO == "3/5" ? 3 :
     RATIO == "5/8" ? 5 :
     RATIO == "8/13" ? 8 :
     RATIO == "13/21" ? 13 :
     RATIO == "21/34" ? 21 :
     RATIO == "34/55" ? 34 :
     RATIO == "55/89" ? 55 :
     RATIO == "89/144" ? 89 :
     RATIO == "144/233" ? 144 :
     na
    
// Set Long MA Period
var Long_period = 
     RATIO == "1/2" ? 2 :
     RATIO == "2/3" ? 3 :
     RATIO == "3/5" ? 5 :
     RATIO == "5/8" ? 8 :
     RATIO == "8/13" ? 13 :
     RATIO == "13/21" ? 21 :
     RATIO == "21/34" ? 34 :
     RATIO == "34/55" ? 55 :
     RATIO == "55/89" ? 89 :
     RATIO == "89/144" ? 144 :
     RATIO == "144/233" ? 233 :
     na

// Set Ratio Period
var Ratio_period=((Long_period+Short_period))

// Set Fast MA Weight
Long_line=(
     WEIGHT == "Exponential" ? ema(SOURCE,Long_period) :
     WEIGHT == "Simple" ? sma(SOURCE,Long_period) :
     WEIGHT == "Running" ? rma(SOURCE,Long_period) :
     WEIGHT == "Weighted" ? wma(SOURCE,Long_period) :
     WEIGHT == "Volume-Weighted" ? vwma(SOURCE,Long_period) :
     na)

// Set Slow MA Weight
Short_line=(
     WEIGHT == "Exponential" ? ema(SOURCE,Short_period) :
     WEIGHT == "Simple" ? sma(SOURCE,Short_period) :
     WEIGHT == "Running" ? rma(SOURCE,Short_period) :
     WEIGHT == "Weighted" ? wma(SOURCE,Short_period) :
     WEIGHT == "Volume-Weighted" ? vwma(SOURCE,Short_period) :
     na)

// Set Ratio Weight
Ratio_line=(
     WEIGHT == "Exponential" ? ema(SOURCE,Ratio_period) :
     WEIGHT == "Simple" ? sma(SOURCE,Ratio_period) :
     WEIGHT == "Running" ? rma(SOURCE,Ratio_period) :
     WEIGHT == "Weighted" ? wma(SOURCE,Ratio_period) :
     WEIGHT == "Volume-Weighted" ? vwma(SOURCE,Ratio_period) :
     na)

// Cross Conditions
Gcross=crossunder(Long_line,Short_line)
Dcross=crossover(Long_line,Short_line)

// Plot Golden Cross Label
Gcross_label=(Gcross_io ? (Gcross ? label.new(
     x=bar_index,
     y=high,
     style=label.style_triangleup,
     color=GOLDEN,
     yloc=yloc.belowbar,
     textcolor=GOLDEN):na) :na)

// Plot Death Cross Label
Dcross_label=(Dcross_io ? (Dcross ? label.new(
     x=bar_index,
     y=high,
     style=label.style_triangledown,
     color=IVORY,
     yloc=yloc.abovebar,
     textcolor=IVORY):na) :na)

// Set Label Text | String
label.set_text(Gcross_label,tostring(close))
label.set_text(Dcross_label,tostring(close))

// Morph Label Text | String -> Float
Gcross_price=tonumber(label.get_text(Gcross_label))
Dcross_price=tonumber(label.get_text(Dcross_label))

// Plot Lines
Long=plot(Long_io ? Long_line : na,title="Long MA",color=RED,linewidth=2)
Short=plot(Short_io ? Short_line : na,title="Short MA",color=GREEN,linewidth=2)
Ratio=plot(Ratio_io ? Ratio_line : na,title="Ratio",color=GOLDEN,linewidth=2)

//---------------------------------------------------------------------------------------------------------//
//-- Testing / Notes
//---------------------------------------------------------------------------------------------------------//
// Set & Plot Cross Price Lines
// Connects each point from DC -> DC or GC -> GC
// Want it to connect last known GC to DC.
//Gcross_price_line=plot(valuewhen(crossunder(Long_line, Short_line), close, 1), color=GOLDEN)
//Dcross_price_line=plot(valuewhen(crossover(Long_line, Short_line), close, 1), color=IVORY)

// Set Bar Colors
//Bars_io=input(title="[Enable/Disable] Colored Bars", group=BAR_GROUP,type=input.bool,defval=true)
//Gcross_bar_color=input(title="Golden Cross Bar Color",group=BAR_GROUP,type=input.color,defval=GOLDEN)
//Dcross_bar_color=input(title="Death Cross Bar Color",group=BAR_GROUP,type=input.color,defval=IVORY)
// Change Bar Color
// If bar ohlc4 is above Ratio_line then change bar color to Golden Cross
// If bar ohlc4 is below Ratio_line then change bar color to Death Cross
//barcolor(Ratio_line < ohlc4 ? Gcross_bar_color : na)
//barcolor(Ratio_line > ohlc4 ? Dcross_bar_color : na)

Overview

Users can choose from multiple weighting types, including Simple, Exponential, Running, Weighted, and Volume-Weighted moving averages. The indicator plots these average lines directly on the price chart and identifies trend crossovers via customizable Golden Cross and Death Cross markers.

Details

Published by

hiPirate on GitHub

Code credit

Pirate, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

cryptocurrencytradingtradingviewtradingview-pine-scriptspine-scripttradingview-charting-librarytradingview-datatrading-strategiestrading-systemscrypto

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
SourcesourcecloseSOURCE
WeightstringWeightedWEIGHT
Long/Short RatioinputRATIO_DEFAULTRATIO
[Enable/Disable] FastbooltrueLong_io
[Enable/Disable] SlowbooltrueShort_io
[Enable/Disable] Golden RatiobooltrueRatio_io
[Enable/Disable] Golden CrossbooltrueGcross_io
[Enable/Disable] Death CrossbooltrueDcross_io
Golden Cross Text Color:colorGOLDENGcross_text_color
Death Cross Text ColorcolorIVORYDcross_text_color
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon
257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

60K均線

by TaichiS
219 stars

This multi-timeframe indicator calculates and plots 20-period and 60-period simple moving averages from the 60-minute timeframe directly onto the price chart. The 20-period average displays as a green line, while the 60-period average appears in blue. It serve

Indicator v4 Moving averagesTrend Repaints
Updated 5 years ago · None stated GitHub repository of 60K均線

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers