what is wrong with my code that I get error 130 invalid stops?

 

The function I use to calculate my lots

//Code to Calculate lot size
       if( ((bear.signal == true)||(bull.signal == true))&&(LotCalculated == false) )
       {
           Print("Calculating Lotsize");
            Balance = AccountEquity();
            StopLoss = multiplier*atr24;
            
            
         //LotSize = NormalizeDouble(CalcLotSize( EquityPercent, StopLoss),1);
         
            Print("AccountEquity(): "+AccountEquity() );
                      RiskAmount = Balance*(EquityPercent1 / 100.0);
                                Print("RiskAmount1: "+RiskAmount);
                                 TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
                                Print("TickValue1: "+TickValue);
                                if(Point == 0.001 || Point == 0.00001) TickValue*= 10;
                                 LotSize1 = NormalizeDouble( (RiskAmount/StopLoss)/TickValue,1);
                           Print("TickValue check1: "+TickValue);
                      Print("LotSize1: "+LotSize1);
                      
                      
                      
                      Print("AccountEquity(): "+AccountEquity() );
                      RiskAmount = Balance*(EquityPercent2 / 100.0);
                                Print("RiskAmount2: "+RiskAmount);
                                 TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
                                Print("TickValue2: "+TickValue);
                                if(Point == 0.001 || Point == 0.00001) TickValue*= 10;
                                 LotSize2 = NormalizeDouble( (RiskAmount/StopLoss)/TickValue,1);
                           Print("TickValue check2: "+TickValue);
                      Print("LotSize2: "+LotSize2);


My code that I used to set my stop and place orders is

CalculateLotSize();
        Print("Bull Market Order ");
        bull.TP1 = NormalizeDouble((Ask + atr24),Digits);
        bull.TP2 = NormalizeDouble((Ask + atr24),Digits);
        
        bull.SL1 = NormalizeDouble((Ask - atr24),Digits);
        bull.SL2 = NormalizeDouble((Ask - atr24),Digits);
        Print("bull.TP1 "+ bull.TP1);
        Print("bull.TP2 "+ bull.TP2);
        Print("bull.SL1 "+ bull.SL1);
        Print("bull.SL2 "+ bull.SL2);
        Print("ATR 24 "+ atr24);
        if(Bull.Ticket1 <= 0)Bull.Ticket1 = OpenBuyOrder(Symbol(), LotSize1,Slippage,bull.SL1,bull.TP1, MagicNumber, "Buy Order"); 
        if(Bull.Ticket2 <= 0)Bull.Ticket2 = OpenBuyOrder(Symbol(), LotSize2,Slippage,bull.SL2,bull.TP2, MagicNumber, "Buy Order");


The print out statements of the bull take profit and stoploss at time of error Invalid 130 invalid stops

bull.TP1 = 0.81948000

bull.TP2 = 0.81948000

bull.SL1 = 0.81608000

bull.SL1 = 0.81608000

ATR 24 = 0.00169792


Bid: 0.8175 Ask: 0.8178

 
jeemba2012:

The function I use to calculate my lots

My code that I used to set my stop and place orders is

Don't you read any other threads on this Forum ? plenty of threads about error 130 and how to address it . . .

Where is the code that actually places the Order ? OpenBuyOrder() is not an MQL4 function . . .

Is your Broker an ECN Broker ?

 

I am using MBtrading. it is EXN

my code to place the order is

int OpenBuyOrder(string argSymbol, double argLotSize, double argSlippage,double argSL, double argTP, double argMagicNumber, string argComment = "Buy Order")
{
                while(IsTradeContextBusy()) Sleep(10);

                // Place Buy Order
                int Ticket = OrderSend(argSymbol,OP_BUY,argLotSize,MarketInfo(argSymbol,MODE_ASK),argSlippage,argSL,argTP,argComment,argMagicNumber,0,Green);

                // Error Handling
                if(Ticket == -1)
                        {
                                int ErrorCode = GetLastError();
                                string ErrDesc = ErrorDescription(ErrorCode);

                                string ErrAlert = StringConcatenate("Open Buy Order - Error     ",ErrorCode,": ",ErrDesc);
                                Alert(ErrAlert);

                                string ErrLog = StringConcatenate("Bid: ",MarketInfo(argSymbol,MODE_BID)," Ask: ",MarketInfo(argSymbol,MODE_ASK)," Lots: ",argLotSize);
                                Print(ErrLog);
                                
                                ErrorCheck( ErrorCode );
                        }
                
                return(Ticket);
}     
 

MBT is an ECN Broker . . you can't set TP & SL when you send a Market order . . . . send with SL & TP = 0.0, then do a ModifyOrder() and set the SL & TP . . .

Read here: ECN

Reason: