declarative

Divergent Bar Strategy [declarative] v0.2

Divergent Bar Strategy v0.2

Divergent Bar is a price action that signals potential trend reversal.

This strategy uses repeating divergent bars during a bearish local trend as signals to issue multiple averaging long orders in the direction of potentially emerging bullish trend. As the local trend reverses from bearish to bullish, position could become profitable and is closed by an opposite signal.

As an averaging strategy, this strategy can accumulate substantial order sizes, so this implementation uses a stop loss which is adjusted dynamically according to the current position size to protect deposit.

What you see on a chart:

Greenish background under the divergent bars. This designates detected divergent signals.
Alligator Fast Period and Required Bar Amplitude affect the amount of divergent bars detected.

Red green and blue alligator lines display the alligator indicator used as part of divergent bar detection. In general, you don’t need to see it, you can color the lines transparent in the Style section.

Green triangles designate placed long orders. Required Divergents for Long Cummulative Signal parameter affects those signals.

Parameters and default values:

Alligator Fast Period, default 9.
Length of the alligator fast EMA. The alligator indicator used to filter a divergent bar. A bar is considered divergent only if it is located below the alligator for bollish signal and above for a bearish. In general you can leave default value, as the period 9 corresponds to a reasonable value for an alligator, used for bars on a specific timeframe.

Required Bar Amplitude (%), default 0.4.
This is an important parameter that needs to be adjusted for different timeframes. It specifies minimum size of candle shadow used to detect divergent bars. Higher values produce more false signals, lower values tend produce only strong signals. Be careful, because it also filters out bearish signals used to close the trades, so you need a bearish signal to appear. If you filter small signals you risk ending up with a trade that does not close in profit. You need to find a balance here.

Required Divergents for Long Cummulative Signal, default 3.
Divergent bar does not necessarily signal an immidiate trend reversal. Sometimes several signals need to accumulate. This parameter specifies the count at which the orders start. If you increase this count, orders are only placed after the count is achieved, so your position has bigger chance to go in profit sooner. It does not necessarily mean the most profitable position.

Required Divergents for Short Cummulative Signal, default 1.
It is the same as for long positions, but the opposite.
These signals are used to close the trades. Higher value can mean that a take profit signal would happen at potentially higher price, but be aware that it could also lead to missign oportunity to take profit if there is not enough signals in the sequence.

Long Order Size (%), default 5.0.
Percentage of deposit used for the first order in sequence. Actual order size is comuted dynamically, it depends on Reinvest and parameter. In case Reinvest is turned on, it is computed relative to the current equity, that is initial deposit and netprofit combined.

Reinvest (only for backtesting), default - turned off.
Affects Long Order Size. If turned off, order size is computed according to percentage of total equity, that is initial deposit + net profit. In an automated strategy, you should not turn this parameter on, because this way you can’t control the position size, as it growith or reduces during the actual period of the study.

Martingale, default 1.0.
Affects dynamically computed order size. First order is calculated in percentage from deposit or equity, as specified by Long Order Size and Reinvest parameters.
Order will be scaled by the following values:
Martingale = 0.0 - only the first order would be placed.
Martingale = 1.0 - equal orders will be placed in sequence, with leads to unlimited position growth.
Martingale = 1.3 - orders will be scaled by 1.3, 1.69, 2.197 etc. That is geometric increasing sequnce, which leads to unlimited position growth.
Sequential long order size is multiplied by the martingale value.
Martingale < 1.0 - orders will be scaled by geometrically decreasing sequence, resulting in limited growth of position.

Long Stop Loss (%), default 10.0.
Dynamically adjusted stop loss, which is computed according to the current average position price, so the value potentially lost is proportional to the percentage specified.

Show Long Stop Loss Line, default is off.
Draws a graph line corresponding to the dynamic stop loss on the chart.

Bullish Line Visual Offset (% of price), default -10
For convenience, the count of sequential orders is drawn as a green line over a black EMA on the same chart, offset from an EMA. This is just a visual aid to visualize the strength of long signal as divergent bars accumulate in sequence. EMA is just used so the visual cue is always displayed somewhere close the price graph.
受保護腳本
該腳本是閉源發佈的,您可以自由使用。您可以把它加入到常用以在圖表上使用它。您無法查看或修改其原始碼。
免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?