你的代码格式让人很难看懂,但有一点,你怎么能在追踪止损中使用这个。订单必须仍然是开放的,所以不存在OrderClosePrice()。
( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + CummulativeValue )
在不知道Figure是什么的情况下,.....,你写的代码知道OrderClosePrice == 0,因此OrderClosePrice - OrderOpenPrice有一个负值,如果订单仍然是开放的?
不,我没有,我所有的其他脚本只使用OrderClosePrice - OrderOpenPrice或反之亦然,工作正常。
谁能帮我一把,我其实已经很接近了。我个人认为我的编码没有问题,但我就是不知道为什么它总是不能正常工作。
我已经很久没有把所有的东西合并到一起了,请原谅我现在的眼睛有点模糊了。
图中返回每个特定货币对的点值。
这是尾随部分。
//+------------------------------------------------------------------+ //| Program's global variables | //+------------------------------------------------------------------+ extern double StartTrailingStop = 15.0 ; extern double TrailingStop = 5.0 ; extern double CummulativeValue = 5.0 ; extern int NumberOfTrail = 10 ; double Figure ; //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| Program's sub-function | //+------------------------------------------------------------------+double PointsDetection() { Figure = 0.0 ; if ( MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.01 || MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.001 ) { Figure = 0.01 ; } else { if ( MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.0001 || MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.00001 ) { Figure = 0.0001 ; } } return ( Figure ) ; }
//+------------------------------------------------------------------+ //| Program's sub-function | //+------------------------------------------------------------------+ void ProcessTrailingStop() { bool Result ; for ( int x = ( OrdersTotal() - 1 ) ; x >= 0 ; x-- ) { if ( OrderSelect ( x , SELECT_BY_POS , MODE_TRADES ) == True ) { PointsDetection() ; if ( OrderType() == OP_BUY ) { for ( int xai = 0 ; xai < NumberOfTrail ; xai++ ) { if ( xai == 0 ) { if ( ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= StartTrailingStop ) && ( ( OrderStopLoss() == 0 ) || ( OrderStopLoss() < ( OrderOpenPrice() + ( TrailingStop * Figure ) ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( TrailingStop * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } if ( xai == 1 ) { if ( ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + CummulativeValue ) ) && ( OrderStopLoss() == ( OrderOpenPrice() + ( TrailingStop * Figure ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( ( TrailingStop + CummulativeValue ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } if ( xai >= 2 ) { if ( ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + ( CummulativeValue * xai ) ) ) && ( OrderStopLoss() == ( OrderOpenPrice() + ( ( TrailingStop + ( CummulativeValue * ( xai - 1 ) ) ) * Figure ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( ( TrailingStop + ( CummulativeValue * xai ) ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } } } else { if ( OrderType() == OP_SELL ) { for ( int xaii = 0 ; xaii < NumberOfTrail ; xaii++ ) { if ( xaii == 0 ) { if ( ( ( ( OrderOpenPrice() - OrderClosePrice() ) / Figure ) >= StartTrailingStop ) && ( ( OrderStopLoss() == 0 ) || ( OrderStopLoss() > ( OrderOpenPrice() - ( TrailingStop * Figure ) ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( TrailingStop * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } if ( xaii == 1 ) { if ( ( ( ( OrderOpenPrice() - OrderClosePrice() ) / Figure ) >= ( StartTrailingStop + CummulativeValue ) ) && ( OrderStopLoss() == ( OrderOpenPrice() - ( TrailingStop * Figure ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( ( TrailingStop + CummulativeValue ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } if ( xaii >= 2 ) { if ( ( ( ( OrderOpenPrice() - OrderClosePrice() ) / Figure ) >= ( StartTrailingStop + ( CummulativeValue * xaii ) ) ) && ( OrderStopLoss() == ( OrderOpenPrice() - ( ( TrailingStop + ( CummulativeValue * ( xaii - 1 ) ) ) * Figure ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( ( TrailingStop + ( CummulativeValue * xaii ) ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; } } } } } } }
也许有:
( OrderStopLoss() == ( OrderOpenPrice() - ( TrailingStop * Figure ) )
https://forum.mql4.com/45053
也许它应该这样编码,以避免服务器错误。
figure = PointsDetection(); if ( ( ( ( OrderOpenPrice() - OrderClosePrice() ) / Figure ) >= StartTrailingStop ) && ( ( OrderStopLoss() == 0 ) || ( OrderStopLoss() >= OrderOpenPrice() ) || ( OrderStopLoss() > ( OrderOpenPrice() - ( TrailingStop * Figure ) ) ) ) ) { Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( TrailingStop * Figure ) ) , OrderTakeProfit() , 0 , Color ) ; if( result == true ) break; }
对于买入订单。
( OrderStopLoss() < ( OrderOpenPrice() + ( TrailingStop * Figure ) )
我在做一个跟踪的EA,当我在演示中测试时,我注意到只有买入订单是正确的(我想),而卖出订单 只移动了一次止损。但我仍然无法发现问题所在。
** 编辑了代码 **