Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Stairs Gain Strategy - MG

A Pine Script v5 strategy built on ATR (14) and Crossover (close). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 8 settings; defaults include Leading Periot 52, Displacement 1 and Zarar Durdurma % 1.0.

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 Stairs Gain Strategy - MG repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 134 of 134 trades.
How did Stairs Gain Strategy - MG do on BTCUSDT 1D with default settings?
+4.23%
From 26 Jan 2024 to 21 Oct 2026, over 461 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Stairs Gain Strategy - MG 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: 461 before, 669 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Stairs Gain Strategy - MG use a stop loss?
Yes
strategy.exit sets a stop on line 43, 48.
Does Stairs Gain Strategy - MG run in Zeal Terminal?
Yes
It compiles in 20 ms and runs 1,000 bars in 62 ms, in the browser.

BTCUSDT · 1D · default settings

  • Leading Span B
  • İşleme Giriş Seviyesi
  • Long Kar Alım Seviyesi
  • Long Zarar Durdurma Seviyesi
  • Short Kar Alım Seviyesi
  • Short Zarar Durdurma Seviyesi
  • 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 (8)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,042,280$2,025,273Equity from $1,000,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
+4.23%
$42,284.70
Buy and hold
+102.5%
same period
Closed trades
461
204 won · 256 lost
Profitable
44.3%
of closed trades
Profit factor
1.11
gross profit ÷ gross loss
Max drawdown
2.53%
−$25,577.30

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 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 40, 45. 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.

SettingDefaultType and rangeFeeds
Leading Periot52int · min 1leadLine2
Displacement1int · min 1Leading Span B buycross sellcross
Pozisyon Sıra Filtresi UygulatrueboollongFiltreSonuc shortFiltreSonuc
Zarar Durdurma %1.0float · step 0.01longZararDurdur shortZararDurdur
Kar Alma %2.0float · step 0.01longKarAl shortKarAl
ATR Çarpanı0.3float · step 0.01atrDegeri
ATR Üst Limit0.01float · step 0.01buycross
ATR Alt Limit0.06float · step 0.01sellcross

What it calculates

  • ATR14atrDegeri · line 19
  • Crossoverclose, leadLine2[displacement-1]buycross · line 24
  • CrossoverleadLine2[displacement-1], closesellcross · line 25

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.

high · low · closehigh · low · closeprice dataatrCarpaniATR Çarpanısetting · 0.3closecloseprice datadisplacementDisplacementsetting · 1atrbuyukdegerATR Üst Limitsetting · 0.01atrkucukdegerATR Alt Limitsetting · 0.06laggingSpan2PeriodsLeading Periotsetting · 52karAlmaYuzdeKar Alma %setting · 2.0zararDurdurmaYuzdeZarar Durdurma %setting · 1.0atrDegeriATR→ atrDegeribuycrossCrossover→ buycrosssellcrossCrossover→ sellcrossleadLine2leadLine2valuelongFiltreSonuc, shortFiltreSonuclongFiltreSonuc · short…2 valueslongKarAl, shortKarAllongKarAl · shortKarAl2 valueslongZararDurdur, shortZararDurdurlongZararDurdur · short…2 valuesentry:LongOpen Longstrategy.entryexit:Long Exitexit Long Exitstrategy.exitentry:ShortOpen Shortstrategy.entryexit:Short Exitexit Short Exitstrategy.exitplot:10Leading Span Bplotplot:50İşleme Giriş Seviyesiplotplot:51Long Kar Alım Seviyesiplotplot:52Long Zarar Durdurma Sev…plotplot:53Short Kar Alım Seviyesiplotplot:54Short Zarar Durdurma Se…plot

Order rules

OrderFires whenBy defaultLine
Open Long longbuycross and longFiltreSonucOn40
Exit Long Exit stop and limitevery barOn43
Open Short shortsellcross and shortFiltreSonucOn45
Exit Short Exit stop and limitevery barOn48

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.

134/134trades 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+4.2%+102.5%46144%1.112.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.1%+5.5%17937%1.130.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.1%+9.8%48344%0.950.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%25540%1.280.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%49345%0.970.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%31335%0.970.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%47544%1.110.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%22032%0.850.0%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 market15744%$7,929.89
Sideways market20243%$24,844.80
Falling market10248%$9,509.95

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

How bad could the drawdown be?

5.7%

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

0%7%
The first 150 of 461 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.5027 Jan 2024 41,823.500$0.00
short27 Jan 2024 41,823.5028 Jan 2024 42,241.801−$418.24
long29 Jan 2024 42,031.1030 Jan 2024 43,302.701$1,271.66
short31 Jan 2024 42,941.101 Feb 2024 42,082.301$858.83
long2 Feb 2024 43,082.904 Feb 2024 42,652.102−$430.83
short5 Feb 2024 42,582.906 Feb 2024 43,008.701−$425.83
long7 Feb 2024 43,099.008 Feb 2024 44,349.601$1,250.64
short9 Feb 2024 45,288.7010 Feb 2024 47,132.801−$1,844.12
long11 Feb 2024 47,751.1012 Feb 2024 48,706.101$955.03
short13 Feb 2024 49,917.3014 Feb 2024 50,416.501−$499.18
long15 Feb 2024 51,795.2017 Feb 2024 51,277.202−$517.96
short18 Feb 2024 51,642.6019 Feb 2024 52,159.101−$516.43
long20 Feb 2024 51,774.7021 Feb 2024 51,257.001−$517.75
short22 Feb 2024 51,849.4023 Feb 2024 50,812.401$1,036.99
long24 Feb 2024 50,744.2025 Feb 2024 51,759.001$1,014.89
short26 Feb 2024 51,728.8027 Feb 2024 54,476.501−$2,747.63
long28 Feb 2024 57,037.3029 Feb 2024 62,432.101$5,394.76
short1 Mar 2024 61,131.002 Mar 2024 62,387.901−$1,256.91
long3 Mar 2024 61,987.304 Mar 2024 63,227.001$1,239.75
short5 Mar 2024 68,245.706 Mar 2024 63,724.001$4,521.70
long7 Mar 2024 66,074.008 Mar 2024 67,395.501$1,321.49
short9 Mar 2024 68,124.2010 Mar 2024 68,805.401−$681.25
long11 Mar 2024 68,955.9012 Mar 2024 72,078.101$3,122.22
short13 Mar 2024 71,452.0014 Mar 2024 73,072.401−$1,620.40
long15 Mar 2024 71,388.9016 Mar 2024 69,499.801−$1,889.10
short17 Mar 2024 65,300.6018 Mar 2024 68,393.501−$3,092.83
long19 Mar 2024 67,610.0020 Mar 2024 61,937.401−$5,672.59
short21 Mar 2024 67,840.5022 Mar 2024 65,501.301$2,339.23
long23 Mar 2024 63,796.6024 Mar 2024 65,072.601$1,275.94
short25 Mar 2024 67,210.0026 Mar 2024 69,880.001−$2,670.00
long27 Mar 2024 69,988.0028 Mar 2024 69,288.101−$699.88
short29 Mar 2024 70,780.601 Apr 2024 69,365.003$1,415.62
long2 Apr 2024 69,649.803 Apr 2024 65,464.001−$4,185.82
short4 Apr 2024 65,963.305 Apr 2024 68,487.801−$2,524.53
long6 Apr 2024 67,820.607 Apr 2024 69,177.101$1,356.42
short8 Apr 2024 69,360.409 Apr 2024 71,620.001−$2,259.62
long10 Apr 2024 69,146.0011 Apr 2024 70,631.101$1,485.08
short12 Apr 2024 70,006.2013 Apr 2024 67,116.501$2,889.70
long14 Apr 2024 63,924.5015 Apr 2024 65,661.901$1,737.33
short16 Apr 2024 63,420.0017 Apr 2024 64,054.201−$634.20
long18 Apr 2024 61,277.4019 Apr 2024 63,470.101$2,192.71
short20 Apr 2024 63,818.0021 Apr 2024 64,940.601−$1,122.57
long22 Apr 2024 64,941.2023 Apr 2024 66,819.301$1,878.17
short24 Apr 2024 66,414.0025 Apr 2024 64,289.601$2,124.42
long26 Apr 2024 64,498.3027 Apr 2024 63,770.001−$728.33
short28 Apr 2024 63,462.0029 Apr 2024 64,096.601−$634.62
long30 Apr 2024 63,866.001 May 2024 60,672.001−$3,193.99
short2 May 2024 58,365.003 May 2024 59,060.601−$695.63
long4 May 2024 62,882.005 May 2024 64,139.701$1,257.65
short6 May 2024 64,012.007 May 2024 62,731.801$1,280.24
long8 May 2024 62,312.109 May 2024 61,193.001−$1,119.04
short10 May 2024 63,074.0011 May 2024 60,800.001$2,274.01
long12 May 2024 60,826.0013 May 2024 62,042.501$1,216.52
short14 May 2024 62,940.1015 May 2024 61,577.501$1,362.60
long16 May 2024 66,206.5017 May 2024 65,235.201−$971.30
short18 May 2024 67,024.0019 May 2024 67,694.201−$670.24
long20 May 2024 66,274.0021 May 2024 71,446.601$5,172.62
short22 May 2024 70,148.3023 May 2024 68,745.401$1,402.97
long24 May 2024 67,969.7025 May 2024 69,329.101$1,359.40
short26 May 2024 69,290.6027 May 2024 69,983.501−$692.91
long28 May 2024 69,436.4029 May 2024 68,398.401−$1,038.03
short30 May 2024 67,652.4031 May 2024 68,352.201−$699.76
long1 Jun 2024 67,540.003 Jun 2024 68,890.802$1,350.81
short4 Jun 2024 68,809.905 Jun 2024 70,537.801−$1,727.94
long6 Jun 2024 71,108.007 Jun 2024 70,396.901−$711.08
short8 Jun 2024 69,355.6010 Jun 2024 70,049.202−$693.56
long11 Jun 2024 69,540.0012 Jun 2024 67,314.201−$2,225.77
short13 Jun 2024 68,264.0014 Jun 2024 66,773.001$1,490.97
long15 Jun 2024 66,044.0017 Jun 2024 65,383.602−$660.44
short18 Jun 2024 66,504.3019 Jun 2024 65,174.201$1,330.09
long20 Jun 2024 64,974.4021 Jun 2024 64,324.601−$649.75
short23 Jun 2024 64,262.0024 Jun 2024 62,976.801$1,285.25
long25 Jun 2024 60,293.3026 Jun 2024 61,806.001$1,512.71
short27 Jun 2024 60,865.0028 Jun 2024 61,706.501−$841.48
long29 Jun 2024 60,427.8030 Jun 2024 61,636.401$1,208.56
short1 Jul 2024 62,772.003 Jul 2024 61,516.602$1,255.45
long4 Jul 2024 60,208.605 Jul 2024 57,050.001−$3,158.55
short6 Jul 2024 56,628.807 Jul 2024 58,230.101−$1,601.34
long8 Jul 2024 55,857.809 Jul 2024 56,975.001$1,117.16
short10 Jul 2024 58,050.0011 Jul 2024 58,630.501−$580.50
long12 Jul 2024 57,339.9013 Jul 2024 58,486.701$1,146.80
short14 Jul 2024 59,204.0015 Jul 2024 60,797.901−$1,593.90
long16 Jul 2024 64,724.1017 Jul 2024 66,018.601$1,294.49
short18 Jul 2024 64,088.0019 Jul 2024 64,728.901−$640.88
long20 Jul 2024 66,660.0021 Jul 2024 67,993.201$1,333.21
short22 Jul 2024 68,165.4023 Jul 2024 66,802.001$1,363.31
long24 Jul 2024 65,936.0025 Jul 2024 65,276.601−$659.36
short26 Jul 2024 65,799.9027 Jul 2024 67,908.001−$2,108.05
long28 Jul 2024 67,896.5029 Jul 2024 67,217.501−$678.97
short30 Jul 2024 66,784.7031 Jul 2024 65,449.001$1,335.70
long1 Aug 2024 64,628.002 Aug 2024 63,981.701−$646.29
short4 Aug 2024 60,698.005 Aug 2024 58,161.001$2,536.99
long6 Aug 2024 54,018.807 Aug 2024 56,022.001$2,003.18
short8 Aug 2024 55,133.809 Aug 2024 61,686.001−$6,552.24
long10 Aug 2024 60,838.0011 Aug 2024 60,229.601−$608.38
short13 Aug 2024 59,346.6014 Aug 2024 60,587.201−$1,240.52
long15 Aug 2024 58,683.4016 Aug 2024 57,541.101−$1,142.34
short17 Aug 2024 58,874.6018 Aug 2024 59,492.001−$617.40
long19 Aug 2024 58,427.3020 Aug 2024 59,595.901$1,168.55
short21 Aug 2024 59,013.8022 Aug 2024 61,156.001−$2,142.23
long23 Aug 2024 60,375.8024 Aug 2024 64,037.201$3,661.41
short25 Aug 2024 64,157.0026 Aug 2024 62,873.901$1,283.15
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$3,419.00
short29 Aug 2024 59,034.9030 Aug 2024 59,625.301−$590.35
long31 Aug 2024 59,124.001 Sep 2024 58,532.801−$591.24
short2 Sep 2024 57,301.803 Sep 2024 59,132.101−$1,830.35
long4 Sep 2024 57,487.705 Sep 2024 56,912.901−$574.88
short6 Sep 2024 56,180.007 Sep 2024 53,963.001$2,217.03
long8 Sep 2024 54,160.909 Sep 2024 55,244.101$1,083.22
short10 Sep 2024 57,042.0011 Sep 2024 57,636.001−$593.98
long12 Sep 2024 57,338.0013 Sep 2024 58,484.801$1,146.76
short14 Sep 2024 60,498.0015 Sep 2024 59,288.001$1,209.96
long16 Sep 2024 59,132.0017 Sep 2024 58,214.001−$918.01
short18 Sep 2024 60,314.0019 Sep 2024 61,760.001−$1,445.99
long20 Sep 2024 62,948.0023 Sep 2024 64,207.003$1,258.96
short24 Sep 2024 63,340.0025 Sep 2024 64,262.701−$922.71
long26 Sep 2024 63,152.0027 Sep 2024 65,174.001$2,021.98
short28 Sep 2024 65,769.9030 Sep 2024 64,454.602$1,315.40
long1 Oct 2024 63,327.602 Oct 2024 60,804.901−$2,522.68
short3 Oct 2024 60,649.304 Oct 2024 61,255.801−$606.50
long5 Oct 2024 62,086.007 Oct 2024 63,327.702$1,241.72
short8 Oct 2024 62,224.009 Oct 2024 60,979.501$1,244.49
long10 Oct 2024 60,636.0011 Oct 2024 61,848.701$1,212.73
short12 Oct 2024 62,540.0013 Oct 2024 63,206.201−$666.24
long14 Oct 2024 62,870.0015 Oct 2024 66,084.001$3,213.98
short16 Oct 2024 67,074.1017 Oct 2024 67,744.901−$670.75
long18 Oct 2024 67,421.8020 Oct 2024 68,770.202$1,348.44
short21 Oct 2024 69,032.0022 Oct 2024 67,377.501$1,654.50
long23 Oct 2024 67,426.0024 Oct 2024 66,668.601−$757.36
short25 Oct 2024 68,198.3026 Oct 2024 66,698.301$1,499.95
long27 Oct 2024 67,092.8028 Oct 2024 68,434.601$1,341.86
short29 Oct 2024 69,962.2030 Oct 2024 72,736.401−$2,774.20
long31 Oct 2024 72,344.801 Nov 2024 70,292.001−$2,052.74
short2 Nov 2024 69,496.003 Nov 2024 68,106.101$1,389.92
long4 Nov 2024 68,776.005 Nov 2024 67,850.001−$925.98
short6 Nov 2024 69,372.007 Nov 2024 75,572.001−$6,199.98
long8 Nov 2024 75,857.9010 Nov 2024 77,375.102$1,517.16
short11 Nov 2024 80,370.0012 Nov 2024 88,648.001−$8,277.99
long13 Nov 2024 87,952.0014 Nov 2024 90,375.201$2,423.21
short15 Nov 2024 87,325.6016 Nov 2024 91,032.101−$3,706.49
long17 Nov 2024 90,588.0018 Nov 2024 89,682.101−$905.88
short19 Nov 2024 90,464.1020 Nov 2024 92,310.801−$1,846.73
long21 Nov 2024 94,286.6022 Nov 2024 98,317.101$4,030.56
short23 Nov 2024 98,892.0024 Nov 2024 96,914.201$1,977.84
long25 Nov 2024 97,900.1026 Nov 2024 93,010.001−$4,890.04
short27 Nov 2024 91,965.2028 Nov 2024 95,863.101−$3,897.95
long29 Nov 2024 95,644.001 Dec 2024 97,556.902$1,912.88
short2 Dec 2024 97,185.203 Dec 2024 95,241.501$1,943.71
long4 Dec 2024 95,849.705 Dec 2024 98,587.301$2,737.63
short6 Dec 2024 96,945.607 Dec 2024 99,740.801−$2,795.21

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Stairs Gain Strategy - MG this page—v5 strategy+4.2%4612.5%
SOJA PIVOT by ParaBellum68atrv4 strategy+3.3%918.2%
Volatility System by EduardoMattjeatrv5 strategy+150.2%221.5%
ATR Stop Buy Strategy by phobo3satrv4 strategyNo trades on this market
VBand Strategy by Saravanan_Ragavanatrv4 strategyNo trades on this market
Volatility Breakout Strategy [Angel Algo] by AngelAlgoatrv5 strategy+3.1%183.6%

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 40, 45). 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.

Clean v5

VerifiedDownload the v5 script

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

  • Line 40: when = buycross and longFiltreSonuc → if block
  • Line 45: when = sellcross and shortFiltreSonuc → if block
⋯//LONG GİRİŞ-strategy.entry("Long", strategy.long, when=buycross and longFiltreSonuc)+if buycross and longFiltreSonuc+    strategy.entry("Long", strategy.long)longKarAl = strategy.position_avg_price * (1 + karAlmaYuzde)⋯//SHORT GİRİŞ-strategy.entry("Short", strategy.short, when=sellcross and shortFiltreSonuc)+if sellcross and shortFiltreSonuc+    strategy.entry("Short", strategy.short)shortKarAl = strategy.position_avg_price * (1 - karAlmaYuzde)⋯

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: 461 before, 669 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.

⋯// © MGULHANN-//@version=5+//@version=6//İchimoku Leading Span 2 Hesaplaması ve Girişleri⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 20 msYes 1,000 bars in 62 msNot measured
PineTSNot testedNot testedNot 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/// © MGULHANN//@version=5//İchimoku Leading Span 2 Hesaplaması ve Girişleristrategy("Stairs Gain Strategy - MG", overlay=true, margin_long=100, margin_short=100)laggingSpan2Periods = input.int(52, minval=1, title="Leading Periot")displacement = input.int(1, minval=1, title="Displacement")donchian(len) => math.avg(ta.lowest(len), ta.highest(len))leadLine2 = donchian(laggingSpan2Periods)p2 = plot(leadLine2, offset = displacement - 1, color=#EF9A9A,     title="Leading Span B")// İşlem Tekrarını Filtrele  filtreUygula = input.bool(true,title="Pozisyon Sıra Filtresi Uygula")//Kar Al / Zarar Durdur Seviyeleri GirişlerizararDurdurmaYuzde = input.float(1.0, title='Zarar Durdurma %', step=0.01) / 100karAlmaYuzde = input.float(2.0, title='Kar Alma %', step=0.01) / 100//ATR HesaplamasıatrCarpani = input.float(0.3, title="ATR Çarpanı", step= 0.01)atrDegeri = ta.atr(14) * atrCarpani//ATR Değer Girişleriatrbuyukdeger = input.float(0.01, title="ATR Üst Limit", step=0.01)atrkucukdeger = input.float(0.06, title="ATR Alt Limit", step=0.01)//Buy ve Sell Şartlarıbuycross =   ta.crossover(close,leadLine2[displacement-1]) ? atrDegeri > atrbuyukdeger : strategy.position_size == 0sellcross = ta.crossover(leadLine2[displacement-1],close) ? atrDegeri < atrkucukdeger : strategy.position_size == 0//KONTROLvar sonPozisyonYonu = 0//Son kapanan pozisyon long ise degiskenin degerini 1 olarak ataif strategy.position_size[1] > 0 and strategy.position_size == 0    sonPozisyonYonu := 1//Son kapanan pozisyon short ise degiskenin degerini -1 olarak ataif strategy.position_size[1] < 0 and strategy.position_size == 0    sonPozisyonYonu := -1    //eger filtre uygulama seçiliyse ve son pozisyon yönü long ise 'longFiltreSonuc' degiskenine false degeri ata ve bir sonraki pozisyonun long olmasını engellelongFiltreSonuc = filtreUygula ? sonPozisyonYonu == 1 ? false : true : true//eger filtre uygulama seçiliyse ve son pozisyon yönü short ise 'shortFiltreSonuc' degiskenine false degeri ata ve bir sonraki pozisyonun short olmasını engelleshortFiltreSonuc = filtreUygula ? sonPozisyonYonu == -1 ? false : true : true//LONG GİRİŞstrategy.entry("Long", strategy.long, when=buycross and longFiltreSonuc)longKarAl = strategy.position_avg_price * (1 + karAlmaYuzde)longZararDurdur = strategy.position_avg_price * (1 - zararDurdurmaYuzde)strategy.exit("Long Exit","Long",limit=longKarAl, stop=longZararDurdur)//SHORT GİRİŞstrategy.entry("Short", strategy.short, when=sellcross and shortFiltreSonuc)shortKarAl = strategy.position_avg_price * (1 - karAlmaYuzde)shortZararDurdur = strategy.position_avg_price * (1 + zararDurdurmaYuzde)strategy.exit("Short Exit","Short",limit=shortKarAl, stop=shortZararDurdur)//Kar Al ve Zarar Durdur Seviyelerinin Grafikte İşaretlenmesiplot(strategy.position_size != 0 ? strategy.position_avg_price : na, color=color.navy, linewidth=2, style=plot.style_linebr, title="İşleme Giriş Seviyesi")plot(strategy.position_size > 0 ? longKarAl : na, color=color.green, linewidth=2, style=plot.style_linebr, title="Long Kar Alım Seviyesi")plot(strategy.position_size > 0 ? longZararDurdur : na, color=color.red, linewidth=2, style=plot.style_linebr, title="Long Zarar Durdurma Seviyesi")plot(strategy.position_size < 0 ? shortKarAl : na, color=color.green, linewidth=2, style=plot.style_linebr, title="Short Kar Alım Seviyesi")plot(strategy.position_size < 0 ? shortZararDurdur : na, color=color.red, linewidth=2, style=plot.style_linebr, title="Short Zarar Durdurma Seviyesi")//plotshape(buycross,size=size.small,style=shape.labelup,location=location.belowbar,color=color.green,text="Al", offset = displacement-1, textcolor=color.white)//plotshape(sellcross,size=size.small,style=shape.labeldown,location=location.abovebar,color=color.red,text="Sat", offset = displacement-1, textcolor=color.white)