Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[astropark] Moon Phases [strategy]

A Pine Script v4 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1 commission. 14 settings; defaults include New Moon Color color.black, Full Moon Color color.white and New Moon Background Color #fffff0aa.

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 [astropark] Moon Phases [strategy] repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 19 of 19 trades.
How did [astropark] Moon Phases [strategy] do on BTCUSDT 1D with default settings?
−87.05%
From 26 Jan 2024 to 21 Oct 2026, over 66 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [astropark] Moon Phases [strategy] be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does [astropark] Moon Phases [strategy] use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does [astropark] Moon Phases [strategy] run in Zeal Terminal?
Yes
It compiles in 30 ms and runs 1,000 bars in 65 ms, in the browser.

BTCUSDT · 1D · default settings

  • Full Moon
  • New Moon
  • Buy Label
  • Sell Label
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (14)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$12,812$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
−87.05%
−$87,052.50
Buy and hold
+102.5%
same period
Closed trades
66
22 won · 44 lost
Profitable
33.3%
of closed trades
Profit factor
0.45
gross profit ÷ gross loss
Max drawdown
90.15%
−$113,985.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog strategy (line 73) shows 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 93, 94, 95, 96. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 70

    transp = on line 70, 91, 92. v5 folds the transparency into the colour with color.new(c, transp).

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames floor → math.floor.
  • 4 strategy calls use the when = argument (line 93, 94, 95, 96). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 66 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 2: //@version=4 → //@version=5
  • Line 14: floor → math.floor
  • Line 26: floor → math.floor
  • Line 31: floor → math.floor
  • Line 32: floor → math.floor
  • Line 33: floor → math.floor
8 more edits
  • Line 33: floor → math.floor
  • Line 45: floor → math.floor
  • Line 45: floor → math.floor
  • Line 46: floor → math.floor
  • Line 46: floor → math.floor
  • Line 70: transp = 10 → color.new(col, 10)
  • Line 91: transp = 0 → color.new(color.green, 0)
  • Line 92: transp = 0 → color.new(color.red, 0)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=4+// @version=5strategy(title="[astropark] Moon Phases [strategy]", overlay=true, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 100000, currency = currency.USD, commission_value = 0.1)⋯    x = _v-    x := x - floor(x)+    x := x - math.floor(x)    if x < 0⋯    float ip = na-    y := _year - floor((12 - _month) / 10)       +    y := _year - math.floor((12 - _month) / 10)           m := _month + 9⋯    -    k1 := floor(365.25 * (y + 4712))+    k1 := math.floor(365.25 * (y + 4712))-    k2 := floor(30.6 * m + 0.5)+    k2 := math.floor(30.6 * m + 0.5)-    k3 := floor(floor((y / 100) + 49) * 0.75) - 38+    k3 := math.floor(math.floor((y / 100) + 49) * 0.75) - 38    ⋯moon = -     floor(age)[1] > floor(age) ? 1 : +     math.floor(age)[1] > math.floor(age) ? 1 : -     floor(age)[1] < 15 and floor(age) >= 15 ? -1 : na+     math.floor(age)[1] < 15 and math.floor(age) >= 15 ? -1 : na//} --- INIT⋯    col := newMoonBackgroundColor-bgcolor(col, title="Moon Phase", transp=10)+bgcolor(color.new(col, 10), title="Moon Phase")//} --- PLOT⋯analyzeFromTimestamp = timestamp(analysisStartYear, analysisStartMonth, analysisStartDay, analysisStartHour, analysisStartMinute)-plotshape(showBuySellSignals and buySignal, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(showBuySellSignals and buySignal, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-plotshape(showBuySellSignals and sellSignal, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(showBuySellSignals and sellSignal, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)strategy.entry("long", strategy.long, when = time > analyzeFromTimestamp and buySignal and longEnabled)⋯

Clean v5

VerifiedDownload the v5 script

Same 66 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 5: input() → input.color()
  • Line 6: input() → input.color()
  • Line 7: input() → input.bool()
  • Line 8: input() → input.color()
  • Line 9: input() → input.color()
  • Line 73: input() → input.string()
12 more edits
  • Line 82: input() → input.bool()
  • Line 83: input() → input.bool()
  • Line 84: input() → input.bool()
  • Line 85: input() → input.int()
  • Line 86: input() → input.int()
  • Line 87: input() → input.int()
  • Line 88: input() → input.int()
  • Line 89: input() → input.int()
  • Line 93: when = time > analyzeFromTimestamp and buySignal and longEnabled → if block
  • Line 94: when = time > analyzeFromTimestamp and sellSignal and shortEnabled → if block
  • Line 95: when = sellSignal → if block
  • Line 96: when = buySignal → if block
⋯// INPUT    --- {-newMoonColor = input(color.black, "New Moon Color")+newMoonColor = input.color(color.black, "New Moon Color")-fullMoonColor = input(color.white, "Full Moon Color")+fullMoonColor = input.color(color.white, "Full Moon Color")-fillBackground = input(true, "Fill Background?")+fillBackground = input.bool(true, "Fill Background?")-newMoonBackgroundColor = input(#fffff0aa, "New Moon Background Color")+newMoonBackgroundColor = input.color(#fffff0aa, "New Moon Background Color")-fullMoonBackgroundColor = input(#aaaaaaaa, "Full Moon Background Color")+fullMoonBackgroundColor = input.color(#aaaaaaaa, "Full Moon Background Color")//} --- INPUT⋯// STRATEGY     --- {-strategy = input("buy on new moon, sell on full moon", options=["buy on new moon, sell on full moon","sell on new moon, buy on full moon"])+strategy = input.string("buy on new moon, sell on full moon", options=["buy on new moon, sell on full moon","sell on new moon, buy on full moon"])longCond = strategy == "buy on new moon, sell on full moon" ? moon == -1 : moon == 1⋯sellSignal = shortCond and weAreInShortTrade[1] == false-showBuySellSignals = input(defval=true, title = "Show Buy/Sell Signals")+showBuySellSignals = input.bool(defval=true, title = "Show Buy/Sell Signals")-longEnabled = input(true, title="Long enabled")+longEnabled = input.bool(true, title="Long enabled")-shortEnabled = input(true, title="Short enabled")+shortEnabled = input.bool(true, title="Short enabled")-analysisStartYear = input(2017, "Backtesting From Year", minval=1980)+analysisStartYear = input.int(2017, "Backtesting From Year", minval=1980)-analysisStartMonth = input(1, "And Month", minval=1, maxval=12)+analysisStartMonth = input.int(1, "And Month", minval=1, maxval=12)-analysisStartDay = input(1, "And Day", minval=1, maxval=31)+analysisStartDay = input.int(1, "And Day", minval=1, maxval=31)-analysisStartHour = input(0, "And Hour", minval=0, maxval=23)+analysisStartHour = input.int(0, "And Hour", minval=0, maxval=23)-analysisStartMinute = input(0, "And Minute", minval=0, maxval=59)+analysisStartMinute = input.int(0, "And Minute", minval=0, maxval=59)analyzeFromTimestamp = timestamp(analysisStartYear, analysisStartMonth, analysisStartDay, analysisStartHour, analysisStartMinute)⋯plotshape(showBuySellSignals and sellSignal, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-strategy.entry("long", strategy.long, when = time > analyzeFromTimestamp and buySignal and longEnabled)+if time > analyzeFromTimestamp and buySignal and longEnabled+    strategy.entry("long", strategy.long)-strategy.entry("short", strategy.short, when = time > analyzeFromTimestamp and sellSignal and shortEnabled)+if time > analyzeFromTimestamp and sellSignal and shortEnabled+    strategy.entry("short", strategy.short)-strategy.close("long", when = sellSignal)+if sellSignal+    strategy.close("long")-strategy.close("short", when = buySignal)+if buySignal+    strategy.close("short")//} --- STRATEGY

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: 66 before, 89 after on BTCUSDT 1D, 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.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=5+// @version=6strategy(title="[astropark] Moon Phases [strategy]", overlay=true, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 100000, currency = currency.USD, commission_value = 0.1)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
New Moon Colorcolor.blackvalueplotshape
Full Moon Colorcolor.whitevalueplotshape
Fill Background?trueboolline 66 line 68
New Moon Background Color#fffff0aavaluecol
Full Moon Background Color#aaaaaaaavaluecol
Strategy (no label in the script)buy on new moon, sell on full moonstring · options ["buy on new moon, sell on full moon","sell on new moon, buy on full moon"]longCond shortCond
Show Buy/Sell SignalstrueboolBuy Label Sell Label
Long enabledtrueboolentry long
Short enabledtrueboolentry short
Backtesting From Year2017int · min 1980analyzeFromTimestamp
And Month1int · min 1 · max 12analyzeFromTimestamp
And Day1int · min 1 · max 31analyzeFromTimestamp
And Hour0int · min 0 · max 23analyzeFromTimestamp
And Minute0int · min 0 · max 59analyzeFromTimestamp

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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.

fullMoonBackgroundColorFull Moon Background Co…setting · #aaaaaaaanewMoonBackgroundColorNew Moon Background Col…setting · #fffff0aastrategyStrategysetting · buy on new moon, se…analysisStartYearBacktesting From Yearsetting · 2017analysisStartMonthAnd Monthsetting · 1analysisStartDayAnd Daysetting · 1analysisStartHourAnd Hoursetting · 0analysisStartMinuteAnd Minutesetting · 0timetimeprice dataxxvaluey, agey · age2 valuesm, k2m · k22 valuesk1, k3k1 · k32 valuesjdjdvalueipipvaluemoonmoonvaluecolcolvaluelongCond, shortCondlongCond · shortCond2 valuesanalyzeFromTimestampanalyzeFromTimestampvaluebuySignalbuySignalconditionsellSignalsellSignalconditionweAreInLongTradeweAreInLongTradeconditionweAreInShortTradeweAreInShortTradeconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryclose:longClose longstrategy.closeclose:shortClose shortstrategy.closeplotshape:49plotshapeplotshapeplotshape:57plotshapeplotshapebgcolor:70Moon Phasebgcolorplotshape:91Buy Labelplotshapeplotshape:92Sell Labelplotshape

Order rules

OrderFires whenBy defaultLine
Open long longtime > analyzeFromTimestamp and buySignal and longEnabledOn93
Open short shorttime > analyzeFromTimestamp and sellSignal and shortEnabledOn94
Close longsellSignalshortCond and weAreInShortTrade[1] == falseOn95
Close shortbuySignallongCond and weAreInLongTrade[1] == falseOn96

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, and the live replay matched history.

19/19trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−87.1%+102.5%6633%0.4590.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−29.3%+5.5%1040%0.4538.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−94.2%+9.8%6636%0.4094.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−34.0%+8.4%1040%0.4945.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−93.5%+16.7%6647%0.5495.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−59.6%+21.5%1040%0.2162.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−88.0%+148.3%6635%0.4689.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−21.0%+17.1%1050%0.5127.3%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2335%−$15,799.30
Sideways market2741%−$39,946.10
Falling market1619%−$31,294.10

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

92.0%

The 95th percentile of the worst drawdown when the same 66 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 87.0% to 92.0%; the tick is what actually happened, 89.7%. Order luck alone moves it this much.

0%106%
All 66 trades
SideEntryExitBarsP&L
short11 Feb 2024 47,751.1026 Feb 2024 51,728.8015−$8,530.02
long26 Feb 2024 51,728.8011 Mar 2024 68,955.9014$30,254.00
short11 Mar 2024 68,955.9026 Mar 2024 69,880.0015−$1,876.38
long26 Mar 2024 69,880.0010 Apr 2024 69,146.0015−$1,497.33
short10 Apr 2024 69,146.0025 Apr 2024 64,289.6015$8,083.87
long25 Apr 2024 64,289.609 May 2024 61,193.0014−$6,335.74
short9 May 2024 61,193.0024 May 2024 67,969.7015−$13,553.40
long24 May 2024 67,969.708 Jun 2024 69,355.6015$1,957.74
short8 Jun 2024 69,355.6023 Jun 2024 64,262.0015$7,759.60
long23 Jun 2024 64,262.007 Jul 2024 58,230.1014−$11,132.90
short7 Jul 2024 58,230.1022 Jul 2024 68,165.4015−$18,165.40
long22 Jul 2024 68,165.406 Aug 2024 54,018.8015−$18,211.30
short6 Aug 2024 54,018.8021 Aug 2024 59,013.8015−$6,501.26
long21 Aug 2024 59,013.804 Sep 2024 57,487.7014−$1,733.03
short4 Sep 2024 57,487.7019 Sep 2024 61,760.0015−$4,623.01
long19 Sep 2024 61,760.004 Oct 2024 60,752.7015−$1,022.66
short4 Oct 2024 60,752.7019 Oct 2024 68,428.0015−$7,049.10
long19 Oct 2024 68,428.002 Nov 2024 69,496.0014$650.22
short2 Nov 2024 69,496.0017 Nov 2024 90,588.0015−$14,823.50
long17 Nov 2024 90,588.002 Dec 2024 97,185.2015$2,383.05
short2 Dec 2024 97,185.2017 Dec 2024 106,059.0015−$3,365.39
long17 Dec 2024 106,059.001 Jan 2025 93,576.0015−$3,907.17
short1 Jan 2025 93,576.0016 Jan 2025 100,497.0015−$2,186.95
long16 Jan 2025 100,497.0030 Jan 2025 103,733.0014$801.78
short30 Jan 2025 103,733.0014 Feb 2025 96,608.1015$1,827.48
long14 Feb 2025 96,608.101 Mar 2025 84,349.9015−$3,759.68
short1 Mar 2025 84,349.9016 Mar 2025 84,338.4015−$47.41
long16 Mar 2025 84,338.4030 Mar 2025 82,648.5014−$559.15
short30 Mar 2025 82,648.5014 Apr 2025 83,760.0015−$384.02
long14 Apr 2025 83,760.0029 Apr 2025 95,011.2015$3,232.57
short29 Apr 2025 95,011.2014 May 2025 104,104.0015−$2,707.52
long14 May 2025 104,104.0028 May 2025 108,938.0014$1,109.07
short28 May 2025 108,938.0012 Jun 2025 108,645.0015$18.07
long12 Jun 2025 108,645.0027 Jun 2025 106,947.0015−$459.81
short27 Jun 2025 106,947.0012 Jul 2025 117,528.0015−$2,591.00
long12 Jul 2025 117,528.0026 Jul 2025 117,614.0014−$29.13
short26 Jul 2025 117,614.0010 Aug 2025 116,462.0015$179.71
long10 Aug 2025 116,462.0025 Aug 2025 113,494.0015−$637.31
short25 Aug 2025 113,494.009 Sep 2025 112,065.0015$239.17
long9 Sep 2025 112,065.0023 Sep 2025 112,651.0014$73.48
short23 Sep 2025 112,651.008 Oct 2025 121,333.0015−$1,810.90
long8 Oct 2025 121,333.0023 Oct 2025 107,567.0015−$2,430.52
short23 Oct 2025 107,567.007 Nov 2025 101,346.0015$1,041.82
long7 Nov 2025 101,346.0021 Nov 2025 86,637.2014−$2,892.53
short21 Nov 2025 86,637.206 Dec 2025 89,330.0015−$555.90
long6 Dec 2025 89,330.0021 Dec 2025 88,360.9015−$208.40
short21 Dec 2025 88,360.905 Jan 2026 91,529.7015−$607.27
long5 Jan 2026 91,529.7019 Jan 2026 93,673.1014$329.85
short19 Jan 2026 93,673.103 Feb 2026 78,738.6015$2,481.50
long3 Feb 2026 78,738.6018 Feb 2026 67,503.5015−$2,634.03
short18 Feb 2026 67,503.505 Mar 2026 72,666.8015−$1,225.13
long5 Mar 2026 72,666.8020 Mar 2026 69,930.0015−$569.44
short20 Mar 2026 69,930.004 Apr 2026 66,964.3015$558.21
long4 Apr 2026 66,964.3018 Apr 2026 77,072.0014$2,136.09
short18 Apr 2026 77,072.003 May 2026 78,686.8015−$378.91
long3 May 2026 78,686.8018 May 2026 77,457.7015−$283.72
short18 May 2026 77,457.702 Jun 2026 71,408.9015$1,205.83
long2 Jun 2026 71,408.9016 Jun 2026 66,328.7014−$1,244.71
short16 Jun 2026 66,328.701 Jul 2026 58,624.7015$1,804.49
long1 Jul 2026 58,624.7016 Jul 2026 64,756.3015$1,803.02
short16 Jul 2026 64,756.3031 Jul 2026 64,780.0015−$45.92
long31 Jul 2026 64,780.0014 Aug 2026 63,490.9014−$423.47
short14 Aug 2026 63,490.9029 Aug 2026 77,845.9015−$4,322.17
long29 Aug 2026 77,845.9013 Sep 2026 77,278.7015−$135.62
short13 Sep 2026 77,278.7028 Sep 2026 84,472.0015−$1,377.41
long28 Sep 2026 84,472.0012 Oct 2026 83,773.1014−$134.45

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 30 msYes 1,000 bars in 65 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

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/// @version=4strategy(title="[astropark] Moon Phases [strategy]", overlay=true, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 100000, currency = currency.USD, commission_value = 0.1)// INPUT    --- {newMoonColor = input(color.black, "New Moon Color")fullMoonColor = input(color.white, "Full Moon Color")fillBackground = input(true, "Fill Background?")newMoonBackgroundColor = input(#fffff0aa, "New Moon Background Color")fullMoonBackgroundColor = input(#aaaaaaaa, "Full Moon Background Color")//} --- INPUT// FUNCTION --- {normalize(_v) =>    x = _v    x := x - floor(x)    if x < 0        x := x + 1    xcalcPhase(_year, _month, _day) =>    int y = na    int m = na    float k1 = na     float k2 = na     float k3 = na    float jd = na    float ip = na    y := _year - floor((12 - _month) / 10)           m := _month + 9    if m >= 12         m := m - 12        k1 := floor(365.25 * (y + 4712))    k2 := floor(30.6 * m + 0.5)    k3 := floor(floor((y / 100) + 49) * 0.75) - 38        jd := k1 + k2 + _day + 59    if jd > 2299160        jd := jd - k3        ip := normalize((jd - 2451550.1) / 29.530588853)    age = ip * 29.53//} --- FUNCTION// INIT     --- {age = calcPhase(year, month, dayofmonth)moon =      floor(age)[1] > floor(age) ? 1 :      floor(age)[1] < 15 and floor(age) >= 15 ? -1 : na//} --- INIT// PLOT     --- {plotshape(     moon==1,      "Full Moon",      shape.circle,      location.top,      color.new(newMoonColor, 20),      size=size.normal     )   plotshape(     moon==-1,      "New Moon",      shape.circle,      location.bottom,      color.new(fullMoonColor, 20),      size=size.normal     )   var color col = naif moon == 1 and fillBackground    col := fullMoonBackgroundColorif moon == -1 and fillBackground    col := newMoonBackgroundColorbgcolor(col, title="Moon Phase", transp=10)//} --- PLOT// STRATEGY     --- {strategy = input("buy on new moon, sell on full moon", options=["buy on new moon, sell on full moon","sell on new moon, buy on full moon"])longCond = strategy == "buy on new moon, sell on full moon" ? moon == -1 : moon == 1shortCond = strategy == "buy on new moon, sell on full moon" ? moon == 1 : moon == -1weAreInLongTrade = falseweAreInShortTrade = falseweAreInLongTrade := (longCond or weAreInLongTrade[1]) and shortCond == falseweAreInShortTrade := (shortCond or weAreInShortTrade[1]) and longCond == falsebuySignal = longCond and weAreInLongTrade[1] == falsesellSignal = shortCond and weAreInShortTrade[1] == falseshowBuySellSignals = input(defval=true, title = "Show Buy/Sell Signals")longEnabled = input(true, title="Long enabled")shortEnabled = input(true, title="Short enabled")analysisStartYear = input(2017, "Backtesting From Year", minval=1980)analysisStartMonth = input(1, "And Month", minval=1, maxval=12)analysisStartDay = input(1, "And Day", minval=1, maxval=31)analysisStartHour = input(0, "And Hour", minval=0, maxval=23)analysisStartMinute = input(0, "And Minute", minval=0, maxval=59)analyzeFromTimestamp = timestamp(analysisStartYear, analysisStartMonth, analysisStartDay, analysisStartHour, analysisStartMinute)plotshape(showBuySellSignals and buySignal, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)plotshape(showBuySellSignals and sellSignal, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)strategy.entry("long", strategy.long, when = time > analyzeFromTimestamp and buySignal and longEnabled)strategy.entry("short", strategy.short, when = time > analyzeFromTimestamp and sellSignal and shortEnabled)strategy.close("long", when = sellSignal)strategy.close("short", when = buySignal)//} --- STRATEGY