Strategy · Pine Script v5 · On the chart

Investor Ninja

by the-up· code credited to hmtkyn

This strategy places repeated long entries of a fixed cash amount on a chosen weekday at a selected weekly interval inside a user-defined start and end date.

View on GitHub

GitHub stars10on the repository
Pine versionv5runs as is
Lines of code62
Settings13inputs
LicenceMIT
Last update2 years ago18 Mar 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

62 lines of Pine Script v5 from index.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

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

//@version=5
strategy(title='Investor Ninja | by @hmtkyn', shorttitle='Investor Ninja | by @hmtkyn', overlay=true, default_qty_type=strategy.cash, default_qty_value=100, initial_capital=100, commission_type=strategy.commission.percent, pyramiding=1000, close_entries_rule='ANY')

//var GroupSource = "Select a Soruce"
//selectSource = input(hl2, title='Select Source', group=GroupSource)

var GroupStart = "Date range start"
startYear = input.int(title='Start Year', defval=2021, minval=1970, maxval=3000, group=GroupStart)
startMonth = input.int(title='Start Month', defval=1, minval=1, maxval=12, group=GroupStart)
startDay = input.int(title='Start Day', defval=1, minval=1, maxval=31, group=GroupStart)
startHour = input.int(title='Start Hour', defval=11, minval=0, maxval=23, group=GroupStart)
startMinute = input.int(title='Start Minute', defval=0, minval=0, maxval=59, group=GroupStart)

var GroupEnd = "Date range end"
endYear = input.int(title='End Year', defval=2022, minval=1970, maxval=3000, group=GroupEnd)
endMonth = input.int(title='End Month', defval=12, minval=1, maxval=12, group=GroupEnd)
endDay = input.int(title='End Day', defval=31, minval=1, maxval=31, group=GroupEnd)
endHour = input.int(title='End Hour', defval=11, minval=0, maxval=23, group=GroupEnd)
endMinute = input.int(title='End Minute', defval=0, minval=0, maxval=59, group=GroupEnd)

var GroupStrategy = "Strategy period"
get_week = input.string("From week 4", "Start week", options = ["From week 1","From week 2","From week 3","From week 4"],group=GroupStrategy)
get_range = input.string("Every 4 weeks", "Weekly range", options = ["Every 1 weeks","Every 2 weeks","Every 3 weeks","Every 4 weeks"],group=GroupStrategy)
get_day = input.string("Friday", "Day of Week", options = ["Monday","Tuesday","Wednesday","Thursday","Friday"],group=GroupStrategy)

var nth_day = 6
var nth_week = 4
var start_week = 4

switch get_day
    "Monday" => nth_day := 2
    "Tuesday" => nth_day := 3
    "Wednesday" => nth_day := 4
    "Thursday" => nth_day := 5
    "Friday" => nth_day := 6
    => nth_day := 6

switch get_range
    "Every 1 weeks" => nth_week := 1
    "Every 2 weeks" => nth_week := 2
    "Every 3 weeks" => nth_week := 3
    "Every 4 weeks" => nth_week := 4
    => nth_week := 4

switch get_week
    "From week 1" => start_week := 1
    "From week 2" => start_week := 2
    "From week 3" => start_week := 3
    "From week 4" => start_week := 4
    => start_week := 4

timeRange = time >= timestamp(syminfo.timezone, startYear, startMonth, startDay, startHour, startMinute) and time <= timestamp(syminfo.timezone, endYear, endMonth, endDay, endHour, endMinute)

for i = 1 to 52
    if timeRange and weekofyear == ((i-1)*nth_week)+start_week and dayofweek == nth_day
        strategy.entry(id='Long' + ' - ' + str.tostring(dayofmonth) + '.' + str.tostring(month) + '.' + str.tostring(year), direction=strategy.long)

if time > timestamp(syminfo.timezone, endYear, endMonth, endDay,endHour,endMinute) and dayofweek >= 2
    strategy.close_all()

Overview

Investor Ninja draws on the price chart. Settings choose the calendar window, the starting week, whether buys occur every one to four weeks, and the weekday from Monday through Friday. After the end timestamp, it closes all open positions on a weekday. There is no stop loss, and many overlapping longs can stay open together.

Details

Published by

the-up on GitHub

Code credit

hmtkyn, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Topics

pinescriptpinescript-strategiescryptocurrencytradingviewinvestor-ninja

Settings

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

SettingTypeDefaultVariable
Start Yearint2021startYear
Start Monthint1startMonth
Start Dayint1startDay
Start Hourint11startHour
Start Minuteint0startMinute
End Yearint2022endYear
End Monthint12endMonth
End Dayint31endDay
End Hourint11endHour
End Minuteint0endMinute
Start weekstringFrom week 4get_week
Weekly rangestringEvery 4 weeksget_range
Show all 13 settings
SettingTypeDefaultVariable
Day of WeekstringFridayget_day
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
440 stars

This script is an empty strategy template for Pine Script developers. It declares a version 4 strategy named Basic Strategy Boilerplate with the short title Strategy Boilerplate and sets overlay to true so any future plots would appear on the price chart. It d

Strategy v4
Updated 7 years ago · GPL-3.0 GitHub repository of Basic Strategy Boilerplate

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

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]

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