StrategyOpen sourceTrend

EMA Cross Risk

The EMA crossover strategy sized by risk: each trade loses the same share of equity at its stop, using Position Kit.

EMA Cross RiskLiveBinance data
Loading chart…

EMA Cross Risk is the EMA Cross strategy with one change that matters more than the signal itself: every trade is sized so that, if its stop is hit, it loses the same share of the account. The sizing comes from Position Kit, and the size written on the chart is the size the strategy tester opens.

How it works

A long position opens on the bar after the fast EMA crosses above the slow EMA. It closes at whichever comes first: the stop, the target, or the fast EMA crossing back below the slow one.

The stop sits a fixed percentage below the entry, and the target a set multiple of that distance above it. Because the stop distance is a fixed percentage, risk-based sizing becomes a fixed share of equity: risk per trade divided by stop distance. With the default settings, 1% ÷ 2% = 50% of equity per trade, and a trade stopped out loses 1% of equity before costs.

On the signal bar, Position Kit builds a plan from the current equity and the close, and the order is sent with that size. The label under the entry shows the size of the plan and the amount at risk; it is the same quantity the strategy tester traded.

Commission (0.1% per side) and slippage (0.05%) are included, so that the test results are not more favourable than real trading would be.

Reading the chart

Hover over an item below to see it on the chart.

  • Blue line: the fast EMA, 9 bars by default.
  • Grey line: the slow EMA, 21 bars by default.
  • Red line and label: the stop of the open trade. The label on the entry bar gives the size in units of the base asset and the amount at risk in the quote currency.
  • Green line: the target of the open trade.

Settings

Fast EMA
9
Length of the fast moving average.
Slow EMA
21
Length of the slow moving average.
Risk per trade (%)
1
The share of equity lost if the stop is hit, before commission and slippage.
Stop distance (%)
2
How far below the entry the stop is placed.
Target (x risk)
2
The target distance as a multiple of the stop distance.

The sizing in the code

Each order carries its own size. The plan is calculated on the signal bar and passed to enterLong as qty, so the size follows the account from one trade to the next.

plan = pk.planFor(equity(), riskPct < stopPct ? riskPct : stopPct, close, close * (1 - stopPct / 100), rr)
enterLong(signal, qty = plan.qty, stopLoss = stopPct, takeProfit = stopPct * rr)
ExampleOn BTCUSDT 4h with 10,000 USDT, a crossover bar closes at 68,020. The plan sizes the trade at 0.0735 BTC, a position of 5,000 USDT, and the order fills on the next bar. If it fills at 68,020, the stop is at 66,659.60 and the target at 70,740.80; when that stop is hit, the loss is 100 USDT before commission and slippage.

Limits and points to note

  • Risk per trade cannot exceed the stop distance: above that, the position would need more than the whole account. Size is capped at 100% of equity, and the actual risk is then the stop distance. Leverage is not used.
  • The size is set at the close of the signal bar and the order fills at the next bar's open. If the open is different, the amount at risk changes by the same proportion.
  • The stop is a fixed percentage, not a volatility stop. In a quiet market it may be wide; in an active one, ordinary movement can reach it.
  • On a price gap or a fast bar, the fill can be worse than the stop, so a single loss can be larger than the chosen risk.
  • Moving average crossovers react after a move has started and give back part of it before the exit. The strategy only takes long trades.
  • Test results describe the past. They are not a forecast and do not indicate future results.

EMA Cross Risk, EMA Cross stratejisinin sinyalden daha önemli tek bir değişiklik yapılmış hâlidir: her işlem, zarar-durduru çalışırsa hesabın aynı payını kaybettirecek büyüklükte açılır. Boyutlandırma Position Kit'ten gelir ve grafikte yazan büyüklük, strateji sınamasının açtığı büyüklüktür.

Nasıl çalışır

Hızlı EMA yavaş EMA'yı yukarı kestiğinde bir sonraki barda long pozisyon açılır. Pozisyon zarar-durdur, kâr-al ya da hızlı EMA'nın yavaş EMA'yı aşağı kesmesinden hangisi önce gelirse onunla kapanır.

Zarar-durdur girişin sabit bir yüzde altında, kâr-al seviyesi ise bu mesafenin belirli bir katı üstünde durur. Zarar-durdur mesafesi sabit bir yüzde olduğu için riske göre boyutlandırma, sermayenin sabit bir payına dönüşür: işlem başına risk bölü zarar-durdur mesafesi. Varsayılan ayarlarla %1 ÷ %2 = işlem başına sermayenin %50'si olur ve zarar-durdurla kapanan bir işlem, maliyetler hariç sermayenin %1'ini kaybettirir.

Sinyal barında Position Kit, o anki sermaye ve kapanış fiyatıyla bir plan kurar ve emir bu büyüklükle gönderilir. Girişin altındaki etiket planın büyüklüğünü ve riske giren tutarı gösterir; bu büyüklük strateji sınamasının işlem yaptığı miktarla aynıdır.

Komisyon (her yön için %0,1) ve kayma (%0,05) hesaba katılır; böylece sınama sonuçları gerçek işlemden daha olumlu görünmez.

Grafiği okuma

Aşağıdaki bir maddenin üzerine geldiğinizde grafikte öne çıkar.

  • Mavi çizgi: hızlı EMA, varsayılan 9 bar.
  • Gri çizgi: yavaş EMA, varsayılan 21 bar.
  • Kırmızı çizgi ve etiket: açık işlemin zarar-durduru. Giriş barındaki etiket, büyüklüğü ana varlık cinsinden, riske giren tutarı karşı para birimi cinsinden verir.
  • Yeşil çizgi: açık işlemin kâr-al seviyesi.

Ayarlar

Fast EMA
9
Hızlı hareketli ortalamanın uzunluğu.
Slow EMA
21
Yavaş hareketli ortalamanın uzunluğu.
Risk per trade (%)
1
Zarar-durdur çalışırsa kaybedilen sermaye payı; komisyon ve kayma hariç.
Stop distance (%)
2
Zarar-durdurun girişin ne kadar altına konduğu.
Target (x risk)
2
Kâr-al mesafesinin zarar-durdur mesafesine oranı.

Koddaki boyutlandırma

Her emir kendi büyüklüğünü taşır. Plan sinyal barında hesaplanır ve enterLong'a qty olarak verilir; böylece büyüklük işlemden işleme hesabı izler.

plan = pk.planFor(equity(), riskPct < stopPct ? riskPct : stopPct, close, close * (1 - stopPct / 100), rr)
enterLong(signal, qty = plan.qty, stopLoss = stopPct, takeProfit = stopPct * rr)
ÖrnekBTCUSDT 4 saatlikte 10.000 USDT ile bir kesişim barı 68.020'de kapanır. Plan işlemi 0,0735 BTC, yani 5.000 USDT'lik bir pozisyon olarak boyutlar ve emir bir sonraki barda gerçekleşir. Giriş de 68.020'den olursa zarar-durdur 66.659,60'ta, kâr-al 70.740,80'dedir; bu zarar-durdur çalıştığında kayıp, komisyon ve kayma hariç 100 USDT'dir.

Sınırlar ve dikkat edilecekler

  • İşlem başına risk zarar-durdur mesafesini aşamaz: bunun üstünde pozisyon hesabın tamamından fazlasını gerektirirdi. Büyüklük sermayenin %100'üyle sınırlanır ve gerçek risk o zaman zarar-durdur mesafesi olur. Kaldıraç kullanılmaz.
  • Büyüklük sinyal barının kapanışında belirlenir, emir bir sonraki barın açılışında gerçekleşir. Açılış farklıysa riske giren tutar da aynı oranda değişir.
  • Zarar-durdur oynaklığa göre değil, sabit bir yüzdeyle konur. Sakin piyasada geniş kalabilir; hareketli piyasada olağan dalgalanma ona ulaşabilir.
  • Fiyat boşluğunda ya da hızlı bir barda gerçekleşme zarar-durdurdan kötü olabilir; bu durumda tek bir kayıp seçilen riskten büyük olur.
  • Hareketli ortalama kesişimleri hareket başladıktan sonra tepki verir ve çıkıştan önce hareketin bir kısmını geri verir. Strateji yalnız long işlem açar.
  • Sınama sonuçları geçmişi anlatır; bir öngörü değildir ve gelecekteki sonuçlara işaret etmez.
EMA Cross Risk37 linesVersion 2View full code
strategy("EMA Cross Risk", overlay = true)import MarkudaDev/PositionKit/1 as pk commission(0.1)slippage(0.05) fastLen = input.int(9, "Fast EMA", min = 2)slowLen = input.int(21, "Slow EMA", min = 3)riskPct = input.float(1, "Risk per trade (%)", min = 0.1, max = 5, step = 0.1)stopPct = input.float(2, "Stop distance (%)", min = 0.5, max = 20, step = 0.1)rr = input.float(2, "Target (x risk)", min = 0.5, max = 10, step = 0.5) fast = ema(close, fastLen)slow = ema(close, slowLen)