Why is my EA not moving my position to breakeven?

限于喜欢 提交于 2019-12-08 23:32:33

For the moment being,
refine the code
and
add self-debuging / tracing code

After OrderModify() use a self-debugging / journaling Print( StringFormat( ... ) ) to document all instructed values used in the actual OrderModify() call and also the remote-execution ( { server-side | StrategyTester } ) reported issues.

The current code does not enter into such self-diagnostics and ModSell is not inspected at all, ModBuy is inspected only at uncertain conditions / by-coincidence at some future visit of the for(){...} code-execution path to a part after newSL == sl ( and all above stated conditions are just by chance met too )


Next, check an assigned value of tp

As stated above,

/*Local  Declarations*/
...
tp                   =  OrderTakeProfit();

which introduces a reasonable doubt, that re-using of this ( inherently uncertain value, as no one knows, which OrderSelect() was the last one that set a db.Pool pointer to decide, from which record from the db.Pool this veryOrderTakeProfit() would accidentally read ( if any record is present in db.Pool already ) inside the whole for(){...} traversing the db.Pool records will not meet conditions for setting properly a TakeProfit price in the next series of OrderModify() calls.

This seems to be the root cause, or a source of unhandled exceptions to the valid, Broker-compliant, OrderModify() values.

Try this:

if (newSL != sl ) {
    ModSell = OrderModify( OrderTicket(),
                           OrderOpenPrice(),
                           OrderOpenPrice(),
                           0,
                           OrderExpiration(),
                           clrRed
                          );
    if(ModBuy == false )
        Print( "OrderModify failed with error #", GetLastError());
}

Then check the Expert-tab for error-message if it fails to set the stop.

Also, you need to take note that StopLoss will ONLY occur if you are on the right chart-timeframe; Otherwise, it won't even get into the if-statements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!