I need help to understand the logic of solution for a problem I had while coding a function

I am sorry but I am eager to understand this

The below function is supposed to be buy and sell sending orders that will be executed for EA

The problem is the EA was executing the buy orders only

The solution of the problem was to delete - else{return false;} - in the below code after that it executed both buy and sell but I do not understand why,

would someone help me understand the logic of the solution and how (else{return false;} ) affected the code that way that made it execute only the buy orders

thanks

if(Type == 0){

``````  double BTP = Ask + (TakeProfit *Point);
double BSL = Ask - (StopLoss *Point);

return true;}

else{return false;}                                                 //this line I delete then it executed the selling trades[/u][/u]
``````

}
if(Type ==1){
double STP = Bid - (TakeProfit *Point);
double SSL = Bid + (StopLoss *Point);

``````   if(OrderSend(Symbol(),OP_SELL,0.1,Bid,10,SSL,STP,NULL,0,0,clrRed)){
return true;}

else{return false;}                               //this line I delete then it executed the selling trades[/u][/u]
``````

}
return false;
}

There is no reason I can see why those lines would have done what they did. Maybe there is a bug in the compiler? However your function definition says that it should return and integer and you are actually returning a boolean type instead, maybe that is messing with things?

Out of curiosity, do you have #property strict set?

The whole reason it forces us into that whole if then else construct for order operations is to make us capture error conditions when something fails or we do something wrong. Return terminates the function and returns control to whatever called it. If removing your else return allows it to continue, it makes me suspect an error somewhere. If that’s the case, you should be able to capture it if you change up a little:

``````if(OrderSend(Symbol(),OP_BUY,0.1,Ask,10,BSL,BTP,NULL,0,0,clrBlue))
{

}
else
{
Alert("OrderSend failed, error # ", GetLastError() );
}
``````

If there are any errors with the operation that should spit them out in your journal and make it easier to troubleshoot.
I actually do mine like they show here:

``````int ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,10,BSL,BTP,NULL,0,0,clrBlue);
if(ticket<0)
{
Print("OrderSend for ",_Symbol," failed with error #",GetLastError());
}
else
Print("Order for ",_Symbol," placed successfully.");``````

Agreed. I’m wondering if that or something else is getting thrown into the else condition and returning.