AIS1 Trading Robot: Instruction Issue date: 14.02.2009 Issue number: 1 Content 1. Introduction 2. Basic information 3. Trading strategy description 4. Trading strategy adjustment 5. Risk management adjustment 6. Trailing-stop stepping 7. Conclusion 1. Introduction 1.1. AIS1 Trading Robot: Instruction refers to original code http://codebase.mql4.com/5260. 1.2. AIS1 Trading Robot is intended for EURUSD trading symbol. 2. Basic information 2.1. The program contents 10 data elements with predefined values that are intended for changes: 2.1.1. 5 constants, lines 16-21; 2.1.2. 5 variables, lines 28-32. 2.2. Constant "acs.Symbol" defines only permitted trading symbol. 2.3. In case of necessity it is possible to assign another value, for example, "EURUSDm". 2.4. Constant "aci.OrderID" defines "magic number" for "OrderSend ()" function, see lines 219-220. 2.5. In case of necessity it is possible to assign another value, for example, "1". 2.6. Constant "acd.TrailStepping" defines step of trailing-stop in spreads, see line 118. 2.7. In case of necessity it is possible to assign another value, for example, "2". 2.8. Constants "aci.Index.1" and "aci.Index.2" define working timeframes, see lines 98 and 99. 2.9. Value "aci.Index.1 = 7" selects daily timeframe D1 in array "aci.Timeframe", see line 22. 2.10. Value "aci.Index.2 = 6" selects 4-hour timeframe H4 in array "aci.Timeframe", see line 22. 2.11. Built-in trading strategy "A System: EURUSD Daily Metrics" uses only D1 and H4 timeframes. 2.12. Constants "acs.Symbol", "aci.Index.1" and "aci.Index.2" are key elements of the trading strategy. 2.13. The robot's behaviour with another values of those constants requires additional study. 2.14. Variable "aed.AccountReserve" means deposit reserve for possible losses. 2.15. Deposit reserve size determines limit of deposit relative drawdon, see line 50. 2.16. Deposit reserve defends capital value from market risk. 2.17. Automatic deposit reserve control is in lines 77-78. 2.18. Variable "aed.OrderReserve" means order reserve for possible losses. 2.19. Variable "aed.OrderReserve" limits market risk for each trade operation, see lines 192-200. 2.20. Order reserve defends deposit reserve from market risk. 2.21. Usage and size setting rules of the reserves are explained in the following example: " < Example. Account manager is talking to investor > 1. AM. There are two trading systems A1 and A2. There are descriptions and statements of those systems. 2. I. Studied. I select А1. 3. AM. Select now: 1) deposit reserve size; 2) order reserve size. 4. I. More information, please. 5. AM. 5.1. Size of reserve is measured in percents of deposit value. 5.2. Let your initial deposit is $100000. 5.3. Let you set deposit reserve size to 20%. 5.4. It means that your capital is equal to $80000, deposit reserve is equal to $20000. 5.5. Let trading position has opened. 5.6. Let your deposit has grown to $110000. 5.7. In this case your capital is equal to $88000, deposit reserve is equal to $22000. 5.8. Let your deposit has lowered to $105000. 5.9. In this case your capital is equal to $88000, deposit reserve is equal to $17000. 5.10. Let your deposit has grown to $200000. 5.11. In this case your capital is equal to $160000, deposit reserve is equal to $40000. 5.12. Let then your deposit has only lowered. 5.13. At deposit value $180000 your capital is equal to $160000, deposit reserve is equal to $20000. 5.14. At deposit value $170000 your capital is equal to $160000, deposit reserve is equal to $10000. 5.15. At deposit value $160000 your capital is equal to $160000, deposit reserve is exhausted, system stop. 5.16. If trading is stopped by your command then deposit reserve will be restored. 5.17. Deposit value at the trading stop is your capital. 5.18. Let trading was stopped at the deposit value equal to $170000, then your capital is equal to $170000. 5.19. Thus deposit reserve defends your capital value from possible losses. 5.20. All our systems have automatic reserve control feature. 6. I. I see. 7. AM. 7.1. Order reserve defends deposit reserve in above explained manner. 7.2. Expected deposit reserve life time depends on order reserve size. 7.3. Let order reserve size will be equal to 10% and deposit reserve size will be equal to 20%. 7.4. Then system A1 can survive in approximately 2 losses consequence. 7.5. A1 statements demonstrate that longer consequences arise approximately 4 times for one year of trading. 7.6. Let order reserve size will be equal to 5% and deposit reserve size will be equal to 20%. 7.7. Then system A1 can survive in approximately 4 losses consequence. 7.8. A1 statements demonstrate that longer consequences arise approximately 1 times for one year of trading. 7.9. On other hand, order reserve determines orders size, that is affecting to system profitability. 7.10. Order size calculation is in lines 192-216 of system A1 code. 8. I. I see. Let deposit reserve size will be equal to 20% and order reserve size will be equal to 4%. 9. AM. For that order reserve size required deposit value is $50000 or more. 10. I. Server *******, login *******, password *******, deposit $100000, I have accepted account management agreement. 11. AM. Your read only password is А1234. " 2.22. Only one trading position can be opened at the same time. 2.23. Variables "aed.TakeFactor", "aed.StopFactor" and "aed.TrailFactor" are the trading strategy presets. 2.24. Usage of those variables is explained in following chapters. 3. Trading strategy description 3.1. Trading strategy "A System: EURUSD Daily Metrics" consists of two parts: 3.1.1. position opening block, lines 161-181; 3.1.2. position managenent block, lines строки 132-159. 3.2. Position opening block uses 14 variables: 3.2.1. input - 9 variables: 3.2.1.1. "ald.QuoteAsk" - Ask price, line 84; 3.2.1.2. "ald.QuoteBid" - Bid price, line 85; 3.2.1.3. "ald.Low.1" - Low price of daily timeframe number 1, line 101; 3.2.1.4. "ald.High.1" - High price of daily timeframe number 1, line 102; 3.2.1.5. "ald.Close.1" - Close price of daily timeframe number 1, line 103; 3.2.1.6. "ald.Average.1" - average price of daily timeframe number 1, line 109; 3.2.1.7. "ald.Range.1" - daily price range of daily timeframe number 1, line 111; 3.2.1.8. "ald.QuoteTake" - distance from current price to TakeProfit price level, line 114; 3.2.1.9. "ald.QuoteStop" - distance from current price to StopLoss price level, line 115; 3.2.2. output - 5 variables: 3.2.2.1. "ali.Command" - operation type; 3.2.2.2. "ald.Price" - operation price; 3.2.2.3. "ald.Stop" - StopLoss price level; 3.2.2.4. "ald.Take" - TakeProfit price level; 3.2.2.5. "ald.Risk" - accepted market risk size in price units. 3.3. Buy rules, lines 165-166: 3.3.1. Close price "ald.Close.1" higher than average price "ald.Average.1"; 3.3.2. Ask price "ald.QuoteAsk" higher than High price "ald.High.1"; 3.3.3. if both of the conditions are true then output variables will be calculated, see lines 167-171. 3.4. Sell rules, lines 173-174: 3.4.1. Close price "ald.Close.1" lower than average price "ald.Average.1"; 3.4.2. Bid price "ald.QuoteBid" lower than Low price "ald.Low.1"; 3.4.3. if both of the conditions are true then output variables will be calculated, see lines 175-179. 3.5. Position managenent block uses 11 variables: 3.5.1. input - 10 variables: 3.5.1.1. "OrderType ()" - ordet type for the currently managed position; 3.5.1.2. "OrderProfit ()" - net profit value for the currently managed position; 3.5.1.3. "OrderTakeProfit ()" - TakeProfit price level for the currently managed position; 3.5.1.4. "OrderStopLoss ()" - StopLoss price level for the currently managed position; 3.2.1.5. "ald.QuoteAsk" - Ask price, line 84; 3.2.1.6. "ald.QuoteBid" - Bid price, line 85; 3.5.1.7. "ald.QuoteStops" - minimal allowed distance for the stop levels, line 88; 3.2.1.8. "ald.Range.2" - price range of 4-hour timeframe H4 number 1, line 112; 3.2.1.9. "ald.QuoteTrail" - distance from current price to new StopLoss price level, line 116; 3.5.1.10. "ald.TrailStep" - minimal allowed step of trailing-stop, line 118; 3.5.2. output - 1 variable: 3.5.2.1. "ald.Stop" - new StopLoss price level. 3.6. Trailing-stop rules: 3.6.1. for Buy order are in lines 139-143; 3.6.2. for Sell order are in lines 139-143. 3.7. Attempt to trail is made in case of "ald.Stop" value assignment, see lines 153-157. 4. Trading strategy adjustment 4.1. Trading strategy adjustment consist in selection of "best" value set of three following variables: 4.1.1. "aed.TakeFactor" - TakeProfit distance calculation coefficient, see lines 30 and 114; 4.1.2. "aed.StopFactor" - StopLoss distance calculation coefficient, see lines 31 and 115; 4.1.3. "aed.TrailFactor" - Trailing Stop distance calculation coefficient, see lines 32 and 116. 4.2. Sense of notion "best" depends on adjustment goals and appraisement measure system. 4.3. The following trading strategy adjustment order is one of possible ones. 4.4. Trading strategy adjustment order: 4.4.1. set "Initial deposit = 100000 USD" in dialog box "Expert Properties/Testing" of strategy tester; 4.4.2. increase deposit reserve size by "double aed.AccountReserve = 0.99 ;" in line 28; 4.4.3. turn off trailing stop by "double aed.TrailFactor = 0.0 ;" in line 32; 4.4.4. declare variables "aed.TakeFactor" and "aed.StopFactor" as "extern": 4.4.4.1. "extern double aed.TakeFactor = 0.8 ;" in line 30, 4.4.4.2. "extern double aed.StopFactor = 1.0 ;" in line 31; 4.4.5. compile code; 4.4.6. run optimization of "aed.TakeFactor" and "aed.StopFactor" values simultaneously; 4.4.7. assign selected "best" values to "aed.TakeFactor" and "aed.StopFactor" variables; 4.4.8. delete "extern" declaration of "aed.TakeFactor" and "aed.StopFactor" variables: 4.4.8.1. "double aed.TakeFactor = 0.8 ;" in line 30, 4.4.8.2. "double aed.StopFactor = 1.0 ;" in line 31; 4.4.8. declare variable "aed.TrailFactor" as "extern" in line 32 - "extern double aed.TrailFactor = 0.0 ;"; 4.4.9. compile code; 4.4.10. run optimization of "aed.TrailFactor" value; 4.4.11. assign selected "best" value to "aed.TrailFactor" variable; 4.4.12. delete "extern" declaration of "aed.TrailFactor" variable "double aed.TrailFactor = 5.0 ;"; 4.4.13. restore previous deposit reserve size "double aed.AccountReserve = 0.20 ;" in line 28; 4.4.14. compile code. 4.5. Trading strategy adjustment is completed. 5. Risk management adjustment 5.1. Risk management adjustment consist in setting of two following variables values: 5.1.1. "aed.AccountReserve" - deposit reserve size, line 28; 5.1.2. "aed.OrderReserve" - order reserve size, line 29; 5.2. Deposit reserve and order reserve size setting rules are explained in p. 2.21. 6. Trailing-stop stepping 6.1. To optimize trailing-stop stepping declare in line 18 "extern double acd.TrailStepping = 1.0 ;". 7. Conclusion 7.1. Values "aed.TakeFactor = 0.8" and "aed.StopFactor = 1.0" are excellent settings for EURUSD trading symbol. 7.2. Behaviour of variable "aed.TrailFactor" and parameter "acd.TrailStepping" require further study.