Open Order immediately after last Oder hit Stop Loss - page 2

 
saro2018: The following message always pops up if my EA tries to open a opposite Order immediately: "OrderSend error 130"
ticket=!OrderSend(Symbol(),OP_SELL,Lots,Bid,2,25,10);
Is the Bid/Ask of your symbol between 10 and 25?
 
WHRoeder:
saro2018: The following message always pops up if my EA tries to open a opposite Order immediately: "OrderSend error 130"
Is the Bid/Ask of your symbol between 10 and 25?
It is bascially the Thing I want to open an order immediately after the lst was closed with loss. Then for sell i use bid with the sl 25 and tp 10 and for buy the ask. What do you mean by ask/Bid of my Symbol between 10 and 25? The Spread or the SL and TP?
 

William is pointing out that you are probably using wrong values for the SL and TP

eg.

If you were to place a sell trade manually on EURUSD would you place it as

entry 1.21000 

SL 25

TP 10

I doubt it. You would use

SL 1.21250

TP 1.20900 

 
GumRai:

William is pointing out that you are probably using wrong values for the SL and TP

eg.

If you were to place a sell trade manually on EURUSD would you place it as

entry 1.21000 

SL 25

TP 10

I doubt it. You would use

SL 1.21250

TP 1.20900 

Thanks for the help, I could solve this problem. But there appeared a new problem. The EA is actually opening a new position if the last order was closed with loss and uses the SL and TP parameters. However its not looping then the first conditions. So it basically ignores after a loss all the conditions and opens in certain time periods orders (Buy, then Sell ...). That is the code of the two conditions, the first if the last order were a profit or Zero and the second if its a loss:

}
if (TimeCurrent() <= tradingAllowed) return(0);


 if(AccountFreeMargin()<(1000*Lots))
 {Print("We have no money. Free Margin = ", AccountFreeMargin());
 return(0);
 }
 //check for long position
if (closedProfit>=0)
{  //Print("6");
if (iOpen(NULL,0,0) > u && iClose(NULL,0,0) < u)
   {
        RefreshRates();                        // Refresh rates
       
         SL=Bid + main_sl;     // Calculating SL of opened
         TP=Bid - main_tp;   // Calculating TP of opened
         
        ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP,"Sell St",123456); 
        if(ticket>0)
        {
        if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
        }
        else Print("Error opening BUY order : ",GetLastError());
        return(0);
        }                           // Criterion for opening Sell 

if (iOpen(NULL,0,0) < o  && iClose(NULL,0,0) > o)
   {
        RefreshRates();                        // Refresh rates
             
         SL=Ask - main_sl;     // Calculating SL of opened
         TP=Ask + main_tp;
         
       ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP,"Buy St",123456);  
       if(ticket>0)
        {
        if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
        }
        else Print("Error opening SELL order : ",GetLastError());
        return(0);
        } 
        //Print("7");
 }       

                         // Criterion for opening Sell 

if (closedProfit < 0 && (lastcomment=="Buy St" || lastcomment=="Sell St")) 
    Print("8");
    double STOPLOSS = 100;
    double TAKEPROFIT = 100;
  //if(total < 1) 
  {          //was soll total sein???
      if (lastorder == 0) {
      Print("Gegenposi");
         ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 2, Bid + (STOPLOSS*Point), Bid - (TAKEPROFIT*Point), "abgesichert", mymagicnumber);
          if(ticket>0)
        {
        if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
        }
        else Print("Error opening SELL order : ",GetLastError());
        return(0);       
      }
      if (lastorder == 1)
      {
      Print("Gegenposition Buy");
      ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 2,Ask - (STOPLOSS*Point), Ask + (TAKEPROFIT*Point), "abgescihert", mymagicnumber);
      if(ticket>0)
        {
        if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
        }
        else Print("Error opening BUY order : ",GetLastError());
        return(0);
          
      } 

   }