HedgeRock Intro HedgeRock combines 3 years of studying and experimenting with trading on MT4 with the latest ideas to allow hedging to reduce drawdown and the closing of losing orders. You can use it to look for patterns on a pair and of course trade them on a demo or real account. Over the years i have seen many market movements that suprised me. I also learned about some things that your wouldnt necessarily expect but all traders that persist come to learn. When you ask why does it work like this or what does that setting do , when the times comes you will realise almost every setting is eventually relevent. Dreamboat was the start. RocketTech evolved from Dreamboat and finally HedgeRock is the next expression. It works well. It may still have some bugs. You may be able to suggest a better way of doing it. Its has run for some time with no issues, although the latest updates of course have not been tested that long but the core works. To turn a feature off, often large values are used to save the number of settings. Setting a value that is unreachable will of course make it irrelevant. There is very little checking done so strange decimal vales and negative values can sometimes create interesting sometimes unpredictable results. HedgeRock starts out opening a hedge at the startlot value. On each tick, every order is evaluated according to the settings and delt with accordingly. As you run through the settings, you will see what each order is being evaluated against and how it will be delt with. The logic starts off simple but can evolve to be very complex if you want it to. When an order is closed in loss its losses are evaluated. When an order closes in profit its profits are evaluated. Things like spread, commission, slippage are considered. A measurement of the loss is processed and a Carrylot is calculated. The Carrylot is by default set to compensate for the loss in the next opened order. A total of the carrylots is kept as the Nextlot. New orders are opened using the Nextlot in a bid to compensate for the previous loss. The maximum next lot (Maxnextlot) can be managed as well as the Carrylot using the "Breaklots" and "Recovery" section. Many orders can be opened and are seperated by the distance of Points between each level "PointsBetweenLevels". The EA tries to keep this distance and only have open 1 order at a level at a time. It will open new orders at each level it reaches according to rules of the "MaxOrders" and "OrdersPerTimer" You can have orders opened against the trend by increasing the number of allowed in loss orders "OrdersPerTimer" per period "Timer" in hours . Please let me know if you have any questions. this is a first draft. Settings EvaluationDelay = 120 EvaluationDelay - 0 every tick, 5 -M5 , 60 - H1 make it 0 for live trading , this is only for backtesting to speed up the evaluation or to avoid sharp quick return ovements in live trade. WARNING!!!! money management is also excluded the EA is effectively off at this time. PRO - makes it stable - CON make sure your account can take the sudden spike. HedgeOver = 0 HedgeOver - hedge summary differences greater than .. The buys and sell orders are totalled to get an effective summary. of the summary is either negative or positive by this amount or more the next order in the opposite will be placed as a hedge to make the summary 0 unless HedgePlus is on then is will add the nextlot. The hedge is not limited by the maxnextlot. It will always try and make the summary 0 (or plus) HedgePlus = false HedgePlus - false - only hedge to the summary to make it 0 or if true - hedge plus nextlot .. increases drawdown when true but makes more profit ______LOTS______ Carrylots - added to the startlot. When you restart MT4 the Nextlot is cleared you can make a note of it and put it into the Carrylots and it will continue. You can also add to the next order at any time but by changing the Carrylots. Once it is added the Carrylot is reduced as normal but the setting itself does not change. it only reacts to changes , so if you chnage it from a value bigger than 0 to 0, the nextlot will clear aswell. >>>>StartLots - Minimum Lot to start opening orders. The lots size will increase to compensate for losses but will start here once all losses are accounted for. TakeProfit (Points) PointsBetweenLevels (Points) Buy StopLossLevel x PointsBetweenLevels = Stoploss points Sell StopLossLevel x PointsBetweenLevels = Stoploss points Once an order is in loss, at some point we will want to start trading in the opposite direction ReverseOnBuyLevel x PointsBetweenLevels = Direction Change points ReverseOnSellLevel x PointsBetweenLevels = Direction Change points Each time an order is closed in loss, if it is the highest losing buy or lowest losing sell it value is kept. if the price is reached again the levels around it can be avoided by skipping the levels around it. If it is a new session, you can set the level manually and it will onlt be changed internally when a new order is closed in loss. Setting Skiplevels to -1 the option is deactivated. LowestBadSell = 0 HighestBadBuy =1000000 SkipLevelsBeforeBad = -1 SkipLevelsAfterBad = -1 ______ORDER_TIMER______ We may want to limit the number of orders open at a time, perhaps only one direction aswell >>>>>MaxOrdersBuy - Maximum open Buys >>>>>MaxOrdersSell - Maximum open Sell A timer is used to decide how much history to consider when deciding how many orders to open in each direction. The timer is in hours. Once an order opentime passes the time it is no longer considered. Open and closed orders are counted. If a direction change is triggered buy ReverseOn level then the count is restarted. This allows for example if 10 orders are allowed but only one in loss, and the price runs and no new orders are opened in the losing direction. Eventually the price will change direction again and once the ReverseOn level is exceeded another order will be allowed as the in loss order is not counted because the direction changed. You can set the direction change very high to avoid this if required. Timer - Hours till direction retry 0.5 = 30min BuyOrdersPerTimer - Max in loss buy orders during Timer above SellOrdersPerTimer - Max in loss sell orders during Timer above Deciding on which orders to take into account for the timer ResetOrderCountonReverse - True = Clear Orderspertime on direction reverse If set to True , each time the direction changes the counter will be reset and allow more orders. if false the count will remain. Higher drawdown if true but more profit. IncludeClosedOrders - False = Ignore closed orders Only use the currently opened orders for the timer and count. Depends on your strategy Closedinlossonly - True = Ordersclosed in profit are excluded from the count even if they would currently be in loss ______BREAK_LOTS______ When the recovery lots get too big they can be limited and let out at the rate of MaxLotMultiply at a time MaxNextLot = 10000 lots over this are limited MaxLotMultiply = 0.667 the nextlot becomes the maxnextlot times this value PauseMultiple - StartLots x PauseMultiple = pause new orders activated if this is set to 100 and the startlot is 0.01 , when the nextlot gets to 1.0 (100x0.01) then the EA will stop opening trades for the "Hourstowait" Hourstowait - hours to pause for market to change/settle ______SPREAD______ Sometimes the spread goes very low or very high and this can cause orders to open or close prematurely. >>>MaxSpread - Max spread to accept, if the spread is above this the EA will not trade. MinSpreadOpen - If the spread is below this the EA will not open an order. MinSpreadCloseProfit - If the spread is below this the EA will not close an order in profit. MinSpreadCloseLoss - Increase avoids early loss with big spreads MinSpreadReverse - Increase avoids early reverse with big spreads The history of the highs and lows etc is not kept for the ask, only the bid is kept. So with some spread changes some false readings can occure when history is concerned. To combat this we decide an average spread to use for the history of the Ask instead of the current fluctuating spread. We choose to use it or not with "UseInternalSpread" . Set to true once you have chosen your avaerage spreat to use "InternalSpread" InternalSpread = 100 UseInternalSpread = false ______SPECIAL_MANAGEMENT______ Special Management is used to set a trailing stoploss or alternate stoploss to orders over a size SManageLotsOver SManageLotsOver - Special Management for lots larger than SMLOStoploss - Stoploss Points for Special Management. The stoploss levels are ignored for these lots. it is replaced with this value in points. Once the order reaches a points in profit "SMLOTrigger" to trigger the trailing stop, the trailing stop of "SMLONewStopLoss" points in profit is set. if the price goes back to that value the order is closed and recovery calculated if it was a recovery order that didnt recover. SMLOTrigger - Points in Profit at which to trigger SMLONewStopLoss SMLONewStopLoss - Points in Profit for new Stoploss 0 = breakeven ..... -10 = 10 points in loss The "SMLONewStopLoss" is fixed and does not trail behind as the price climbs unless "SMLODynamicTakeProfit" is set to True. If set to True the order will only close when it reverses from its maximum reached price and price difference reaches the difference between "SMLOTrigger" and "SMLONewStopLoss" SMLODynamicTakeProfit - false will close on regular takeprofit ______iADX______ The iADX indicator can be used to decide when new order are opened. It is only used when the orders are above the "UseADXLots" . You can set it to 0 to process all orders via iADX. When all conditions are met an order will open. UseADXLots - Use the iADX indicator for lots over iADX Timeframe ENUM 1 for 1min 5 for 5min 15 for 15min 30 for 30min 60 fot 1hour 240 for 4hour 1440 for 1Day 10080 for 1Week etc https://docs.mql4.com/constants/chartconstants/enum_timeframes iADX Period iADX ENUM Applied Price 0- close - https://docs.mql4.com/constants/chartconstants/enum_timeframes ADXBarsBack - Compare current ADX to previous ADX this many bars back on the iADX Timeframe ADXMustCross only trigger if Di's have crossed The below ADX values range from 0-100 and have fractions the gradient can be -100 >>ADX Trigger for Main must be above this ADX Max for Main must be below this ADXTriggerDiff - Gradient - Minimum Difference between current and previous 0 for flat or any up. -100 doesnt matter 0.01 must be slightly up >>ADX Trigger - Di must be above this ADX Max - Di must be below this ADXDiTriggerDiff - Gradient - Minimum Difference between current and previous >>ADX Trigger - reverse Di must be below this ADX Min - reverse Di must be above this ADXDiConfirmDiff - Gradient - Minimum Difference between current and previous ______CloseiADX______ UseADXSLLots - Use the iADX Stoploss indicator for lots over UseADXSLPoints - Hard stoploss in Points iADXSL Timeframe ENUM iADXSL Period iADXSL ENUM Applied Price 0- close ADXSLBarsBack - Compare current ADX to previous ADXSLMustCross only trigger if Di's have crossed >>ADXSL Trigger for Main. Droping below closes ADXSLTriggerDiff - Minimum Difference between current and previous ADX >>ADXSL Trigger for Di if it drops below then closes ADXSLDiTriggerDiff - Minimum Difference between current and previous ADX >>ADXSL Trigger for reverse Di if it moves above closes ADXSLDiConfirmDiff - Minimum Difference between current and previous ADX ______RECOVERY______ When an order closes in loss a recovery (martingale) lot is calculated with the following ratios >>>>>>LossRecoveryRatio - 0 - dont compensate 1 - calculate a carrylot size that will recover the loss in one takeprofit 1.2 - add 20% etc Max1stRecoveryLotSize once the recovery lot gets to this size then use the 2nd recovery lots ratio instead 2ndLossRecoveryRatio- 0 - dont compensate Max2stRecoveryLotSize once the recovery lot gets to this size then use the 3rd recovery lots ratio instead 3rdLossRecoveryRatio- 0 - dont compensate Max3stRecoveryLotSize 4rthLossRecoveryRatio- 0 - dont compensate ______TRIGGERS______ Once an order in profit gets to the takeprofit it can become a trailing in percentage by the return trigger. If the price falls below the TP before the trigger is reached the order is left open to see if it can go higher. 1.1 would mean immediate as it gets to the TP with no dynamic nature. >>>>>>>>ProfitTrigger - 0.9 allows 10% pullback before closing once takeprofit met LossTrigger - 1.1 closes losses at stoploss .. 0.6 waits for 40% retrace >>>>>>>>>Lotgrowth - 0.5 Startlots increase at 50% of equity increases more used for backtesting but as the balance grows the startlot can also grow by this factor 1 would mean if the equity doubles the startlot doubles. .1 would mean when the euity doubles the startlot increases by 10% . 1 being 100% . Very high risk can set this to 2 to incease the startlot faster than the equity is increasing as it will drop again if the equity decreaes causes possible huge growth or total failure. the reset on percentage or "EquityTargetPercent reset " can be used with it as it will reset the equity and therefor also the startlot. allowing a quick climb and then reset bcak to original lots. ______SLIPPAGE_COMMISSION______ OpenSlippage - Max Slippage on OpenOrder CloseSlippage - Max Slippage on CloseOrder SlippageRecoveryRatio - 1 = Carrylot added to recover lost slippage profit over 1 takeprofit CommissionRecoveryRatio - 1 = Carrylot added to recover lost commission profit over 1 takeprofit ______MISC______ MAGICNUM = 20222222 use this for your magicnumber (any number to differenciate between other EAs on the same pair. if you use it on a different pair the number can be the same but any two EAs on the same pair must have different numbers to not interfier with eachother or if you want them to both manage the same orders then they must be the same) Verbose = false .. set to true to see the EAs comments