return function not working

 
int Decision() {
      if (Dir==0) return(0);  
      if (Dir == 1 && nTrade==2) { openBuy(); return(0); }
      if (Dir == -1 && nTrade==2) { openShort(); return(0); }
      Print(" Testing for mistake");
      if (Dir == 1 && nTrade==1 && TempProfit < 10) { openShort(); return(0); }
      if (Dir == -1 && nTrade==1 && TempProfit < 10) { openBuy(); return(0); }



I have the above code. The return(0) functions seem to be not working. After opening one trade, instead of returning, it goes ahead to next lines and opens another trade (the second set of openings are only if first attempt failed, but it always opens two at once). I tried separating them to another routine and it still did not solve the problem (though it opened the second trades after one minute, which I have to analyze separately). I cannot think of anything wrong here. So, any suggestions will be greatly appreciated.
-chandra

 
return() is not function! It is program statement like if, for, switch, while etc

Insert Print functions to control program flow
 
Hi Slawa,
Thank you for the comments. Using the Print function only I found out that the program ran through the return(0) functions/statements. But, I cannot figure out why/how does it do that and don't know how to make it respect the return(0)s.
-chandra
 
I've checked your source and make sure your code works properly.

Please show your testcases. I suspect You call this function over and over again

Insert
Print("Decision begins");
at the beginning of the function and analyze experts log-file.
 
Hi Slawa,
I call this routine only once from the Start routine. But when in the next round of call after opening a position (during next tick), the call will miss it because it is controlled by open position. The code making the call is:
if(nopen==0) Decision();

My Print function I have included in the first post should not come at the first purchase of a position. But always when one position entry is made, second entry is also made and the Print command comes exactly in between. That showed that the execution went right through the return(0) statement. If it bought a position using {openBuy(); return(0); } it is not possible to go beyond. But it goes beyond and executes the other OpenBuy because the if conditions will be true, because the open positions are not included here (even when I included the open position condition before Print command [ if (nOpen > 0) return(0);] still it did not work!!! It keeps opening two positions. I dont create/check log file, but I see the Print text in the Journal section.
Thanks
-chandra