How to set order few pips above order initiation bar in MQL4

眉间皱痕 提交于 2019-12-03 21:52:54

Major issue

Once having assigned ( per each Market Event Quote Arrival )

double HH = High[1],
       LL = Low[ 1];

Your instruction to OP_SELL shall be repaired:

ticket = OrderSend( Symbol(),
                    OP_SELL, 
                    Lots,
                    Bid,
                    10,
                 // ----------------------v--------------------------------------
                 // Ask              + HH * 10 * Point,
                 // intention was High[1] + 10 [PT]s ( if Broker allows ), right?
                    NormalizeDouble(   HH + 10 * Point,
                                       Digits      // ALWAYS NORMALIZE FOR .XTO-s
                                       ),
                 // vvv----------------------------------------------------------
                 // Ask - TakeProfit * Point * 10, // SAFER TO BASE ON BreakEvenPT
                    NormalizeDouble(   Ask
                                     - TakeProfit * Point * 10,
                                       Digits      // ALWAYS NORMALIZE FOR .XTO-s
                                       ),
                    "Set by SimpleSystem"
                    );

Symmetrically review and modify the OP_BUY case.

For Broker T&C collisions ( these need not get reflected in backtest ) review:

MarketInfo( _Symbol, MODE_STOPLEVEL )
MarketInfo( _Symbol, MODE_FREEZELEVEL )

or inspect in the MT4.Terminal in the MarketWatch aMouseRightClick Symbols -> Properties for STOPLEVEL distance.


Minor Issue

Review also your code for OrderClose() -- this will fail due to having wrong Price:

// ---------------------------------------------vvvvv----------------------------
   bool  res2  = OrderClose( ticket, Lots, OrderClosePrice(), 10 ); # was db.POOL()-SELECT'd
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!