Home System Trading Post

Mastering the Smart Trend Follower EA for MetaTrader 5

Attachments
53022.zip (3.5 KB, Download 0 times)

Welcome, fellow traders! Today, we're diving into the Smart Trend Follower, an expert advisor (EA) designed for MetaTrader 5 that helps you ride the market waves with ease. Whether you're a seasoned pro or just getting your feet wet, understanding how this EA operates can give you a serious edge. Let’s break down its features and functions in a way that keeps you ahead of the game.

1. Enum Types

  • enumJnsSignal: This enum defines the types of signals used in the EA. You have two options here:
    • eTypeCrossMA: This one utilizes the signal from the crossing of two Moving Averages (MA).
    • eTypeTrend: This follows the trend using both Moving Averages and the Stochastic indicator.
  • enumOrderType: This enum specifies the type of order:
    • eBuy: Represents a Buy order.
    • eSell: Represents a Sell order.
    • eNone: Indicates no order is executed.

2. Input Parameters

  • inMagicNumber: A unique identifier for orders generated by this EA.
  • inLotSize: The initial lot size for each order.
  • inMultiply: The multiplier used in your lot size strategy.
  • inJarakLayer: The pip distance between trading positions in a grid or layering strategy.
  • inMAPeriodFast & inMAPeriodSlow: The periods set for fast and slow Moving Averages.
  • inSTOKPeriod, inSTODPeriod, inSTOSlowing: These are parameters for the Stochastic Oscillator.
  • inTakeProfit & inStopLoss: Settings for your Take Profit and Stop Loss levels.

3. Struct DataTrades

  • This structure stores essential data about open trading positions, including the total number of positions (ttlPos), average price of positions (hargaTA, hargaTB), and total volume (ttlLot).

4. OnInit() Function

  • This function kicks off the initialization process for the EA, validating input parameters (like ensuring the fast MA period is less than the slow MA period) and creating handles for the MA and Stochastic indicators.

5. OnTick() Function

  • The heartbeat of our EA, this function runs every time there's a price tick.
  • It calls GetSignal() to check for new trading signals. If a valid signal pops up, manageTrading() takes the reins to execute the trades.
  • Additionally, setTPSL() is triggered to ensure your Take Profit and Stop Loss settings are always up to date.

6. isNewCandle() Function

  • This function checks if a new candle has formed, which is crucial since our EA only looks for signals with new candle formations.

7. GetSignal() Function

  • This function identifies if a valid trading signal exists based on your chosen strategy:
    • For eTypeCrossMA, it checks for crossings between fast and slow Moving Averages.
    • For eTypeTrend, it looks for confirmations using both MA and Stochastic indicators.

8. manageTrading() Function

  • This function oversees trade execution.
  • When a valid signal is detected, the EA opens a position using the lot size calculated by getLotSize().
  • A grid or layering strategy is also applied to open additional positions based on the pip distance defined in inJarakLayer.

9. updateDataTrades() Function

  • This function keeps your data fresh, calculating the average price and total volume of all open positions.

10. openTrade() Function

  • This function opens a new trading position based on the generated signal and calculated lot size, executing orders with OrderSend().

11. setTPSL() Function

  • This function sets or updates the Take Profit and Stop Loss for each open position.

12. modifTPSL() Function

  • This function modifies the Take Profit and Stop Loss of existing positions if the new values differ from what's currently set.

13. validateLot() Function

  • This function ensures that the lot size used falls within the allowed minimum and maximum ranges in accordance with the minimum lot step (gLotStep).

14. getLotSize() Function

  • This function calculates the lot size based on the initial lot size and the number of currently open positions, factoring in the multiplier (inMultiply).

In summary, the Smart Trend Follower EA is designed to automatically capture market trends and manage trading positions using technical signals from Moving Averages and the Stochastic indicator. By understanding its functions, you can optimize your trading strategy and make more informed decisions. Happy trading!

Related Posts

Comments (0)