I thought I had the paramaters right on this one. Can anyone tell me what I'm doing wrong?
I get an INVALID_TRADE_PARAMETERS error. I'm not sure where the error is.
I have a procedure for Long and it's the same thing. I get the error on that one too.
Inserted Code
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); }
I get an INVALID_TRADE_PARAMETERS error. I'm not sure where the error is.
I have a procedure for Long and it's the same thing. I get the error on that one too.