OPEN-SOURCE SCRIPT

Tailwind.(BTC)

153
Imagine the price of Bitcoin is like a person climbing a staircase.

The Steps (Grid): Instead of watching every single price movement, the strategy divides the market into fixed steps. In your configuration, each step measures **3,000 points**. (Examples: 60,000, 63,000, 66,000...).

The Signal: We buy only when the price climbs a full step decisively.

The "Expensive Price" Filter: If the price jumps the step but lands too far away (the candle closes too high), we do not buy. It is like trying to board a train that has already started moving too fast; the risk is too high.

Rigid Exits: The Take Profit (TP) and Stop Loss (SL) are calculated from the edge of the step, not from the specific price where you managed to buy. This preserves the geometric structure of the market.

The Code Logic (Step-by-Step)

A. The Math of the Grid (`math.floor`)

pinescript
level_base = math.floor(close / step_size) * step_size


This is the most important line.

What does it do? It rounds the price down to the nearest multiple of 3,000.

Example: If BTC is at 64,500 and the step size is 3,000:

1. Divide: $64,500 / 3,000 = 21.5$

2. `math.floor` (Floor): Removes the decimals $\rightarrow$ remains $21$.

3. Multiply: $21 * 3,000 = 63,000$.

Result: The code knows that the current "floor" is **63,000**, regardless of whether the price is at 63,001 or 65,999.

B. The Strict Breakout (`strict_cross`)

pinescript
strict_cross = (open < level_base) and (close > level_base)

Most strategies only check if `close > level`. We do things slightly differently:

`open < level_base`: Requires the candle to have "born" *below* the line (e.g., opened at 62,900).

`close > level_base`: Requires the candle to have *finished* above the line (e.g., closed at 63,200).

Why? This avoids entering on gaps (price jumps where the market opens already very high) and confirms that there was real buying power crossing the line.

C. The "Expensive Price" Filter (`max_dist_pct`)

pinescript
limit_price_entry = level_base + (step_size * (max_dist_pct / 100.0))
price_is_valid = close <= limit_price_entry


Here you apply the percentage rule:

-If the level is 63,000 and the next is 66,000 (a difference of 3,000).

-If `max_dist_pct` is **60%**, the limit is $63,000 + (60\% \text{ of } 3,000) = 64,800$.

-If the breakout candle closes at **65,000**, the variable `price_is_valid` will be **false** and it will not enter the trade. This avoids buying at the ceiling.


D. TP and SL Calculation (Anchored to the Level)

pinescript
take_profit = level_base + (step_size * tp_mult)
stop_loss = level_base - (step_size * sl_mult)

Note that we use `level_base` and not `close`.

-If you entered because the price broke 63,000, your SL is calculated starting from 63,000.

-If your SL is 1.0x, your stop will be exactly at 60,000.

This is crucial: If you bought "expensive" (e.g., at 63,500), your real stop is wider (3,500 points) than if you bought cheap (63,100). Because you filter out expensive entries, you protect your Risk/Reward ratio.

E. Visual Management (`var line`)

The code uses `var` variables to remember the TP and SL lines and the `line.set_x2` function to stretch them to the right while the operation remains open, providing that visual reference on the chart until the trade ends.


Workflow Summary

Strategy Parameters:

Total Capital: $20,000
We will use 10% of total capital per trade.
Commissions: 0.1% per trade.
TP: 1.4
SL: 1
Step Size (Grid): 3,000
We use the 200 EMA as a trend filter.

Feel free to experiment with the parameters to your liking. Cheers.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.