Работа завершена
Техническое задание
Trading Idea
It is a simple daily break-out system, based on how far price has been moving away from the opening price each day.
This EA is to be based on three moving averages to develop a trade signal. The moving averages operate on daily OHLC values. A value is calculated from the moving averages that establishes a buy limit price and sell limit price for the day. The buy limit is above the opening price and the sell limit is below the opening price. These limit values are not sent to the broker as limit orders, but held by the EA until the buy/sell trigger occurs then market orders sent to broker.
The buy and sell triggers will come from the closing price of the last bar. The timeframe of the bar is dependent on the chart that the EA is attached to.If either limit is triggered during that day and a position is opened, a trailing stop will be used to close the position. The trailing stop will always move based on close of 1 minute bars. If the position is not closed by the trailing stop, the EA is to close the order at the end of the day. It is possible that both buy and sell limits will be hit in a day, but the stop loss will be between them so there will only be one open position at a time.
The Indicators
- MA_Open is the moving average of the daily open prices
- MA_High is the moving average of the daily high prices
- MA_Low is the moving average of the daily low prices
- Avg_Up = MA_High - MA_Open
- Avg_Down = MA_Open - MA_Low
- Excursion = Max(Avg_Up, Avg_Down)
- Threshold = Excursion*Multiplier
- Buy_Limit = the opening price for the current day plus the value of Threshold
- For example, if the opening prices for today is 1.20000 and Threshold = 0.00500 then Buy_Limit = 1.20500.
- Sell_Limit = the opening price for the current day minus the value of Threshold
- For example, if the opening prices for today is 1.20000 and Threshold = 0.00500 then Sell_Limit = 1.19500.
- The Moving Averages are to share the following input variables so that each moving average has the same parameter values exept of the price they operate on (open, high, low).
- MA_Period : Default = 10
- MA_Shift : Default = 0
- MA_Method : Default = Simple
- Multiplier is to be set by user : Default = 1.0
Rules to Open a New Position
- Check for pending orders and open positions. Only place an order to open when no pending orders or open positions exist. There is to be at most one open position at any time.
- Place a buy-to-open marked order when the closing price of the most recent 1-minute bar is greater than Buy_Limit.
- Place a sell-to-open market order when the closing price of the most recent 1 minute bar is less than Sell_Limit.
Rules to Close a Position
- Use a trailing stop loss at a Threshold*Tstop_Modifier
-
Default value for input variable Tstop_Modifier = 1.0
-
For example, if a buy order was executed at 1.20500, Threshold is 0.00500, and Tstop_Modifier = 0.5 then the initial value of the trailing stop is to be set at 1.20500 – (0.00500*0.5) = 1.20250
-
- The Trailing Stop is to be limited by input variable Max_SL : Default value = 50. Units are pips. Meaning that the stop loss price will always be 50 pips (the value of Max_SL) or less from the opening trade execution price.
- The trailing stop is to be moved based on the closing price of one-minute bars.
- Stop Loss cannot be moved towards the loss direction, i.e. the Stop Loss value cannot be increased.
- Close the open position using a market order when the close price of the most recent 1 minute bar crosses the stop loss.
- Before sending an order to close a position, check the following
- There is an open position
- The type of position (long or short)
- That the order type is the correct type to close close open position
-
Only send a Market Sell order when there is an open long position and
-
Only send a Market Buy order when there is an open short position
Other Inputs
-
MagicNumber : Default = 88991
-
Lot_Sizing : Menu of Fixed or Proportional. Default to be Fixed
-
Fixed_Lots : Default = 0.1. This is the number of lots to be bought and sold
-
Proportional_Pct : Default = 2.0. This is the percent of the account balance to be used as initial margin for the position. Lots are to be calculated from this value, the account balance and the margin required.
Graphical
The following will show on the chart and in the visualization of back tests.
-
Green solid thin lines at Buy_Limit and Sell_Limit prices for the day
-
Red solid thin lines at the trailing stop
-
Green up arrow where buy orders are placed
-
Red Down arrow where sell orders are placed
-
Green dashed thin lines between the buy-to-open order and the sell-to-close order
-
Red dashed thin lines between the sell-to-open order and the buy-to-close order
Error Handling
I don’t know. Apply best practices.
Logging
The EA is to log the following events and values
-
Order execution time and price
-
Reason for closing position – “Closed on trailing stop”or “Closed on end of day”.
-
If Threshold < Threshold_Min
-
Any errors reported by the trading console or the broker
Other
If possible please keep the onTick actions to a minimum for faster backtesting. I tried to make it so that everything is done on 1 minute or daily values.
Thank you and please me know if you have questions.