Pine Script v5 · Strategy
Trade Hour
A Pine Script v5 strategy built on CUM (hours_x*indicator) and RSI or MFI (close, 24). It has 2 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include Src close, Timezone UTC+0000 and Timeperiod 24.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Trade Hour repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Trade Hour do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does Trade Hour run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 43 before, 23 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Trade Hour use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Trade Hour run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 42 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog src (line 6), timezone (line 7) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 37, 38. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Src (no label in the script) | close | source | buy_indicator sell_indicator |
| Timezone (no label in the script) | UTC+0000 | string · options ["UTC+0000","GMT+0000","America/New_York","America/Los_Angeles","America/Chicago","America/Phoenix","America/Toronto","America/Vancouver","America/Argentina" ,"America/El_Salvador","America/Sao_Paulo","America/Bogota","Europe/Moscow","Europe/Athens","Europe/Berlin","Europe/London","Europe/Madrid","Europe/Paris","Europe/Warsaw","Australia/Sydney","Australia/Brisbane","Australia/Adelaide","Australia/ACT","Asia/Almaty","Asia/Ashkhabad","Asia/Tokyo","Asia/Taipei","Asia/Singapore","Asia/Shanghai","Asia/Seoul","Asia/Tehran","Asia/Dubai","Asia/Kolkata","Asia/Hong_Kong","Asia/Bangkok","Pacific/Auckland","Pacific/Chatham","Pacific/Fakaofo","Pacific/Honolulu"] | hours isLongBestHour isShortBestHour |
| Timeperiod | 24 | int | buy_indicator sell_indicator |
What it calculates
- CUMhours_x*indicator
hours_x_avg · line 20 - CUMhours_y*indicator
hours_y_avg · line 21 - RSI / MFISrc (close), Timeperiod (24)
buy_indicator · line 23 - RSI / MFI1/src, Timeperiod (24)
sell_indicator · line 24
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| order buy long | isLongBestHourmath.round(buy_hour) == hour(time,timezone) | On | 37 |
| order sell short | isShortBestHourmath.round(sell_hour) == hour(time,timezone) | On | 38 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +12.9% | +5.5% | 43 | 42% | 2.80 | 9.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.5% | +8.4% | 42 | 69% | 3.62 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 50 | 60% | 6.27 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 24 | 54% | 3.12 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Trade Hour this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| CCU MFI + RSI + STOCH RSI by Bangsoul | mfi rsi | v4 strategy | +41.8% | 6 | 37.4% |
| Full CRYPTO pack macd, rsi, obv, ema strategy by SoftKill21 | rsi cum | v4 strategy | No trades on this market | ||
| 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders by ggekko21 | rsi mfi | v5 strategy | No trades on this market | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 2 strategy calls use the when = argument (line 37, 38). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 43 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 37: when = isLongBestHour → if block
- Line 38: when = isShortBestHour → if block
⋯bgcolor(isShortBestHour ? color.new(color.red,80) : na)-strategy.order("buy", strategy.long, when =isLongBestHour)+if isLongBestHour+ strategy.order("buy", strategy.long)-strategy.order("sell", strategy.short, when = isShortBestHour)+if isShortBestHour+ strategy.order("sell", strategy.short)Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 43 before, 23 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// based on idea of circular mean with atan2-//@version=5+//@version=6strategy("Trade Hour V4",overlay=false)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | Yes 1,000 bars in 42 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © mablue (Masoud Azizi)// based on idea of circular mean with atan2//@version=5strategy("Trade Hour V4",overlay=false)src = input.source(close)timezone = input.string("UTC+0000",options=["UTC+0000","GMT+0000","America/New_York","America/Los_Angeles","America/Chicago","America/Phoenix","America/Toronto","America/Vancouver","America/Argentina" ,"America/El_Salvador","America/Sao_Paulo","America/Bogota","Europe/Moscow","Europe/Athens","Europe/Berlin","Europe/London","Europe/Madrid","Europe/Paris","Europe/Warsaw","Australia/Sydney","Australia/Brisbane","Australia/Adelaide","Australia/ACT","Asia/Almaty","Asia/Ashkhabad","Asia/Tokyo","Asia/Taipei","Asia/Singapore","Asia/Shanghai","Asia/Seoul","Asia/Tehran","Asia/Dubai","Asia/Kolkata","Asia/Hong_Kong","Asia/Bangkok","Pacific/Auckland","Pacific/Chatham","Pacific/Fakaofo","Pacific/Honolulu"] )length = input.int(24,"Timeperiod")arctan2(x,y)=> if x>0 and y>0 result = math.atan(x/y) else if y<0 result = math.atan(x/y) + math.pi else if x<0 and y>0 result = math.atan(x/y) + 2*math.pibest_hour(indicator)=> hours = (2*math.pi)*(hour(time,timezone)/24) hours_y = math.sin(hours) hours_x = math.cos(hours) hours_x_avg = ta.cum(hours_x*indicator)/ta.cum(indicator) hours_y_avg = ta.cum(hours_y*indicator)/ta.cum(indicator) hours_avg = (arctan2(hours_y_avg,hours_x_avg)*24/(2*math.pi))%24buy_indicator = math.avg(ta.rsi(src,length),ta.mfi(src,length))sell_indicator = math.avg(ta.rsi(1/src,length),ta.mfi(1/src,length))// buy_indicator = ta.roc(src,length)// sell_indicator = ta.roc(1/src,length)// buy_indicator = ta.roc(src,length)// sell_indicator = ta.roc(1/src,length)buy_hour = best_hour(buy_indicator)sell_hour = best_hour(sell_indicator)plot(buy_hour,"Buy hour",color.green)plot(sell_hour,"Sell hour",color.red)bool isLongBestHour = math.round(buy_hour) == hour(time,timezone)bool isShortBestHour = math.round(sell_hour) == hour(time,timezone)bgcolor(isLongBestHour ? color.new(color.green,80) : na)bgcolor(isShortBestHour ? color.new(color.red,80) : na)strategy.order("buy", strategy.long, when =isLongBestHour)strategy.order("sell", strategy.short, when = isShortBestHour)