Pending Order
Hallo zusammen,
ich würde gerne wissen, wie ich eine pending order öffnen kann, ohne dass sich mehrere öffnen. Wäre für eine Antwort sehr dankbar.
MfG
Du musst als erstes lernen wie man sein Problem so detailliert beschreibt das andere damit was anfangen können. In der Welt der Computer ist das zu ungenau.
Gruß Christian
CTrade m_Trade;
double Lot;
double bid;
double ask;
double Spread;
double Gewinn;
double StopLoss;
double TakeProfit;
bool Buy;
bool Sell;
bool HedgingAktiv;
bool OK=false;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
Spread=SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
Gewinn=PositionGetDouble(POSITION_PRICE_OPEN);
StopLoss=PositionGetDouble(POSITION_SL);
TakeProfit=PositionGetDouble(POSITION_TP);
if(PositionSelect(_Symbol)==false)
{
Lot=0.01;
if(Spread<=60)
{
m_Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lot,ask,ask-0.00180,ask+0.00090,NULL);
Buy=false;
Sell=false;
HedgingAktiv=false;
}
}
if(PositionSelect(_Symbol)==true)
{
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
HedgingAktiv=true;
if(HedgingAktiv==true)
{
if(bid<=Gewinn)
{
Sell=true;
}
}
if(Sell==true)
{
if(Spread<=60)
{
Lot=Lot*2;
MqlTradeRequest request;
MqlTradeResult result;
ZeroMemory(request);
request.action=TRADE_ACTION_PENDING;
request.symbol=Symbol();
request.volume=Lot;
request.price=Gewinn-0.00090;
request.sl=TakeProfit;
request.tp=StopLoss;
request.type=ORDER_TYPE_SELL_STOP;
OrderSend(request,result);
OK=true;
Sell=false;
}
}
if(OK==false)
{
HedgingAktiv=false;
}
}
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
{
if(HedgingAktiv==true)
{
if(ask>=Gewinn-0.00090)
{
Buy=true;
}
}
if(Buy==true)
{
if(Spread<=60)
{
Lot=Lot*2;
MqlTradeRequest request;
MqlTradeResult result;
ZeroMemory(request);
request.action=TRADE_ACTION_PENDING;
request.symbol=Symbol();
request.volume=Lot;
request.price=Gewinn;
request.sl=StopLoss;
request.tp=TakeProfit;
request.type=ORDER_TYPE_BUY_STOP;
OrderSend(request,result);
Buy=false;
}
}
}
}
}
Dann siehst Du selbst sofort warum das passiert, was Du nicht willst!
Nachdem du mit dem Debugger die Stelle gefunden hast guckt du dir noch das hier an
-> https://www.mql5.com/de/docs/trading/positionselect
Dir fehlt die Prüfung in deinem Code ob das Konto auf dem der EA läuft ein NETTING oder HEDGE Konto ist.
Davon ist die Art der Prüfung von "Positionen im Markt " abhängig.
- www.mql5.com
Hallo zusammen,
ich würde gerne wissen, wie ich eine pending order öffnen kann, ohne dass sich mehrere öffnen. Wäre für eine Antwort sehr dankbar.
MfG