Problem mit der Gesamtzahl der offenen Aufträge - Seite 2

 

Ja, Sie müssen den Auftrag erneut auswählen.

   int buy_ticket=0;
   total=0;
   for(i = OrdersTotal()-1; i >= 0 ; i--)
   if ( OrderSelect(i, SELECT_BY_POS)                
    &&  OrderMagicNumber()  == magicNumber            
    &&  OrderSymbol()       == Symbol())
    {             
      total++;
      if(OrderType()==OP_BUY)
         buy_ticket=OrderTicket();
    }
    
   if(buy_ticket>0 && OrderSelect(buy_ticket,SELECT_BY_TICKET))
     {
     //Do stuff
     }

Mit dem obigen Code erstellen Sie eine neue Variable, um die Ticketnummer zu speichern, dann können Sie den Handel anhand der Ticketnummer auswählen

 
GumRai:

Ja, Sie müssen den Auftrag erneut auswählen.

Mit dem obigen Code erstellen Sie eine neue Variable, um die Ticketnummer zu speichern, dann können Sie den Handel anhand der Ticketnummer auswählen

Awesome!!!!!! Vielen Dank dafür. Nach vielen Wochen funktioniert jetzt alles. Ich habe viel gelernt. Vielen Dank an alle!!!
 
Trader3000:
Awesome!!!!!! Vielen Dank dafür. Nach vielen Wochen funktioniert jetzt alles. Ich habe viel gelernt. Vielen Dank an alle!!!

Sorry, aber ich habe mich zu früh geäußert. Der Trailingstop setzt nur manchmal ein, also denke ich, dass der Code noch irgendwo kaputt ist. Hier ist der gesamte EA. Kann bitte jemand überprüfen und mir Bescheid sagen, wenn er einen Fehler entdeckt. Danke

#define  magicNumber  12345

// Kicks in when position reaches at least TrailingStop pips of profit.

extern string Label_Trailingstart = "Pip threshold to activate Trailing stop";
extern double TrailingStart = 10;
extern string Label_Trailingstop = "Pips trailing behind";
extern double TrailingStop = 5;

//Set it to some value above 0 to activate Hedge
extern double Hedge = 10;
extern double Multiplier = 3;

extern string Label_StopLoss = "Set StopLoss of original trade";
extern double StopLoss = 11;

extern string Label_Stoploss1 = "Set Stoploss of Hedge trade";
extern string Label_Stoploss2 = "Value should be less than 'Hedge'";
extern string Label_Stoploss3 = "otherwise a second Hedge trade will open";
extern double Stoploss = 9;

extern string Label_Percentage = "Lotsize percentage of Equity";
extern double Percentage = 1;
extern double Lotsize = 0.01;

int i, result, total;
double stoplevel;

int init()
{
   stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;  // get broker's stoplevel
   if(StopLoss<=stoplevel) StopLoss=stoplevel;     // we compare our StopLoss with
   if(Stoploss<=stoplevel) Stoploss=stoplevel;     // stoplevel and adjust it when error occured
   if(TrailingStop<=stoplevel) TrailingStart=stoplevel+TrailingStop;  // we compared our TakeProfit
                                                       // as we compared our StopLoss
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)
   {
   MessageBox("Please note: If your inputs for StopLoss, Stoploss"+
              "\nand/or TrailingStop are below the minimum levels"+
              "\nrequired by your broker, they will automatically"+ 
              "\nbe increased to "+StringConcatenate(stoplevel)); 
   }                                                             
   return(0);
}
 
int deinit()
{
   return(0);
}
 
int start()
{ 
   //double Lots = NormalizeDouble(AccountEquity()*Percentage*Lotsize/100, 2);
   
  int buy_ticket=0;
  int sell_ticket=0;
   total=0;
   for(i = OrdersTotal()-1; i >= 0 ; i--)
   if ( OrderSelect(i, SELECT_BY_POS)                
    &&  OrderMagicNumber()  == magicNumber            
    &&  OrderSymbol()       == Symbol())
    {             
      total++;
      if(OrderType()==OP_BUY)
         buy_ticket=OrderTicket();
      if(OrderType()==OP_SELL)
         sell_ticket=OrderTicket();   
    }
          if(total==0 && Close[1]>Close[2])
           {
              result=OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Ask - StopLoss*Point*10, 0, "Original", magicNumber, 0, Blue);
              Print("Error setting Original order: ",GetLastError());     
           }
           
     if (buy_ticket>0 && OrderSelect(buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_BUY) 
       {
        if (Bid - OrderOpenPrice() > NormalizeDouble(TrailingStart *Point*10,Digits))
         {
           if (OrderStopLoss() < Bid - NormalizeDouble(TrailingStop *Point*10,Digits))
           {
              if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - NormalizeDouble(TrailingStop *Point*10,Digits),
              OrderTakeProfit(), Blue)) 
              Print("Error setting Buy trailing stop: ",GetLastError()); 
           }
         }
            else if (OrderOpenPrice() > Bid + NormalizeDouble(Hedge*Point*10,Digits))
            if(total == 1)
            {
            result=OrderSend(Symbol(), OP_SELL, NormalizeDouble(OrderLots() * Multiplier, 2), Bid, 3,
            Bid + Stoploss*Point*10, 0, "Hedge", magicNumber, 0, Blue);
            Print("Error setting Sell Hedge: ", GetLastError());
            }
       }
     else if (sell_ticket>0 && OrderSelect(buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_SELL)
       {
        if (OrderOpenPrice() - Ask > NormalizeDouble(TrailingStart *Point*10,Digits)) 
         {
          if (OrderStopLoss() > Ask + NormalizeDouble(TrailingStop *Point*10,Digits))
           {
              if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask + NormalizeDouble(TrailingStop *Point*10,Digits),
              OrderTakeProfit(), Red))
              Print("Error setting Sell trailing stop: ",GetLastError()); 
           }
              }
                 else if (OrderOpenPrice() < Ask - NormalizeDouble(Hedge*Point*10,Digits))
            if(total == 1)
            { 
            result=OrderSend(Symbol(), OP_BUY, NormalizeDouble(OrderLots() * Multiplier, 2), Ask, 3,
            Ask - Stoploss*Point*10, 0, "Hedge", magicNumber, 0, Red);
            Print("Error setting Buy Hedge: ", GetLastError());
            }  
            }
    return(0);
}
 
  if (buy_ticket>0 && OrderSelect(buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_BUY) 
       {
        //Code
       }
     else if (sell_ticket>0 && OrderSelect(buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_SELL)
       {
        //If there is an open buy order code here will not be executed
        //The else is not necessary
       }

,

 
GumRai:

,

Vielen Dank für den Hinweis, ich habe den Fehler behoben und es funktioniert jetzt. Ich habe noch eine andere Frage: Ich versuche, das Meldungsfeld aufpoppen zu lassen, wenn mein Stoploss unter dem STOP_LEVEL des Brokers liegt, aber es erscheint auch, wenn es darüber liegt. Ich habe versucht, es in den Abschnitt "Start" und nicht in den Abschnitt "Init" zu setzen, aber auch dort funktioniert es nicht. Könnte bitte jemand einen Blick darauf werfen und mir sagen, was falsch ist. Danke

int init()
{
   stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;  // get broker's stoplevel
   if(StopLoss<=stoplevel) StopLoss=stoplevel;     // we compare our StopLoss with
   if(Stoploss<=stoplevel) Stoploss=stoplevel;     // stoplevel and adjust it when error occured
   if(TrailingStop<=stoplevel) TrailingStart=stoplevel+TrailingStop;  // we compared our TakeProfit
                                                       // as we compared our StopLoss
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)
   {
   MessageBox("Please note: If your inputs for StopLoss, Stoploss"+
              "\nand/or TrailingStop are below the minimum levels"+
              "\nrequired by your broker, they will automatically"+ 
              "\nbe increased to "+StringConcatenate(stoplevel)); 
   }                                                             
   return(0);
}
 
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)

macht keinen Sinn

Meinen Sie?

   if ((StopLoss  < stoplevel || TrailingStop) < stoplevel)
 
GumRai:

macht keinen Sinn

Meinen Sie?

Nochmals vielen Dank, damit ist das Problem behoben :)
 

Hallo zusammen, ich bin wieder auf ein Problem gestoßen. Es ist sehr seltsam und ich kann nicht verstehen, warum das passiert. Wie ich oben erwähnt habe, hat der EA gut funktioniert, aber jetzt möchte ich einfach von diesem

result=OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Ask - StopLoss*Point*10, 0, "Original", magicNumber, 0, Blue);

zu

result=OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, 0, 0, "Original", magicNumber, 0, Blue);

Ich berühre nichts anderes, aber nach dieser einfachen Änderung wird weder der Trailing-Stop noch die Absicherung ausgelöst. Es ist seltsam. Der vollständige Code ist oben

 
Wie kann man eine Haltestelle verfolgen, wenn man keine hat.
 

Vielen Dank für Ihre Antwort, aber ich verstehe das nicht. Der Code für den Trailing-Stop ist hier

{
        if (Bid - OrderOpenPrice() > NormalizeDouble(TrailingStart *Point*10,Digits))
         {
           if (OrderStopLoss() < Bid - NormalizeDouble(TrailingStop *Point*10,Digits))
           {
              if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - NormalizeDouble(TrailingStop *Point*10,Digits),
              OrderTakeProfit(), Blue)) 

Wenn ich einen Stoploss habe, funktioniert der EA und der Trailingstop und die Absicherung treten in Kraft, aber wenn ich den Stoploss auf 0 ändere, funktioniert nichts. Ich verstehe nicht, wie und warum der Stoploss irgendeinen Einfluss auf den Trailingstop und die Absicherung haben sollte?

Grund der Beschwerde: