Skip to content

codingthoughts/Pine-Script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pine Script

A library of trading indicators, strategies and code snippets for Pine Script programming language.


Strategies

An simple long/short strategy template file.
An advance long/short strategy template file.

The template file layout an trend following trading system. [1] [2]

  • Trend Following - An indicator that identify trend's direction, most likely an moving average.
  • Trend Confirmation - Most trend following indicator are prone to whipsaw, so you what to confirm the movement with something like an momentum indicator.
  • Entry/Exit - Now that you have an trend directional bias you may want to find an optimal entry/exit strategy this is where overbought/oversold indicator come in handy.
  • Stop-Loss and Profit-Taking - We need to determine an method to take profit on a winning trade and an loss on an losing trade. [3]
  • Position Sizing - To control risk and maximize gains we must determine what size of a position we are willing to risk. [4]
References/Notes:

[1] https://www.babypips.com/learn/forex/design-your-trading-system
[2] https://www.investopedia.com/articles/forex/10/indicators-fx-traders-must-know.asp
[3] I provided an method using bollinger bands with an stop loss and three profit-taking price levels. Each time an tp level is hit you will reduce your position and move the stop-loss to the old price level.
[4] I use the formula: Position Size = Risk Amount / Distance to Stop Loss. https://medium.com/@cryptocreddy/comprehensive-guide-to-position-size-and-leverage-2e27764ce9e0

An example of an advance trend following strategy. [1]
  • Trend Following - Moving Average.
  • Trend Confirmation - Waddah Attar Explosion.
  • Entry/Exit - Fisher Transform.
References/Notes:

[1] If you wish to see re-entry results increase the Trades Count setting.

Requested strategy by discord user Mrhutqc#2962

A rewrite of Logical_Strat_Template_v0.2
@author MrhutQC, Ozine
@thanks DarkRico, FurryBoffin

Requested strategy by discord user IamLegion#6493. [1]
  • Trend Following - 2 Higher Timeframe Moving Average. [2]
  • Trend Confirmation - 2 Lower Timeframe Moving Average. [2]
  • Entry/Exit - Entry: 2 Moving Average, Connors RSI, Stochastic %K & %D and Bollinger BandWidth Exit: MACD and RSI
  • Stop-Loss and Profit-Taking - Fix Percentage, ATR Percentage
References/Notes:

[1] Strategy mainly use for backtesting setting for ProfitTrailer bot.
[2] Use for turning on the bot.

An trend strategy using Parabolic SAR.
  • Trend Following - A Moving Average.
  • Trend Confirmation - Parabolic SAR
  • Entry/Exit - None
  • Stop-Loss and Profit-Taking - ATR
  • Position Sizing - None
An trend strategy using Parabolic SAR and WaveTrend Oscillator.
  • Trend Following - Parabolic SAR.
  • Trend Confirmation - WaveTrend Oscillator.
  • Entry/Exit - IFish TCI Indicator
  • Stop-Loss and Profit-Taking - None
  • Position Sizing - None
An counter-trend strategy finding tops/bottoms.
  • Trend Following - Percentage Difference of Moving Average and Source, IFish TCI. [1]
  • Trend Confirmation - WaveTrend Oscillator
  • Entry/Exit - Sigma Accumulate
  • Stop-Loss and Profit-Taking - None
  • Position Sizing - None
References/Notes:

[1] IFish TCI has static moving average (zlema) due to error: Script has too many local scopes.


Indicators

Momentum Indicators

These technical indicators may identify the speed of price movement
Fisher Transform with an changeable EMA alpha https://www.mesasoftware.com/papers/UsingTheFisherTransform.pdf

@author LazyBear, xSilas, Ni6HTH4wK

TCI indicator presumed if the position of an close within a candlestick provides information on whether the uptrend is gaining or losing power.

A rewrite of Trend Confirmation Index http://www.fxcodebase.com/code/viewtopic.php?f=38&t=61051
@author Mario Jemic

@author LazyBear

Trend Indicators

These technical indicators measure the direction and strength
Moving average cross strategies with three type:

Price Cross - When price cross the slow ma Two Cross - When fast ma cross the slow ma Tri Cross - When fast ma cross mid, slow ma

Waddah Attar Explosion with custom moving averages and exit strategies

Volatility Indicators

These technical indicators measure the rate of price movement
An standalone indicator version of the stop-loss and profit-taking from Template Advance Strategy.

Show the different of fast/slow sigma (stdev) with money flow index. Blue bar - fast above slow Grey bar - fast under slow

Volume Indicators

These technical indicators measure the strength of a trend based on volume

Experimental Indicators

These technical indicators are experimental, usually combination of indicators.
An inverse fisher transformation of TCI indicator http://www.fxcodebase.com/code/viewtopic.php?f=38&t=61051

Snippets

An collection of moving averages used in the code base. [1]
References/Notes:

[1] TradingView will slow down when their is a long chain of if/else statement, so have to split MA function.

An collection of channel bands used in the code base.
  • bollinger - Bollinger Bands
  • keltner - Keltner Channels
  • atr - Average True Range
  • donchian - Bollinger Bands
  • chandelier - Chandelier Exit
An collection of momentum indicator used in the code base.
References/Notes:

[1] Use PercentRank instead of ROC describe in ConnorsRSI Guidebook.
[2] Return K not %K: %K = sma(K, pk_len) %D = sma(%K, pd_len)

Find if current ticker has quote currency.

Copying

You may copy and/or modified this project source code on the condition that you released under the same license and keep copyright notice when distributing this project source code. TradingView template default header are license under Mozilla Public License 2.0

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © YOUR NAME


Contributing

See CONTRIBUTING.md file.


Donation

If you like any of the project code consider donating.
BTC: 32LxoJWQvUJbZsJY2ZBqopoCCELigfzFy3
ETH: 0x9a0661d3FE5110a40685bdF9F329eF1f159F2482
XTZ: tz1PBFLc4PeQnkjneXKjS8o7rWNK5zNaLjGa
BNB: bnb1mtxsz94u4xvj5z5ste6t2n9y50fg0w4vy7u0v4


License

This project is licensed under the Mozilla Public License 2.0.


Disclaimer

No Investment Advice Provided

USE THE SOFTWARE AT YOUR OWN RISK. YOU ARE RESPONSIBLE FOR YOUR OWN MONEY. ALL TRADING INVOLVES HIGH RISK AND YOU CAN LOSE A SUBSTANTIAL AMOUNT OF MONEY, NO MATTER WHAT METHOD YOU USE. THE AUTHOR HAS NO RESPONSIBILITY FOR YOUR TRADING RESULTS. YOU SHOULD ALWAYS UNDERSTAND THAT PAST PERFORMANCE IS NOT NECESSARILY INDICATIVE OF FUTURE RESULTS.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published