# I need help to understand the solution I figure out by chance to problem I had with my code

#### MichaelMano

##### Recruit
I had a problem with the EA that when I used the function created, the EA would execute only the buy orders and for the sell order it sends to the journal the note that I mention in else, for sell execution, but after I deleted the below underlined 2 lines it executed both sell and buy order. I just need your help to understand :
*how the system read the code although it has been compiled correctly, how the system understood my code as to execute only the buy orders
*and why it sent the Print of "else" of sell order not the buy
-------------------------------------
// Below is the function code//
------------------------------------

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;
}

-----------------------------------------------------
//Below is the Ontick section//

----------------------------------------------------
void OnTick()
{
double value = MathRand();
double remain = MathMod(value,2);

double MdValue = iMA(Symbol(),0,MA_Period,Shift,MA_Method,AplliedPrice,1);
double SARValue = iSAR(Symbol(),0,Step,Maximum,0);

if(remain == 0 && Ask>MdValue && OrdersTotal()==0){
}
else{
}

}

if(remain==1&& Bid< MdValue && OrdersTotal()==0){
}
else{
Print("SELL Order Sending failed");
}

}
}
only when I deleted the above underlined 2 lines of else it executed sell and buy
the problem turned out to be in the code of the function that I was trying to create and the problem is sorted out by deleting these 2 line in my code of the function else{return false;} in both conditions if (type ==0) and if ( type ==1) and now the EA is executing the sell and buy.
but I did not understand the logic of the solution and I was just trying to understand how this line (else{return false;} ) affected the code that way that made it execute only the buy orders and why as well it send the note of Print("SELL Order Sending failed") and not the note of Print("Buy order sending failed") ,

#### grow_a_pair

##### Recruit
Hey MichealMano, the TradeEntry function never reached the "if(Type == 1) section of code.

#### MichaelMano

##### Recruit
Thank you so much