我怎样才能获得订单打开后的最高价。

 

亲爱的。

谁能检查一下下面的链接并回答我的问题(我怎样才能在订单打开价格后得到最高的价格)。

http://www.forexfactory.com/showthread.php?t=307937

 
string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }
:
datetime    OOT         = OrderOpenTime();          // Assumes OrderSelect() done already
int         iOOT        = iBarShift(NULL,0, OOT);   // Bar of the open.
#define     iBarCURRENT   0                         // Include current bar.
int         nSince  = iOOT - iBarCURRENT + 1;       // No. bars since open.
int         iHi         = iHighest(NULL,0, MODE_HIGH, nSince, iBarCURRENT);
double      HH          = High[iHi];                // Highest high.
Print( "High since order opened on ", TimeToStr(OOT)," is ", PriceToStr(HH) );
 
WHRoeder:


以下是上述代码的一些错误。

'(' -函数 定义意外 D:\Program Files\FXDD Malta - MetaTrader 4\experts\test2.mq4 (343, 18)

这个错误适用于字符串 PriceToStr(double p)。

对于这个错误 我不知道如何才能解决它


'iBarCurrent' - 未定义变量 D:\Program Files\FXDD Malta - MetaTrader 4\experts\test2.mq4 (348, 30)

这个错误是因为你定义了#define iBarCURRENT,然后你把它作为iBarCurrent

我将解决这个问题。


2个错误(s)。

 

把这一行放在你的代码的最后, start函数 之外. .

string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }

并开始阅读这个,如果你想学习代码:https://book.mql4.com//

 

它是清楚的家伙(RaptorUK和WHRoeder)。

谢谢你们。

datetime    OOT         = OrderOpenTime();          // Assumes OrderSelect() done already
int         iOOT        = iBarShift("EURUSD",PERIOD_H1, OOT);   // Bar of the open.
#define     iBarCURRENT   0                         // Include current bar.
int         nSince  = iOOT - iBarCURRENT + 1;       // No. bars since open.
int         iHi         = iHighest("EURUSD",PERIOD_H1, MODE_HIGH, nSince, iBarCURRENT);
double      HH          = High[iHi];                // Highest high.
int         iLi         = iLowest("EURUSD",PERIOD_H1, MODE_LOW, nSince, iBarCURRENT);
double      LL          = Low[iLi];                 // Lowest low. 

我还有一个问题。

如果我有两个订单,一个是买入,另一个是卖出。

我怎样才能让我的EA理解并接受iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // 开仓的条。对于我从它那里得到的买入头寸的条形图,并从该点计算最高价。

而且

取iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // 开盘的小节。对于我从它那里得到的卖出头寸,并计算出从该点开始的最低点。

非常感谢

 
要获得OOT,你必须已经做了一个orderSelect
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
){
    datetime    OOT         = OrderOpenTime();          // Assumes OrderSelect() done already
    int         iOOT        = iBarShift("EURUSD",PERIOD_H1, OOT);   // Bar of the open.
    #define     iBarCURRENT   0                         // Include current bar.
    int         nSince      = iOOT - iBarCURRENT + 1;   // No. bars since open.
    if (OrderType == OP_BUY){
        int     iHi         = iHighest("EURUSD",PERIOD_H1, MODE_HIGH, nSince, iBarCURRENT);
        double  HH          = High[iHi];                // Highest high.
    }
    else{
        int     iLi         = iLowest("EURUSD",PERIOD_H1, MODE_LOW, nSince, iBarCURRENT);
        double  LL          = Low[iLi];                 // Lowest low. 
    }
}
 
WHRoeder:
要获得OOT,你必须已经做了一个订单选择


谢谢大家。

此外,我还有其他问题。

我怎样才能做到这样的条件:如果(卖出的最后一笔订单的价格()> 卖出的最后一笔订单的价格)&&(卖出的最后一笔订单的价格>=出价)。

关闭该头寸

像这样的情况就可以了

if ( (OrderType == OP_SELL)&& OrderSelect(pos+1, SELECT_BY_POS,MODE_TRADES ) )          { if( pos>pos+1  && pos+1>MarketInfo("EURUSD",MODE_BID);
            // close the position


 

只是。

我想知道我怎样才能得到:最后一笔订单之前的订单(开仓或平仓)价格()(买入或卖出),以便将它们加入一些计算中。

非常感谢。

 
没有答案,只是我需要在最后一个订单之前获得订单,即使是买入或卖出,即使该订单是开放订单或关闭订单,等待您的帮助。
 
Hand:
我想知道如何才能得到:最后一个订单之前的订单(开仓或平仓)的价格()(买入或卖出),以便在一些计算中加入它们。
找到最后一个订单,记住,找到下一个更早的订单。
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    ){
       datetime OOTlatest = OrderOpenTime();  // found latest open order
       break;
    }
    for(pos--; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    ){
       datetime OOTprevious = OrderOpenTime(); // found the previous
       break;
    }
    if (OOTlastest == 0) // no open orders
    if (OOTprevious == 0) // no previous
:
 

谢谢WHRoeder。

如果我需要获得买入的最后一笔订单和卖出的最后一笔订单,然后通过以下方式进行比较。

如果( 最后一笔买入订单 == OOTlastest )

{ 做一些事情 }

否则

{ }.......,下面的代码将工作。

for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
){
    if (OrderType() == OP_BUY){
        int lastorderforbuy= OrderOpenPrice();
    }
    else{
        int lastorderforsell= OrderOpenPrice(); 
         }
    }   for(pos--; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    ){
       if (OrderType() == OP_BUY){
        int previousorderforbuy= OrderOpenPrice();
    }
    else{
        int previousorderforsell= OrderOpenPrice(); 
         }
     } 
    if ( ((lastorderforbuy+ previousorderforsell)/2)<=MarketInfo("EURUSD",MODE_BID))
               {  CLOSESHORT("EURUSD") ;}