Indicator · Pine Script v4 · On the chart

SimpleBot

by g-moe· code credited to goodgains

SimpleBot is a Pine Script v4 overlay indicator that stores recent prior-bar opens and closes in rolling arrays and averages each series.

View on GitHub

GitHub stars3on the repository
Pine versionv4older, still runs
Lines of code92
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

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

92 lines of Pine Script v4 from Tradingview/simplebot.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

simplebot.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // You can change the License here
// © goodgains

// (c) SimpleSignalsOfficial //

//@version=4
study("SimpleBot", overlay=true)

// @keywords: array-averaged-open-close, smoothed-open-line, smoothed-close-line, period-array-buffer, v4-study-overlay, configurable-line-style, line-width-settings, open-close-lines, n-period-average, historical-bar-array, simple-trend-lines, averaged-ohlc-levels, array-shift-push, avg-open-close-plot, minimal-signal-bot, price-level-guidance, rolling-average-bands, array-size-input, dual-line-indicator, plot-horizontal-levels


//--------------------------------------------------------
//--------------------------------------------------------
// Array Average
//--------------------------------------------------------
//--------------------------------------------------------
i_Periods = input(3,   "Nbr Periods", group="Nbr Periods") 
//--------------------------------------------------------
//--------------------------------------------------------
// Initialize array of user-selected size with `na` values. 
var Open_Array = array.new_float(i_Periods) 
var Close_Array = array.new_float(i_Periods) 
if bar_index    
    // Remove the oldest level from the beginning of the array.
    array.shift(Open_Array)
    array.shift(Close_Array)
    //--------------------------------------------------------
    // Add the new level to the end of the array. 
    array.push(Open_Array, open[1])
    array.push(Close_Array, close[1])
    //--------------------------------------------------------
// Calculate the avg of levels in the array, excluding any `na` values. 
Avg_Open = array.avg(Open_Array)
Avg_Close = array.avg(Close_Array)
//--------------------------------------------------------
//Plots (Can be hidden)
//--------------------------------------------------------
//plot(Avg_Open, "Average Open", close > Avg_Open ? color.lime : color.red)
//plot(Avg_Close, "Average Close", close > Avg_Close ? color.lime : color.red)
//--------------------------------------------------------


//--------------------------------------------------------
//--------------------------------------------------------

l_style_ = input(defval = "Solid", title = "Line Style", options = ["Solid", "Dashed", "Dotted"], group="Style Settings")
l_width = input(defval = 1, title = "Line Width", minval = 1, group="Style Settings")

Open_col = input(defval = color.lime, title = "Open", group="Color Settings")
Close_col = input(defval = color.red, title = "Close", group="Color Settings")
//--------------------------------------------------------
//--------------------------------------------------------
// set line styles
var l_style = l_style_ == "Solid" ? line.style_solid : 
                       l_style_ == "Dashed" ? line.style_dashed :
                       line.style_dotted
                       //--------------------------------------------------------
//--------------------------------------------------------


//--------------------------------------------------------
//--------------------------------------------------------
var OpenLine = line.new(x1=bar_index, y1=Avg_Open[0],
     x2=bar_index, y2=Avg_Open, color=Open_col, width = l_width, style=l_style,
     extend=extend.right)
// Update the Open line
if (Avg_Open)
    line.set_xy1(id=OpenLine, x=bar_index[1], y=Avg_Open)
    line.set_xy2(id=OpenLine, x=bar_index, y=Avg_Open)
    
var CloseLine = line.new(x1=bar_index, y1=Avg_Open[0],
     x2=bar_index, y2=Avg_Open, color=Close_col, width = l_width, style=l_style,
     extend=extend.right)
// Update the Open line
if (Avg_Close)
    line.set_xy1(id=CloseLine, x=bar_index[1], y=Avg_Close)
    line.set_xy2(id=CloseLine, x=bar_index, y=Avg_Close)    
//--------------------------------------------------------
//--------------------------------------------------------


//--------------------------------------------------------
// Inbuilt Average
//--------------------------------------------------------
//periods = input(3)
//Open = sma(open,periods)[1]
//Close = sma(close,periods)[1]
//plot(Open)
//plot(Close, color=color.white)


//--------------------------------------------------------

Overview

SimpleBot draws two horizontal lines on the price chart, one for the average open and one for the average close, both extended to the right. The period count, line style, line width, and the two line colors are user settings. It does not generate entries, exits, or a stop loss, and the provided source ends while updating the open line.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Moving averages, Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Nbr Periodsint3i_Periods
Line StylestringSolidl_style_
Line Widthint1l_width
Opencolorcolor.limeOpen_col
Closecolorcolor.redClose_col
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

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

PivotHighLow

by Alorse
330 stars

This indicator calculates pivot high and pivot low points on the price chart based on configurable left and right bar counts. Confirmed pivot highs and lows are plotted with negative bar offsets directly on the price chart using line and cross styles. Addition

Indicator v4 Support & resistanceOscillators & momentum Repaints
Updated 2 months ago · None stated GitHub repository of PivotHighLow

Deduct

by TaichiS
219 stars

This indicator displays moving average deduction reference points directly on the price chart. It plots dynamic labels on historical bars corresponding to short, medium, and long lookback periods, defaulted to 20, 60, and 120 bars. Each text label displays the

Indicator v4 Moving averagesSupport & resistance
Updated 5 years ago · None stated GitHub repository of Deduct

Ichimoku Cloud

by harryguiacorn
219 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

Midnight VWAP

by TradersPost
218 stars

The Midnight VWAP indicator calculates and overlays two distinct Volume Weighted Average Price (VWAP) lines on the price chart based on customizable session timeframes. It tracks an overnight or pre-market session alongside regular trading hours, resetting cal

Indicator v6 Moving averagesSessions & time
Updated 3 months ago · None stated GitHub repository of Midnight VWAP

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