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

MichaelMano

Recruit
Messages
4
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//
------------------------------------
int TradeEntry(int Type){

if(Type == 0){

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

if(OrderSend(Symbol(),OP_BUY,0.1,Ask,10,BSL,BTP,NULL,0,0,clrBlue)){
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){
if (TradeEntry(0)){
Print("buy Trade Sent successfully");
}
else{
Print("Buy order sending failed");
}


}


if(remain==1&& Bid< MdValue && OrdersTotal()==0){
if (TradeEntry(1)){
Print("Sell Trade Sent successfully");
}
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") ,

thanks for your help
 

Attachments

  • 2da56797bd870bec9241351820b8f1b3.png
    2da56797bd870bec9241351820b8f1b3.png
    85.6 KB · Views: 11
  • Chart (1).PNG
    Chart (1).PNG
    75.6 KB · Views: 12
  • Sell (1).PNG
    Sell (1).PNG
    45.1 KB · Views: 11
Back
Top