OPEN-SOURCE SCRIPT

EMA SHIFT & PARALLEL [n_dot]

ETHUSDT.P

This strategy was developed for CRYPTO FUTURES, (the settings for ETHUSDT.P) . I aimed for the strategy to function in a live environment, so I focused on making its operation realistic:

  • When determining the position, only 80% (adjustable) of the available cash is invested to reduce the risk of position liquidation.
  • I account for a 0.05% commission, typical on the futures market, for each entry and exit.


Concept:

I modified a simple, well-known method: the crossover of two exponential moving averages (FAST, SLOW) generates the entry and exit signals.

I enhanced the base idea as follows:

  • For the fast EMA, I incorporated a multiplier (offset) to filter out market noise and focus only on strong signals.
  • I use different EMAs for long and short entry points; both have their own FAST and SLOW EMAs and their own offset. For longs, the FAST EMA is adjusted downward (<1), while for shorts, it is adjusted upward (>1). Consequently, the signal is generated when the modified FAST EMA crosses the SLOW EMA.


Risk Management:
The position includes the following components:
  • Separate stop-losses for long and short positions.
  • Separate trailers for long and short positions.
  • The strategy operates so that the entry point is determined by the EMA crossover, while the exit is governed only by the Stop Loss or Trailer. Optionally, it can be set to close the position at the EMA recrossing ("Close at Signal").


Trailer Operation:
  • An entry percentage and offset are defined. The trailer activates when the price surpasses the entry price, calculated automatically by the system.
  • The trailer closes the position when the price drops by the offset percentage from the highest reached price.


Example for trailer:
  • Purchase Price = 100
  • Trailer Enter = 5% → Activation Price = 105 (triggers trailer if market price crosses it).
  • Trailer Offset = 2%
  • If the price rises to 110, the exit price becomes 107.8.
  • If the price goes to 120, the exit price becomes 117.6.
  • If the price falls below 117.6, the trailer closes the position.


Settings:

  • Source: Determines the market price reference.
  • End Close: Closes positions at the end of the simulation to avoid "shadow positions" and provide an objective result.
  • Lot proportional to free cash (%): Only a portion of free cash is invested to meet margin requirements.
  • Plot Short, Plot Long: Simplifies displayed information by toggling indicator lines on/off.
  • Long Position (toggleable):
  • EMA Fast ws: Window size for FAST EMA.
  • EMA Slow ws: Window size for SLOW EMA.
  • EMA Fast down shift: Adjustment factor for FAST EMA.
  • Stop Loss long (%): Percent drop to close the position.
  • Trailer enter (%): Percent above the purchase price to activate the trailer.
  • Trailer offset (%): Percent drop to close the position.
  • Short Position (toggleable):
  • EMA Fast ws: Window size for FAST EMA.
  • EMA Slow ws: Window size for SLOW EMA.
  • EMA Fast up shift: Adjustment factor for FAST EMA.
  • Stop Loss short (%): Percent rise to close the position.
  • Trailer enter (%): Percent below the purchase price to activate the trailer.
  • Trailer offset (%): Percent rise to close the position.


Operational Framework:

  • If in a long position and a short EMA crossover occurs, the strategy closes the long and opens a short (flip).
  • If in a short position and a long EMA crossover occurs, the strategy closes the short and opens a long (flip).


A position can close in three ways:
  • Stop Loss
  • Trailer
  • Signal Recrossing

If none are active, the position remains open until the end of the simulation.

Observations:

  • Shifts significantly deviating from 1 increase overfitting risk. Recommended ranges: 0.96–0.99 (long) and 1.01–1.05 (short).
  • The strategy's advantage lies in risk management, crucial in leveraged futures markets. It operates with relatively low DrawDown.


Recommendations:

  • Bullish Market: Higher entry threshold (e.g., 6%) and larger offset (e.g., 3%).
  • Volatile/Sideways Market: Tighter parameters (e.g., 3%, 1%).
  • The method is stable, and minor parameter adjustments do not significantly impact results, helping assess overfitting: if small changes lead to drastic differences, the strategy is over-optimized.
  • EMA Settings: Adjust FAST and SLOW EMAs based on the asset's volatility and cyclicality.
  • On the crypto market, especially in the Futures market, short time periods (1–15 minutes) often show significant noise, making patterns/repetitions hard to identify. I recommend setting the interval to at least 1 hour.


I hope this contributes to your success!
CyclesExponential Moving Average (EMA)Trend Analysis

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

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

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

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