Pine Script v4 · Strategy
Coin Flipper Pro with strategy tester
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 is one contract and pays no commission. 16 settings; defaults include Max Bars between Coin Filps 25.0, Risk in % 5.0 and Risk to Reward Ratio x:1 1.5.
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 Coin Flipper Pro with strategy tester repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
- How did Coin Flipper Pro with strategy tester do on BTCUSDT 1D with default settings?
- −23.07%
- From 26 Jan 2024 to 21 Oct 2026, over 57 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Coin Flipper Pro with strategy tester be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Coin Flipper Pro with strategy tester use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Coin Flipper Pro with strategy tester run in Zeal Terminal?
- Yes
- It compiles in 28 ms and runs 1,000 bars in 71 ms, in the browser.
BTCUSDT · 1D · default settings
- short label
- short label
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −23.07%
- −$23,072.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 57
- 23 won · 34 lost
- Profitable
- 40.4%
- of closed trades
- Profit factor
- 0.83
- gross profit ÷ gross loss
- Max drawdown
- 52.39%
- −$64,666.30
One run with the author's default settings, $100,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
4 settings do nothing
“------- Trade Activity -------”, “------- Position Settings -------”, “------- Plot Options -------”, “------- Back Testing -------” are declared but never read.
-
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
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 96, 97, 98, 99. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 82
transp = on line 82, 83, 84. 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 round → math.round, random → math.random, barssince → ta.barssince.
- 4 strategy calls use the when = argument (line 96, 97, 98, 99). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 53 before, 53 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 9: input(type = input.float) → input.float()
- Line 10: input(type = input.float) → input.float()
- Line 41: round → math.round
- Line 41: random → math.random
- Line 43: barssince → ta.barssince
7 more edits
- Line 45: random → math.random
- Line 52: round → math.round
- Line 52: random → math.random
- Line 52: round → math.round
- Line 82: transp = 100 → color.new(color.white, 100)
- Line 83: transp = 100 → color.new(color.white, 100)
- Line 84: transp = 100 → color.new(color.white, 100)
⋯// © melodicfish-//@version=4+//@version=5strategy("Coin Flipper Pro",overlay=true,max_bars_back=100)⋯h2=input(title="------- Position Settings -------",defval=false)-risk=input(defval=5.0,title="Risk in % ",type=input.float, minval=0.001 ,step=0.1)+risk=input.float(defval=5.0,title="Risk in % ", minval=0.001 ,step=0.1)-ratio= input(defval=1.5,title="Risk to Reward Ratio x:1 ",type=input.float, minval=0.001,step=0.1)+ratio= input.float(defval=1.5,title="Risk to Reward Ratio x:1 ", minval=0.001,step=0.1)h3=input(title="------- Plot Options -------",defval=false)⋯getColor() => - round(random(1,255))+ math.round(math.random(1,255))// ===== Logic ========-if barssince(flip==true)>barsBetweenflips and posLive==false+if ta.barssince(flip==true)>barsBetweenflips and posLive==false flip:=true- coinLabel:=random(1,10)+ coinLabel:=math.random(1,10) // Candle Colors ⋯ flip:=false- barsBetweenflips:=round(random(3,round(maxBars)))+ barsBetweenflips:=math.round(math.random(3,math.round(maxBars))) posLive:=true⋯// ====== Plots ========-plot1=plot(plotBox and showBox? p1:na,style=plot.style_linebr,color=color.white, transp= 100)+plot1=plot(plotBox and showBox? p1:na,style=plot.style_linebr,color=color.new(color.white, 100))-plot2=plot(plotBox and showBox? p2:na,style=plot.style_linebr,color=color.white, transp= 100)+plot2=plot(plotBox and showBox? p2:na,style=plot.style_linebr,color=color.new(color.white, 100))-plot3=plot(plotBox and showBox? p3:na,style=plot.style_linebr,color=color.white, transp= 100)+plot3=plot(plotBox and showBox? p3:na,style=plot.style_linebr,color=color.new(color.white, 100))fill(plot1,plot2,color= color.green)⋯Clean v5
DiffersTrades differ: 53 before, 55 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.bool()
- Line 7: input() → input.float()
- Line 8: input() → input.bool()
- Line 11: input() → input.bool()
- Line 12: input() → input.bool()
- Line 13: input() → input.bool()
12 more edits
- Line 14: input() → input.bool()
- Line 15: input() → input.bool()
- Line 16: input() → input.int()
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 20: input() → input.int()
- Line 21: input() → input.int()
- Line 22: input() → input.int()
- Line 96: when = short==true → if block
- Line 97: when = stoppedOut==true or takeProfit==true → if block
- Line 98: when = long==true → if block
- Line 99: when = stoppedOut==true or takeProfit==true → if block
⋯// ======= User Inputs variables=========-h1=input(title="------- Trade Activity -------",defval=false)+h1=input.bool(title="------- Trade Activity -------",defval=false)-maxBars=input(25.0,title="Max Bars between Coin Filps",step=1.0,minval=4.0)+maxBars=input.float(25.0,title="Max Bars between Coin Filps",step=1.0,minval=4.0)-h2=input(title="------- Position Settings -------",defval=false)+h2=input.bool(title="------- Position Settings -------",defval=false)risk=input.float(defval=5.0,title="Risk in % ", minval=0.001 ,step=0.1)ratio= input.float(defval=1.5,title="Risk to Reward Ratio x:1 ", minval=0.001,step=0.1)-h3=input(title="------- Plot Options -------",defval=false)+h3=input.bool(title="------- Plot Options -------",defval=false)-showBox=input(defval=true, title="Show Position Boxes")+showBox=input.bool(defval=true, title="Show Position Boxes")-h4=input(title="------- Back Testing -------",defval=false)+h4=input.bool(title="------- Back Testing -------",defval=false)-runTest=input(defval=true, title="Run Strategy Back Test")+runTest=input.bool(defval=true, title="Run Strategy Back Test")-customTime=input(defval=false, title="Use Custom Date Range for back test")+customTime=input.bool(defval=false, title="Use Custom Date Range for back test")-tsYear = input(2021,minval=1000,maxval=9999,title= "Test Start Year")+tsYear = input.int(2021,minval=1000,maxval=9999,title= "Test Start Year")-tsMonth = input(1,minval=1,maxval=12,title= "Test Start Month")+tsMonth = input.int(1,minval=1,maxval=12,title= "Test Start Month")-tsDay = input(1,minval=1,maxval=31,title= "Test Start Day")+tsDay = input.int(1,minval=1,maxval=31,title= "Test Start Day")start = timestamp(tsYear,tsMonth,tsDay,0,0)-teYear = input(2021,minval=1000,maxval=9999,title= "Test Stop Year")+teYear = input.int(2021,minval=1000,maxval=9999,title= "Test Stop Year")-teMonth = input(5,minval=1,maxval=12,title= "Test Stop Month")+teMonth = input.int(5,minval=1,maxval=12,title= "Test Stop Month")-teDay = input(1,minval=1,maxval=31,title= "Test Stop Day")+teDay = input.int(1,minval=1,maxval=31,title= "Test Stop Day")end = timestamp(teYear,teMonth,teDay,0,0)⋯if runTest==true and customTime==false or runTest==true and customTime==true and time >= start and time <= end - strategy.entry("Sell", strategy.short,when=short==true)+ if short==true+ strategy.entry("Sell", strategy.short)- strategy.close("Sell", comment="Close Short", when=stoppedOut==true or takeProfit==true)+ if stoppedOut==true or takeProfit==true+ strategy.close("Sell", comment="Close Short")- strategy.entry("Long", strategy.long,when=long==true)+ if long==true+ strategy.entry("Long", strategy.long)- strategy.close("Long",comment="Close Long", when= stoppedOut==true or takeProfit==true )+ if stoppedOut==true or takeProfit==true+ strategy.close("Long",comment="Close Long" )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: 55 before, 49 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.
⋯// © melodicfish-//@version=5+//@version=6strategy("Coin Flipper Pro",overlay=true,max_bars_back=100)⋯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 |
|---|---|---|---|
| ------- Trade Activity ------- | false | bool | unused |
| Max Bars between Coin Filps | 25.0 | float · min 4.0 · step 1.0 | barsBetweenflips |
| ------- Position Settings ------- | false | bool | unused |
| Risk in % | 5.0 | float · min 0.001 · step 0.1 | p1 p3 riskLDEC riskSDEC |
| Risk to Reward Ratio x:1 | 1.5 | float · min 0.001 · step 0.1 | p1 riskSDEC |
| ------- Plot Options ------- | false | bool | unused |
| Show Position Boxes | true | bool | plot1 plot2 plot3 plot |
| ------- Back Testing ------- | false | bool | unused |
| Run Strategy Back Test | true | bool | entry Sell close Sell entry Long close Long line 95 |
| Use Custom Date Range for back test | false | bool | entry Sell close Sell entry Long close Long line 95 |
| Test Start Year | 2021 | int · min 1000 · max 9999 | start |
| Test Start Month | 1 | int · min 1 · max 12 | start |
| Test Start Day | 1 | int · min 1 · max 31 | start |
| Test Stop Year | 2021 | int · min 1000 · max 9999 | end |
| Test Stop Month | 5 | int · min 1 · max 12 | end |
| Test Stop Day | 1 | int · min 1 · max 31 | end |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Sell short | short==true | On | 96 |
| Close Sell | stoppedOut==true or takeProfit==true | On | 97 |
| Open Long long | long==true | On | 98 |
| Close Long | stoppedOut==true or takeProfit==true | On | 99 |
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 | −23.1% | +102.5% | 57 | 40% | 0.83 | 52.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −3.0% | +5.5% | 13 | 31% | 0.89 | 22.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2.1% | +9.8% | 62 | 37% | 0.64 | 2.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.4% | +8.4% | 20 | 30% | 0.67 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 63 | 65% | 1.90 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 24 | 46% | 1.04 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.2% | +148.3% | 59 | 41% | 1.19 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 16 | 38% | 0.69 | 0.2% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 18 | 44% | −$2,001.51 |
| Sideways market | 26 | 42% | −$3,408.97 |
| Falling market | 13 | 31% | −$17,662.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
53.1%
The 95th percentile of the worst drawdown when the same 57 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 30.8% to 53.1%; the tick is what actually happened, 51.3%. Order luck alone moves it this much.
All 57 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 28 Jan 2024 42,120.60 | 8 Feb 2024 44,349.60 | 11 | −$2,228.97 |
| long | 19 Feb 2024 52,137.70 | 28 Feb 2024 57,037.30 | 9 | $4,899.67 |
| long | 5 Mar 2024 68,245.70 | 6 Mar 2024 63,724.00 | 1 | −$4,521.70 |
| long | 16 Mar 2024 69,499.80 | 17 Mar 2024 65,300.60 | 1 | −$4,199.20 |
| long | 24 Mar 2024 63,990.00 | 26 Mar 2024 69,880.00 | 2 | $5,889.98 |
| long | 19 Apr 2024 63,470.10 | 23 Apr 2024 66,819.30 | 4 | $3,349.23 |
| short | 12 May 2024 60,826.00 | 16 May 2024 66,206.50 | 4 | −$5,380.52 |
| short | 7 Jun 2024 70,799.10 | 15 Jun 2024 66,044.00 | 8 | $4,755.07 |
| long | 17 Jun 2024 66,676.90 | 25 Jun 2024 60,293.30 | 8 | −$6,383.56 |
| long | 4 Jul 2024 60,208.60 | 5 Jul 2024 57,050.00 | 1 | −$3,158.55 |
| long | 18 Jul 2024 64,088.00 | 30 Jul 2024 66,784.70 | 12 | $2,696.69 |
| short | 2 Aug 2024 65,354.00 | 5 Aug 2024 58,161.00 | 3 | $7,193.02 |
| short | 12 Aug 2024 58,712.60 | 16 Aug 2024 57,541.10 | 4 | $1,171.54 |
| short | 29 Aug 2024 59,034.90 | 7 Sep 2024 53,963.00 | 9 | $5,071.93 |
| short | 20 Sep 2024 62,948.00 | 27 Sep 2024 65,174.00 | 7 | −$2,225.99 |
| short | 13 Oct 2024 63,206.20 | 15 Oct 2024 66,084.00 | 2 | −$2,877.77 |
| long | 7 Nov 2024 75,572.00 | 8 Nov 2024 75,857.90 | 1 | $285.90 |
| long | 15 Nov 2024 87,325.60 | 22 Nov 2024 98,317.10 | 7 | $10,991.50 |
| short | 7 Dec 2024 99,740.80 | 12 Dec 2024 101,125.00 | 5 | −$1,384.16 |
| short | 27 Dec 2024 95,791.60 | 31 Dec 2024 92,792.10 | 4 | $2,999.55 |
| short | 2 Jan 2025 94,591.80 | 4 Jan 2025 98,174.20 | 2 | −$3,582.39 |
| short | 19 Jan 2025 104,556.00 | 21 Jan 2025 102,260.00 | 2 | $2,296.23 |
| short | 9 Feb 2025 96,444.80 | 26 Feb 2025 88,680.40 | 17 | $7,764.36 |
| short | 2 Mar 2025 86,064.50 | 3 Mar 2025 94,270.00 | 1 | −$8,205.45 |
| short | 18 Mar 2025 84,010.00 | 20 Mar 2025 86,845.90 | 2 | −$2,835.91 |
| long | 1 Apr 2025 82,550.00 | 7 Apr 2025 78,430.00 | 6 | −$4,120.00 |
| long | 10 Apr 2025 82,615.20 | 11 Apr 2025 79,607.30 | 1 | −$3,007.92 |
| long | 27 Apr 2025 94,628.00 | 9 May 2025 103,262.00 | 12 | $8,633.61 |
| long | 18 May 2025 103,127.00 | 23 May 2025 111,696.00 | 5 | $8,569.57 |
| long | 27 May 2025 109,435.00 | 1 Jun 2025 104,592.00 | 5 | −$4,842.90 |
| long | 3 Jun 2025 105,858.00 | 23 Jun 2025 100,964.00 | 20 | −$4,894.13 |
| short | 27 Jun 2025 106,947.00 | 11 Jul 2025 116,010.00 | 14 | −$9,062.95 |
| long | 21 Jul 2025 117,265.00 | 4 Aug 2025 114,209.00 | 14 | −$3,056.30 |
| short | 6 Aug 2025 114,130.00 | 12 Aug 2025 118,686.00 | 6 | −$4,556.25 |
| short | 22 Aug 2025 112,500.00 | 3 Oct 2025 120,529.00 | 42 | −$8,029.35 |
| long | 5 Oct 2025 122,391.00 | 11 Oct 2025 112,774.00 | 6 | −$9,616.50 |
| long | 16 Oct 2025 110,763.00 | 18 Oct 2025 106,432.00 | 2 | −$4,331.60 |
| long | 24 Oct 2025 110,078.00 | 28 Oct 2025 114,108.00 | 4 | $4,029.46 |
| long | 13 Nov 2025 101,654.00 | 15 Nov 2025 94,594.00 | 2 | −$7,060.37 |
| long | 28 Nov 2025 91,333.90 | 2 Dec 2025 86,286.00 | 4 | −$5,047.93 |
| long | 11 Dec 2025 92,015.40 | 15 Dec 2025 88,172.20 | 4 | −$3,843.22 |
| short | 20 Dec 2025 88,136.90 | 23 Dec 2025 88,620.80 | 3 | −$483.84 |
| short | 6 Jan 2026 93,859.70 | 14 Jan 2026 95,414.00 | 8 | −$1,554.28 |
| short | 28 Jan 2026 89,250.00 | 31 Jan 2026 84,260.50 | 3 | $4,989.49 |
| short | 4 Feb 2026 75,770.20 | 5 Feb 2026 73,165.80 | 1 | $2,604.37 |
| long | 26 Feb 2026 67,988.00 | 3 Mar 2026 68,830.10 | 5 | $842.02 |
| short | 14 Mar 2026 70,930.00 | 17 Mar 2026 74,884.70 | 3 | −$3,954.66 |
| long | 2 Apr 2026 68,113.90 | 11 Apr 2026 72,962.70 | 9 | $4,848.79 |
| long | 28 Apr 2026 77,371.30 | 24 May 2026 76,752.00 | 26 | −$619.32 |
| long | 26 May 2026 77,322.00 | 29 May 2026 73,617.50 | 3 | −$3,704.49 |
| long | 4 Jun 2026 64,142.80 | 5 Jun 2026 63,886.00 | 1 | −$256.76 |
| long | 20 Jun 2026 63,543.90 | 25 Jun 2026 61,078.00 | 5 | −$2,465.90 |
| long | 6 Jul 2026 63,650.00 | 20 Aug 2026 69,334.80 | 45 | $5,684.77 |
| short | 22 Aug 2026 78,338.00 | 23 Aug 2026 77,074.90 | 1 | $1,263.09 |
| long | 29 Aug 2026 77,845.90 | 12 Sep 2026 77,225.70 | 14 | −$620.17 |
| long | 14 Sep 2026 76,842.00 | 22 Sep 2026 86,620.00 | 8 | $9,778.00 |
| long | 8 Oct 2026 83,321.80 | 9 Oct 2026 81,754.50 | 1 | −$1,567.35 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 28 ms | Yes 1,000 bars in 71 ms | Not measured |
| PineTS | No 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/// © melodicfish//@version=4strategy("Coin Flipper Pro",overlay=true,max_bars_back=100)// ======= User Inputs variables=========h1=input(title="------- Trade Activity -------",defval=false)maxBars=input(25.0,title="Max Bars between Coin Filps",step=1.0,minval=4.0)h2=input(title="------- Position Settings -------",defval=false)risk=input(defval=5.0,title="Risk in % ",type=input.float, minval=0.001 ,step=0.1)ratio= input(defval=1.5,title="Risk to Reward Ratio x:1 ",type=input.float, minval=0.001,step=0.1)h3=input(title="------- Plot Options -------",defval=false)showBox=input(defval=true, title="Show Position Boxes")h4=input(title="------- Back Testing -------",defval=false)runTest=input(defval=true, title="Run Strategy Back Test")customTime=input(defval=false, title="Use Custom Date Range for back test")tsYear = input(2021,minval=1000,maxval=9999,title= "Test Start Year")tsMonth = input(1,minval=1,maxval=12,title= "Test Start Month")tsDay = input(1,minval=1,maxval=31,title= "Test Start Day")start = timestamp(tsYear,tsMonth,tsDay,0,0)teYear = input(2021,minval=1000,maxval=9999,title= "Test Stop Year")teMonth = input(5,minval=1,maxval=12,title= "Test Stop Month")teDay = input(1,minval=1,maxval=31,title= "Test Stop Day")end = timestamp(teYear,teMonth,teDay,0,0)// ======= variables =========var barsBetweenflips=25var coinFlipResult=0.0var flip=truevar coinLabel=0.0var stoppedOut= truevar takeProfit=truevar posLive=falsevar p1=0.0var p2=0.0var p3=0.0var plotBox=falsevar posType=0long=falseshort=false// ===== Functions ======getColor() => round(random(1,255))// ===== Logic ========if barssince(flip==true)>barsBetweenflips and posLive==false flip:=true coinLabel:=random(1,10) // Candle Colors candleColor= flip==true and flip[1]==false and barstate.isconfirmed==false?color.rgb(getColor(),getColor(),getColor(),0):flip==false and close>=open?color.green:color.redcandleColor:= barstate.ishistory==true and close>=open?color.green: barstate.ishistory==true and close<open? color.red:candleColor barcolor(candleColor)if flip[1]==true and posLive==false flip:=false barsBetweenflips:=round(random(3,round(maxBars))) posLive:=true long:= flip[1]==true and coinLabel[1]>=5.0short:= flip[1]==true and coinLabel[1]<5.0 // Calculate Position Boxesif long==true and posType!=1 riskLDEC=1-(risk/100) p1:= close[1]*(1+((risk/100)*ratio)) // TargetLine p2:=close[1] p3:= close[1]*riskLDEC // StopLine plotBox:=true posType:=1 if short==true and posType!=-1 riskSDEC=1-((risk*ratio)/100) p1:= close[1]*riskSDEC // TargetLine p2:=close[1] p3:= close[1]*(1+(risk/100)) // StopLine plotBox:=true posType:=-1 // Check Trade Status stoppedOut:= posType==1 and long==false and low<= p3? true: posType==-1 and short==false and high>=p3? true: false takeProfit:= posType==1 and long == false and high>= p1? true: posType==-1 and short==false and low<=p1? true: false if stoppedOut==true or takeProfit==true posType:=0 plotBox:=false posLive:=false// ====== Plots ========plot1=plot(plotBox and showBox? p1:na,style=plot.style_linebr,color=color.white, transp= 100)plot2=plot(plotBox and showBox? p2:na,style=plot.style_linebr,color=color.white, transp= 100)plot3=plot(plotBox and showBox? p3:na,style=plot.style_linebr,color=color.white, transp= 100)fill(plot1,plot2,color= color.green)fill(plot2,plot3,color= color.red)plotshape(flip==true and flip[1]==false and coinLabel>=5.0,style=shape.labelup,location=location.belowbar, color=color.green,size=size.tiny,title="short label",text="Heads",textcolor=color.white)plotshape(flip==true and flip[1]==false and coinLabel<5.0,style=shape.labeldown,location=location.abovebar, color=color.red,size=size.tiny,title="short label",text="Tails",textcolor=color.white)if stoppedOut==true label.new(bar_index-1, p3, style=label.style_xcross, color=color.orange)if takeProfit==true label.new(bar_index-1, p1, style=label.style_flag, color=color.blue) if runTest==true and customTime==false or runTest==true and customTime==true and time >= start and time <= end strategy.entry("Sell", strategy.short,when=short==true) strategy.close("Sell", comment="Close Short", when=stoppedOut==true or takeProfit==true) strategy.entry("Long", strategy.long,when=long==true) strategy.close("Long",comment="Close Long", when= stoppedOut==true or takeProfit==true )