datetime issue in Order Send and a 130 error

 

How do you put the date in for expiration in the OrderSend function if your using a 'pending order' command? If I replace tmpTime+3450 w/ 0, it works.

I also get an 'invalid stops - 130' on my order modify.

Anyone got any ideas? I'd appreciate it. TIA!

int EnterShrt( string FinalSymbol, double FinalLots, string Commentary, double StopLoss, int ProfitTarget, int MagicNumber, int MaxTry, int Slippage, double PrefPrice ) 
{
      SymPoints = MarketInfo( FinalSymbol, MODE_POINT  );
      SymDigits = MarketInfo( FinalSymbol, MODE_DIGITS );
   
         if( SymPoints == 0.001   ) { SymPoints = 0.01;   SymDigits = 3; }
   else if( SymPoints == 0.00001 ) { SymPoints = 0.0001; SymDigits = 5; }
        
   double MaximumLots = MarketInfo(FinalSymbol, MODE_MAXLOT );       
   double RemainingLots = FinalLots;   
   int OrdersToPlace = 1;
   if( FinalLots > MaximumLots ) { OrdersToPlace = MathFloor( FinalLots / MaximumLots )+1; }
   
   for( int i = 0; i < OrdersToPlace; i++ )
   {
         int Ticket = -1; int err = 0; bool OrderLoop = False; int TryCount = 0;
         double thisLot = NormalizeDouble( FinalLots / MathMax( OrdersToPlace, 1 ), 2 ); 
         if( RemainingLots - MaximumLots <= 0 ) { thisLot = RemainingLots; }
                                 
         while( !OrderLoop )
         {
            while( IsTradeContextBusy() ) { Sleep( 10 ); }
                           
            RefreshRates();
            double SymAsk = NormalizeDouble( MarketInfo( FinalSymbol, MODE_ASK ), SymDigits );    
            double SymBid = NormalizeDouble( MarketInfo( FinalSymbol, MODE_BID ), SymDigits );
            datetime tmpTime=TimeSeconds(TimeCurrent());
                               
            Ticket = OrderSend( FinalSymbol, OP_SELLSTOP, thisLot, PrefPrice, Slippage * SymPoints, 0.0, 0.0, Commentary, MagicNumber, tmpTime+3540, Red ); 
            int Err=GetLastError();
      
             switch (Err) 
            {
                 //---- Success
                 case               ERR_NO_ERROR: OrderLoop = true;
                                                  if( OrderSelect( Ticket, SELECT_BY_TICKET ) )
                                                  { OrderModify( Ticket, OrderOpenPrice(), StopLoss, TakeShrt(SymBid,ProfitTarget, SymPoints,SymDigits), 0, CLR_NONE ); }
                                                  break;
     
                 //---- Retry Error     
                 case          ERR_INVALID_STOPS:
                 case            ERR_SERVER_BUSY:
                 case          ERR_NO_CONNECTION:
                 case          ERR_INVALID_PRICE:
                 case             ERR_OFF_QUOTES:
                 case            ERR_BROKER_BUSY:
                 case     ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
                 case          ERR_PRICE_CHANGED:
                 case                ERR_REQUOTE: continue;
     
                 //---- Fatal known Error 
                 //case          ERR_INVALID_STOPS: OrderLoop = true; Alert( Commentary + " Invalid Stops "  + GetLastError()  ); break; 
                 case   ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Alert( Commentary + " Invalid Lots"     ); break; 
                 case          ERR_MARKET_CLOSED: OrderLoop = true; Alert( Commentary + " Market Close"     ); break; 
                 case         ERR_TRADE_DISABLED: OrderLoop = true; Alert( Commentary + " Trades Disabled"  ); break; 
                 case       ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Alert( Commentary + " Not Enough Money" ); break; 
                 case  ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Alert( Commentary + " Too Many Orders"  ); break; 
                 case                        149: OrderLoop = true; Alert( Commentary + " Hedge is prohibited"  ); break; 
              
                 //---- Fatal Unknown Error
                 case              ERR_NO_RESULT:
                                         default: OrderLoop = true; Print( "Unknown Error - " + Err ); break; 
                 //----                         
             }  
             // end switch 
             if( TryCount > MaxTry ) { OrderLoop = true; }
         }
      RemainingLots -= thisLot;
   }
   //----               
   return(Ticket);
}
//+------------------------------------------------------------------+
 

TakeShrt(SymBid,ProfitTarget, SymPoints,SymDigits) ????

 
qjol:

TakeShrt(SymBid,ProfitTarget, SymPoints,SymDigits) ????

oops. Sorry.

double TakeShrt(double price,double take,double point,double SymDgts )
{
if(take==0) {  return(0);}
else        {  return(NormalizeDouble( price-(MathAbs(take)*point),SymDgts));}
}
 

Change this:

datetime tmpTime=TimeSeconds(TimeCurrent());

To this:

datetime tmpTime=TimeCurrent();

Reason: