Andrew Pitchfork EA
Logic:
- Trend Following with Pitchfork:
- Uses Andrew’s Pitchfork to identify trends and potential entry points.
- The pitchfork tool helps to visualize support and resistance levels and to determine the overall market trend.
- Indicators and Conditions:
- Utilizes Moving Averages (FastMA and SlowMA), Momentum, and MACD to confirm entry and exit signals.
- Employs Bollinger Bands to identify price volatility and potential breakouts.
- Order Management:
- Opens buy or sell orders based on trend direction and momentum confirmation.
- Moves stop-loss to break-even after a certain profit is achieved to secure trades.
- Implements a trailing stop to lock in profits as the market moves in favor of the trade.
- Risk Management:
- Calculates optimal lot size based on account equity and risk parameters.
- Ensures that trades are only opened when sufficient margin is available.
- Uses a magic number to manage and identify trades specific to this EA.
Detailed EA Explanation
- Initialization and Deinitialization:
- Initializes key variables and sets up the pitchfork tool on the chart.
- Cleans up when the EA is deinitialized.
- OnTick Function:
- Main function where all trading decisions and order management occur.
- Continuously checks for new bars and updates the pitchfork.
- Evaluates the market conditions using Moving Averages, Momentum, MACD, and Bollinger Bands.
- Decides whether to open new buy or sell orders based on the trend direction and momentum confirmation.
- Moves stop-loss to break-even and adjusts trailing stops as needed.
- stop Function:
- Evaluates current open positions and decides whether to exit based on MACD signals and Bollinger Bands.
- Manages trailing stops for open positions.
- MOVETOBREAKEVEN Function:
- Moves the stop-loss to break-even when the price reaches a predefined profit level.
- LotsOptimized Function:
- Calculates the optimal lot size for new trades based on account equity and risk parameters.
- Order Management Functions:
- IfOrderDoesNotExistBuy, getOpenOrders, OrderModifyCheck, and CheckStopLoss_Takeprofit manage the opening, closing, and modification of trades.
- exitbuys and exitsells close open buy and sell positions, respectively.
- Create and drow Functions:
- Create and update the pitchfork tool on the chart to visualize support and resistance levels.
This EA implements a trend-following strategy using Andrew’s Pitchfork along with Moving Averages, Momentum, MACD, and Bollinger Bands to identify and execute trades in the direction of the trend, while employing robust risk management techniques to optimize trading performance and protect account equity.