Einzelnen Beitrag anzeigen
  #6 (permalink)  
Alt 30.12.16
akuh akuh ist offline
Neues Mitglied
 
Registriert seit: Nov 2016
Beiträge: 7
akuh befindet sich auf einem aufstrebenden Ast
Standard

Hey

Erstmal Vielen Dank für die Antworten. Ich hab es mittlerweile folgendermassen gelöst:
Code:
int LastOrderType()
{
    datetime TicketTime = 0;
   
    for (int ix = 0; ix < OrdersHistoryTotal(); ix++)
    {
        if(OrderSelect(ix, SELECT_BY_POS, MODE_HISTORY) 
            && OrderMagicNumber() == Magic 
            && OrderSymbol() == Symbol())
        {
            if (OrderCloseTime() > TicketTime)
            {
                TicketTime = OrderCloseTime();  //For testing
                TicketN = OrderTicket();        //For testing
                LastOT = OrderType();
            }   
        }
        else
            Print("OrderSelect returned the error of ",GetLastError());
    }
    Print("Last closed order: ",TicketN,"  ",TicketTime,"  ",LastOT);   //For testing
    return(LastOT); // Buy==0, Sell==1, Others==2 through 5
}// End Last Order Type
Dann kann ich bei meiner Buy Condition einfach &&OrderType()==OP_SELL angeben. Dann wird eine buy position nur dann eröffnet, wenn vorher eine Sell Position geschlossen war.

Ich stehe aber mittlerweile vor einem neuen Problem, das ich nicht gelöst kriege. Ich möchte gerne eine Sellstop bzw. Buystop position eröffnen, sobald der ask bzw bid Wert des aktuellen Kurses, höher bzw. niedriger ist als der Wert des Super-trend indicators. Ich habe bereits einige Versuche unternommen, aber keiner War erfolgreich. Hier sieht ihr meinen Code für die Eröffnung von buy/sell und buystop/sellstop positionen:

Code:
  double up = iCustom(NULL,PERIOD_M5,"HalfTrend_1",4,1); // returns EMPTY_VALUE when no arrow occurs
 double down = iCustom(NULL,PERIOD_M5,"HalfTrend_1",5,1);// returns EMPTY_VALUE when no arrow occurs
 double tu = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,0,1); // returns EMPTY_VALUE in downtrends
 double td = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,1,1); // returns EMPTY_VALUE in uptrends
  double stup = iCustom(NULL,PERIOD_M15,"ST_MTEI",0,0); // returns EMPTY_VALUE when no arrow occurs
 double stdown = iCustom(NULL,PERIOD_M15,"ST_MTEI",1,0);// returns EMPTY_VALUE when no arrow occurs
 //Print("ST_MTEI:", up);
 //Print("ST_MTEI:", down);

 
 
 
   RefreshRates();  // RefreshRate() update Bid and Ask value.
  
   if ( ( Ask - Bid ) / Point < MaxSpread ) { // Checking, if spread is less than MaxSpread from inputs. If its Bigger, orders wont open
 
  // Replace 1 == 0 to your conditions to buy order.
      if ( up!=empty && stup!=empty && tu!=empty && down == empty && td==empty  && stdown ==empty &&OrderType()==OP_SELL && LastOrder != 1 ) { // LastOrder!= 1 prevent script from making a lot of same buy orders
         Ticket = OrderSend ( Symbol(), OP_BUY, Lots, Ask, Slippage, Ask - ( StopLoss * Point ), Ask + ( TakeProfit * Point ), NULL, Magic, 0, Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }
   
      // Replace 1 == 0 to your conditions to buy order.&& LastOT==1
      if ( Bid<tu    && LastOrder != 1 )  {  // LastOrder!= 1 prevent script from making a lot of same buystop orders
         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, Magic, TimeCurrent() + ( 60 * Mins ), Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }
  
      // Replace 1 == 0 to your conditions to sell order.
      if ( down!=empty &&  stdown!=empty && td!=empty && up==empty && tu==empty  && stup==empty &&OrderType()==OP_BUY  && LastOrder != 0 ) { // LastOrder!= 0 prevent script from making a lot of same sell orders
         Ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, Bid + ( StopLoss * Point ), Bid - ( TakeProfit * Point ), NULL, Magic, 0, Red);
         LastOrder = 0; // It prevent script from making a lot of same sell orders
      }
   
      // Replace 1 == 0 to your conditions to sell order.&&  LastOT==0
      if ( Ask>td   && LastOrder != 0 ) {  // LastOrder!= 0 prevent script from making a lot of same sellstop orders
         Ticket = OrderSend ( Symbol(), OP_SELLSTOP, Lots, Bid - ( Pips * Point ) , Slippage, Bid - ( Pips * Point ) + ( StopLoss * Point ), Bid + ( Pips * Point ) - ( TakeProfit * Point ), NULL, Magic, TimeCurrent() + ( 60 * Mins ), Red);
         LastOrder = 0; // It prevent script from making a lot of same sell orders
      }
      
   }

return ( 0 );
}
hättet ihr vielleicht eine idee dazu ?

gruss akuh