PROTECTED SOURCE SCRIPT

Diabolos Long

53
What the strategy tries to do

It looks for RSI dips into oversold, then waits for RSI to recover above a chosen level before placing a limit buy slightly below the current price. If the limit doesn’t fill within a few bars, it cancels it. Once in a trade, it sets a fixed take-profit and stop-loss. It can pyramid up to 3 entries.

Step-by-step
1) Inputs you control

RSI Length (rsiLen), Oversold level (rsiOS), and a re-entry threshold (rsiEntryLevel) you want RSI to reach after oversold.

Entry offset % (entryOffset): how far below the current close to place your limit buy.

Cancel after N bars (cancelAfterBars): if still not filled after this many bars, the limit order is canceled.

Risk & compounding knobs: initialRisk (% of equity for first order), compoundRate (% to artificially grow the equity base after each signal), plus fixed TP% and SL%.

2) RSI logic (arming the setup)

It calculates rsi = ta.rsi(close, rsiLen).

If RSI falls below rsiOS, it sets a flag inOversold := true (this “arms” the next potential long).

A long signal (longCondition) happens only when:

inOversold is true (we were oversold),

RSI comes back above rsiOS,

and RSI is at least rsiEntryLevel.

So: dip into OS → recover above OS and to your threshold → signal fires.

3) Placing the entry order

When longCondition is true:

It computes a limit price: close * (1 - entryOffset/100) (i.e., below the current bar’s close).

It sizes the order as positionRisk / close, where:

positionRisk starts as accountEquity * (initialRisk/100).

accountEquity was set once at script start to strategy.equity.

It places a limit long: strategy.order("Long Entry", strategy.long, qty=..., limit=limitPrice).

It then resets inOversold := false (disarms until RSI goes oversold again).

It remembers the bar index (orderBarIndex := bar_index) so it can cancel later if unfilled.

Important nuance about “compounding” here

After signaling, it does:

compoundedEquity := compoundedEquity * (1 + compoundRate/100)

positionRisk := compoundedEquity * (initialRisk/100)

This means your future order sizes grow by a fixed compound rate every time a signal occurs, regardless of whether previous trades won or lost. It’s not tied to actual PnL; it’s an artificial growth curve. Also, accountEquity was captured only once at start, so it doesn’t automatically track live equity changes.

4) Auto-cancel the limit if it doesn’t fill

On each bar, if bar_index - orderBarIndex >= cancelAfterBars, it does strategy.cancel("Long Entry") and clears orderBarIndex.

If the order already filled, cancel does nothing (there’s nothing pending with that id).

Behavioral consequence: Because you set inOversold := false at signal time (not on fill), if a limit order never fills and later gets canceled, the strategy will not fire a new entry until RSI goes below oversold again to re-arm.

5) Managing the open position

If strategy.position_size > 0, it reads the avg entry price, then sets:

takeProfitPrice = avgEntryPrice * (1 + exitGainPercentage/100)

stopLossPrice = avgEntryPrice * (1 - stopLossPercentage/100)

It places a combined exit:
strategy.exit("TP / SL", from_entry="Long Entry", limit=takeProfitPrice, stop=stopLossPrice)

With pyramiding=3, multiple fills can stack into one net long position. Using the same from_entry id ties the TP/SL to that logical entry group (not per-layer). That’s OK in TradingView (it will manage TP/SL for the position), but you don’t get per-layer TP/SL.

6) Visuals & alerts

It plots a green triangle under the bar when the long signal condition occurs.

It exposes an alert you can hook to: “Покупка при достижении уровня”.

A quick example timeline

RSI drops below rsiOS → inOversold = true (armed).

RSI rises back above rsiOS and reaches rsiEntryLevel → signal.

Strategy places a limit buy a bit below current price.
4a) If price dips to fill within cancelAfterBars, you’re long. TP/SL are set as fixed % from avg entry.
4b) If price doesn’t dip enough, after N bars the limit is canceled. The system won’t re-try until RSI becomes oversold again.

Key quirks to be aware of

Risk sizing isn’t PnL-aware. accountEquity is frozen at start, and compoundedEquity grows on every signal, not on wins. So size doesn’t reflect real equity changes unless you rewrite it to use strategy.equity each time and (optionally) size by stop distance.

Disarm on signal, not on fill. If a limit order goes stale and is canceled, the system won’t try again unless RSI re-enters oversold. That’s intentional but can reduce fills.

Single TP/SL id for pyramiding. Works, but you can’t manage each add-on with different exits.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.