Library · Pine Script v5 · Library

MPB2_0

by sourdiesel1202

A Pine library that exports condition checks for long and short setups, selected by a position type string.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code99
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago16 Jul 2023

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 library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

99 lines of Pine Script v5 from mpb2_0.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=5

// @description TODO: add library description here
library("MPB2_0")
short_position_type = "SHORT"
long_position_type = "LONG"
// sma_length = input(10, "SMA Length")
// @function TODO: add function description here
// @param x TODO: add parameter x description here
// @returns TODO: add what function returns

// def validate_sma(position_type, ticker, ticker_history, indicator_data, module_config):
//     if module_config['logging']:
//         print(f"{datetime.datetime.now()}:{ticker}: {timestamp_to_datetime(ticker_history[-1].timestamp).strftime('%Y-%m-%d %H:%M:%S')}: Close: {ticker_history[-1].close} SMA: {indicator_data[ticker_history[-1].timestamp]}")
//     if position_type == PositionType.LONG:
//         return (ticker_history[-1].close > indicator_data[ticker_history[-1].timestamp] and ticker_history[-1].low > indicator_data[ticker_history[-1].timestamp] and ticker_history[-1].close > ticker_history[-1].open)

//     else:
//         return (ticker_history[-1].close < indicator_data[ticker_history[-1].timestamp] and ticker_history[-1].high < indicator_data[ticker_history[-1].timestamp] and ticker_history[-1].close < ticker_history[-1].open)

export validate_sma(string position_type) =>
    _value=false

    sma = ta.sma(close,10)

    if position_type == long_position_type
        _value := close > sma and low > sma and close > open

    else
        _value := close < sma and high < sma and close < open

    [_value]
    //TODO : add function body and return value here
    // x


// def validate_macd(position_type, ticker, ticker_history, indicator_data, module_config):
//     if module_config['logging']:
//         print(f"{datetime.datetime.now()}:{ticker}: {timestamp_to_datetime(ticker_history[-1].timestamp).strftime('%Y-%m-%d %H:%M:%S')}: Close: {ticker_history[-1].close} MACD: {indicator_data['macd'][ticker_history[-1].timestamp]} Signal: {indicator_data['signal'][ticker_history[-1].timestamp]}")
//     if position_type == PositionType.LONG:
//         return indicator_data['macd'][ticker_history[-1].timestamp] > indicator_data['signal'][ticker_history[-1].timestamp]
//     else:
//         return indicator_data['macd'][ticker_history[-1].timestamp] < indicator_data['signal'][ticker_history[-1].timestamp]


export validate_macd(string position_type) =>
    slowlength = 26
    fastLength = 12
    MACDLength = 9
    fast_ma = ta.ema(close, fastLength)
    slow_ma = ta.ema(close, slowlength)
    macd = fast_ma - slow_ma
    signal = ta.ema(macd, MACDLength)
    _value = false
    if position_type == long_position_type
        _value := macd > signal
    else
        _value := signal > macd
    [_value]


// def validate_adx(position_type, ticker, ticker_history, indicator_data, module_config):
// if module_config['logging']:
//     print(f"{datetime.datetime.now()}:{ticker}: {timestamp_to_datetime(ticker_history[-1].timestamp).strftime('%Y-%m-%d %H:%M:%S')}: Close: {ticker_history[-1].close} ADX[current]: {indicator_data['adx'][ticker_history[-1].timestamp]} ADX[previous]-: {indicator_data['adx'][ticker_history[-2].timestamp]} ")
// return indicator_data['adx'][ticker_history[-1].timestamp] > module_config['adx_threshold'] and indicator_data['adx'][ticker_history[-1].timestamp] > indicator_data['adx'][ticker_history[-2].timestamp]
export validate_rsi(string position_type) =>
    // [dmilpus, dmineg, adx] = ta.dmi(14, 3)
    rsi = ta.rsi(close, 14)
    _value = false
    if position_type == long_position_type
        _value := rsi < 65
    else
        _value := rsi > 45
    [_value]
    // [ta.rsi(14) ] //we know trend is strong]
export validate_adx() =>
    [dmilpus, dmineg, adx] = ta.dmi(14, 3)

    [adx > adx[2] and adx > 25] //we know trend is strong]

// if module_config['logging']:
//     print(f"{datetime.datetime.now()}:{ticker}: {timestamp_to_datetime(ticker_history[-1].timestamp).strftime('%Y-%m-%d %H:%M:%S')}: Close: {ticker_history[-1].close} DMI+: {indicator_data['dmi+'][ticker_history[-1].timestamp]} DMI-: {indicator_data['dmi-'][ticker_history[-1].timestamp]} ADX: {indicator_data['adx'][ticker_history[-1].timestamp]}")
// if position_type == PositionType.LONG:
//     return indicator_data['dmi+'][ticker_history[-1].timestamp] > indicator_data['dmi-'][ticker_history[-1].timestamp] and indicator_data['dmi+'][ticker_history[-1].timestamp] > module_config['adx_threshold'] and indicator_data['adx'][ticker_history[-1].timestamp] > module_config['adx_threshold'] and indicator_data['adx'][ticker_history[-1].timestamp] > indicator_data['adx'][ticker_history[-2].timestamp]
// else:
//     return indicator_data['dmi+'][ticker_history[-1].timestamp] < indicator_data['dmi-'][ticker_history[-1].timestamp] and indicator_data['dmi-'][ticker_history[-1].timestamp] > module_config['adx_threshold'] and indicator_data['adx'][ticker_history[-1].timestamp] > module_config['adx_threshold'] and indicator_data['adx'][ticker_history[-1].timestamp] > indicator_data['adx'][ticker_history[-2].timestamp]

export validate_dmi(string position_type) =>
    _value = false
    [dmilpus, dmineg, adx] = ta.dmi(14, 3)
    if position_type == long_position_type

        _value :=  dmilpus > dmineg and dmilpus > 20 and dmilpus > adx
    else
        _value :=  dmilpus < dmineg and dmineg > 20 and dmineg > adx
    [_value]

Overview

The simple moving average check uses a 10-bar average and requires the close, and for longs the low, to sit on one side of it with a matching candle colour. The MACD check compares the 12 and 26 period MACD line with its 9 period signal line. RSI and further checks follow in the full file, but the supplied source is cut off. It draws nothing itself and is imported by other scripts.

Details

Published by

sourdiesel1202 on GitHub

Type

Library, Pine Script v5

Draws

Library (no plots)

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.

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

261 stars

AIActivationFunctionsBipolarSigmoid is a Pine Script library that provides mathematical implementations of the bipolar sigmoid activation function and its derivatives for machine learning algorithms. It calculates bipolar sigmoid values bounded between -1 and

Library v5 AI / machine learning
Updated 4 years ago · None stated GitHub repository of AIActivationFunctionsBipolarSigmoid

KernelFunctions

by artificial-intelligence-edge
75 stars

KernelFunctions is a Pine Script v5 library that exports kernel weight functions for Nadaraya-Watson style estimation. It calculates a Rational Quadratic kernel, a Gaussian kernel based on a radial basis function, and a periodic kernel that models repeating be

Library v5
Updated 3 days ago · MIT GitHub repository of KernelFunctions

Ta

by nersent
29 stars

This Pine Script v5 library exports thin wrappers around built-in technical analysis functions. It covers moving averages, momentum measures such as RSI and CCI, volatility tools including ATR and standard deviation, range extremes, cross detection, and runnin

Library v5
Updated 11 months ago · Custom licence GitHub repository of Ta

Bands

by heyphat
26 stars

This library exports a Band type and functions that build a simple-moving-average basis with upper and lower envelopes from standard deviation. It classifies a source as above, below, or inside those envelopes, measures band width, and scales an imported z-sco

Library v6 Volatility & bandsMoving averages
Updated 2 months ago · AGPL-3.0 GitHub repository of Bands

Mylib

by ferranbt
21 stars

This script serves as a minimal utility library written in Pine Script v6. It provides an exported helper function that calculates the sum of two numeric arguments. As a reusable code library, it produces no visual plots, charts, or trading signals, and it con

Library v6
Updated 7 weeks ago · MPL-2.0 GitHub repository of Mylib

HLevel

by stupenkov
14 stars

HLevel is a Pine Script v5 utility library designed to manage horizontal price levels for cryptocurrency charts. It defines custom types for pivots and levels, along with methods to initialize, add, track, and expire price levels based on pivot high and pivot

Library v5
Updated 3 years ago · None stated GitHub repository of HLevel

More libraries

Trade Your Charts With a Regulated Broker

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

Compare brokers