Strategy · Pine Script v4 · On the chart

Binomial Moving Average

by hasnocool· code credited to HosseinDaftary

This strategy calculates custom moving averages weighted by binomial coefficients.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code36
Settings2inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

36 lines of Pine Script v4 from Binomial Moving Average Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Binomial Moving Average Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HosseinDaftary
//@version=4
strategy("Binomial Moving Average","BMA", overlay=true, margin_long=100, margin_short=100 ,max_bars_back=96)
//Binomial Moving Average:This type of moving average that is made by myself and i did not see anywhere before uses the half of binomial cofficients for
//averaging the prices for example if the period be 5 then we use the 9 degree binomial cofficients(that yields 10 cofficients) and use half of them.
//we use 126/256 for last bar,84/256,36/256,9/256 and finally use 1/256 for 5th bar. Seemingly this MA works better than EMA.
fa_ma=input(title='Fast MA',defval=10)
sl_ma=input(title='Slow MA',defval=30)
fac(n)=>
    fact=1
    for i= 1 to n
        fact:=fact*i
    fact
cof= array.new_float(sl_ma) 
hn_ma(price,length)=>
    sum=1.0
    sum1=0.0
    array.set(cof,length-1,1)
    for i=2 to length
        array.set(cof,length-i,fac(2*length-1)/(fac(i-1)*fac(2*length-i)))
        sum:=sum+array.get(cof,length-i)
    for i=0 to length-1
        array.set(cof,i,array.get(cof,i)/sum)
        sum1:=sum1+array.get(cof,i)*price[i]
    sum1
hn1=plot(hn_ma(close,sl_ma) , color=#00ff00)
hn2=plot(hn_ma(close,fa_ma) ,color=#ff0000)
fill(hn1,hn2,color=hn_ma(close,fa_ma)>hn_ma(close,sl_ma)?color.green:color.red)
longCondition = crossover(hn_ma(close, fa_ma), hn_ma(close, sl_ma))
if (longCondition)
    strategy.entry("Long", strategy.long)
shortCondition = crossunder(hn_ma(close, fa_ma), hn_ma(close, sl_ma))
if (shortCondition)
    strategy.entry("Short", strategy.short)
Expand (41 lines)

Overview

Binomial Moving Average plots a fast and a slow binomial moving average directly on the price chart, filling the space between them according to the trend direction. A long position enters when the fast moving average crosses above the slow moving average, while a short position enters on a crossunder. Positions reverse on opposite crossover signals. The script contains no stop-loss or take-profit rules.

Details

Published by

hasnocool on GitHub

Code credit

HosseinDaftary, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Moving averages, Trend

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Fast MAint10fa_ma
Slow MAint30sl_ma
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers