OPEN-SOURCE SCRIPT

Multi-Step FlexiMA - Strategy [presentTrading]

It's time to come back! hope I can not to be busy for a while.

█ Introduction and How It Is Different

The FlexiMA Variance Tracker is a unique trading strategy that calculates a series of deviations between the price (or another indicator source) and a variable-length moving average (MA). Unlike traditional strategies that use fixed-length moving averages, the length of the MA in this system varies within a defined range. The length changes dynamically based on a starting factor and an increment factor, creating a more adaptive approach to market conditions.

This strategy integrates Multi-Step Take Profit (TP) levels, allowing for partial exits at predefined price increments. It enables traders to secure profits at different stages of a trend, making it ideal for volatile markets where taking full profits at once might lead to missed opportunities if the trend continues.

BTCUSD 6hr Performance
สแนปชอต

█ Strategy, How It Works: Detailed Explanation

🔶 FlexiMA Concept

The FlexiMA (Flexible Moving Average) is at the heart of this strategy. Unlike traditional MA-based strategies where the MA length is fixed (e.g., a 50-period SMA), the FlexiMA varies its length with each iteration. This is done using a **starting factor** and an **increment factor**.

The formula for the moving average length at each iteration \(i\) is:
`MA_length_i = indicator_length * (starting_factor + i * increment_factor)`
Where:
- `indicator_length` is the user-defined base length.
- `starting_factor` is the initial multiplier of the base length.
- `increment_factor` increases the multiplier in each iteration.

Each iteration applies a **simple moving average** (SMA) to the chosen **indicator source** (e.g., HLC3) with a different length based on the above formula. The deviation between the current price and the moving average is then calculated as follows:

`deviation_i = price_current - MA_i`
These deviations are normalized using one of the following methods:

- **Max-Min normalization**:
`normalized_i = (deviation_i - min(deviations)) / range(deviations)`

- **Absolute Sum normalization**:
`normalized_i = deviation_i / sum(|deviation_i|)`

The **median** and **standard deviation (stdev)** of the normalized deviations are then calculated as follows:
`median = median(normalized deviations)`

For the standard deviation:
`stdev = sqrt((1/(N-1)) * sum((normalized_i - mean)^2))`

These values are plotted to provide a clear indication of how the price is deviating from its variable-length moving averages.

For more detail:
https://www.tradingview.com/script/R9qM6XrY-FlexiMA-Variance-Tracker-Strategy-presentTrading/

🔶 Multi-Step Take Profit

This strategy uses a multi-step take profit system, allowing for exits at different stages of a trade based on the percentage of price movement. Three take-profit levels are defined:
- Take Profit Level 1 (TP1): A small, quick profit level (e.g., 2%).
- Take Profit Level 2 (TP2): A medium-level profit target (e.g., 8%).
- Take Profit Level 3 (TP3): A larger, more ambitious target (e.g., 18%).

At each level, a corresponding percentage of the trade is exited:
- TP Percent 1: E.g., 30% of the position.
- TP Percent 2: E.g., 20% of the position.
- TP Percent 3: E.g., 15% of the position.

This approach ensures that profits are locked in progressively, reducing the risk of market reversals wiping out potential gains.

Local
สแนปชอต

🔶 Trade Entry and Exit Conditions

The entry and exit signals are determined by the interaction between the **SuperTrend Polyfactor Oscillator** and the **median** value of the normalized deviations:
- Long entry: The SuperTrend turns bearish, and the median value of the deviations is positive.
- Short entry: The SuperTrend turns bullish, and the median value is negative.

Similarly, trades are exited when the SuperTrend flips direction.

* The SuperTrend Toolkit is made by EliCobra

█ Trade Direction

The strategy allows users to specify the desired trade direction:
- Long: Only long positions will be taken.
- Short: Only short positions will be taken.
- Both: Both long and short positions are allowed based on the conditions.

This flexibility allows the strategy to adapt to different market conditions and trading styles, whether you're looking to buy low and sell high, or sell high and buy low.

█ Usage

This strategy can be applied across various asset classes, including stocks, cryptocurrencies, and forex. The primary use case is to take advantage of market volatility by using a flexible moving average and multiple take-profit levels to capture profits incrementally as the market moves in your favor.

How to Use:
1. Configure the Inputs: Start by adjusting the **Indicator Length**, **Starting Factor**, and **Increment Factor** to suit your chosen asset. The defaults work well for most markets, but fine-tuning them can improve performance.
2. Set the Take Profit Levels: Adjust the three **TP levels** and their corresponding **percentages** based on your risk tolerance and the expected volatility of the market.
3. Monitor the Strategy: The SuperTrend and the FlexiMA variance tracker will provide entry and exit signals, automatically managing the positions and taking profits at the pre-set levels.

█ Default Settings

The default settings for the strategy are configured to provide a balanced approach that works across different market conditions:

Indicator Length (10):
This controls the base length for the moving average. A lower length makes the moving average more responsive to price changes, while a higher length smooths out fluctuations, making the strategy less sensitive to short-term price movements.

Starting Factor (1.0):
This determines the initial multiplier applied to the moving average length. A higher starting factor will increase the average length, making it slower to react to price changes.

Increment Factor (1.0):
This increases the moving average length in each iteration. A larger increment factor creates a wider range of moving average lengths, allowing the strategy to track both short-term and long-term trends simultaneously.

Normalization Method ('None'):
Three methods of normalization can be applied to the deviations:
- None: No normalization applied, using raw deviations.
- Max-Min: Normalizes based on the range between the maximum and minimum deviations.
- Absolute Sum: Normalizes based on the total sum of absolute deviations.

Take Profit Levels:
- TP1 (2%): A quick exit to capture small price movements.
- TP2 (8%): A medium-term profit target for stronger trends.
- TP3 (18%): A long-term target for strong price moves.

Take Profit Percentages:
- TP Percent 1 (30%): Exits 30% of the position at TP1.
- TP Percent 2 (20%): Exits 20% of the position at TP2.
- TP Percent 3 (15%): Exits 15% of the position at TP3.

Effect of Variables on Performance:
- Short Indicator Lengths: More responsive to price changes but prone to false signals.
- Higher Starting Factor: Slows down the response, useful for longer-term trend following.
- Higher Increment Factor: Widens the variability in moving average lengths, making the strategy adapt to both short-term and long-term price trends.
- Aggressive Take Profit Levels: Allows for quick profit-taking in volatile markets but may exit positions prematurely in strong trends.

The default configuration offers a moderate balance between short-term responsiveness and long-term trend capturing, suitable for most traders. However, users can adjust these variables to optimize performance based on market conditions and personal preferences.
histogramnormalizedpresenttradingSimple Moving Average (SMA)strategysupertrendTrend Analysis

สคริปต์โอเพนซอร์ซ

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถเข้าใจและตรวจสอบได้ ต้องขอบคุณผู้เขียน! ที่ให้คุณใช้ได้ฟรี แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?


Watch patiently/ then trade
และใน:

คำจำกัดสิทธิ์ความรับผิดชอบ