call a function

 

Hi all,

 

Is that possible to call a function from another function. What I mean is, if inside a void function I want to call another void function is this possible ?

 

thanks for any clue here

Luis 

 
luisneves:

Hi all,

 

Is that possible to call a function from another function. What I mean is, if inside a void function I want to call another void function is this possible ?

Yes,  of course.
 
RaptorUK:
Yes,  of course.


Hi RaptorUK,

 Thank you for your prompt attention to my issue.

 While the question seems to be of an obvious way to conclude the reason why I ask have to do with this,

 

Say that I have two buy orders open and then a sell open

when sell gain is more than 0  a trailing stop line (stoploss) comes and from there if sell continues to gain there is no need to maintain those buys open (all open orders will close when the sell close by trailingstop)

so, if one can introduce a way to close the orders that are in loss (considering that the trailingstop is already in place) and from there only the orders that are in profit continue to roll at the close we will have more gains.

so I have one block of code that receive the information when the profit is more than 0 and start to identify what orders have their OrderProfit() less than 0 and then call a block of code to close those ones right way.

From there only orders that are keeping their gain above 0 continue rolling till the moment they are closed  by mean of trailingstop.

The issue is that I can't see if those orders that are in loss are closed before the ones that are in profit because in history they seem to close at the same time. 

 
luisneves: The issue is that I can't see if those orders that are in loss are closed before the ones that are in profit because in history they seem to close at the same time.
Then your code is closing all the orders, not just the ones in loss. Post your code.
 
WHRoeder:
Then your code is closing all the orders, not just the ones in loss. Post your code.

Hi WHRoeder,

Thank you to keep your attention to my post.

In attach is the file you kindly requested.

Thank you in advance for your support

Luis 

 
  1. int GetTicketFromHistory(string sym,int mn,int orderposinhistory=0){
       int ticket,count=1,i;
       datetime orderclosedates[];
       for(i=OrdersHistoryTotal()-1;i>=0;i--)
       :
       if(ArraySize(orderclosedates)>0) <--- use if(count > 1) instead.
    
    Arrays are like static, they will not reset to zero size. You should rewrite that as count should be zero initially and increment after resize/insertion. Or use my code.
  2.       if(SellStopLoss > 0 || SellTakeProfit > 0)
             {
             OrderModify(SellTicket,OpenPrice,SellStopLoss,SellTakeProfit,0);
             }
    
    What are Function return values ? How do I use them ? - MQL4 forum
  3. Always count down. Loops and Closing or Deleting Orders - MQL4 forum
  4.  void IdentifyOrderInLoss()
                  {
                   int OrderLoss;
                    
                     for(int OrderInLoss = OrdersTotal()-1; OrderInLoss >= 0; OrderInLoss--)       
                        if(OrderSelect(OrderInLoss, SELECT_BY_POS, MODE_TRADES)
                           && OrderMagicNumber()== MagicNumber 
                           && OrderSymbol()== Symbol())                                                    
                        {//31
                         OrderLoss = OrderProfit();
                        }                                       
                        if(OrderLoss < 0)CloseAllInLoss();               
                    }//32               
    
    This is supposed to close all in loss if any are in loss. A) if the 0 position order is in profit, OrderLoss will be positive, and nothing gets closed. B) IdentifyOrderInLoss doesn't identify anything, it closes all order if any is in loss. Rename it.
     void IdentifyOrderInLoss(){
                     for(int OrderInLoss = OrdersTotal()-1; OrderInLoss >= 0; OrderInLoss--)       
                        if(OrderSelect(OrderInLoss, SELECT_BY_POS, MODE_TRADES)
                           && OrderMagicNumber()== MagicNumber 
                           && OrderSymbol()== Symbol())                                                    
                        {//31
                        if(OrderProfit() < 0 ){ // Found one in loss
                           CloseAllInLoss();    // Close all
                           break; }             // break or return, since there are none left
                        }                                       
                    }//32               

  5. Then your code is closing all the orders, not just the ones in loss. Post your code.
    What is the difference between CloseAll() and CloseAllInLoss()? Nothing! It closes ALL open orders.


 
WHRoeder:
  1. Arrays are like static, they will not reset to zero size. You should rewrite that as count should be zero initially and increment after insertion. Or use my code.
  2. What are Function return values ? How do I use them ? - MQL4 forum
  3. Always count down. Loops and Closing or Deleting Orders - MQL4 forum
  4. This is supposed to close all in loss if any are in loss. A) if the 0 position order is in profit, OrderLoss will be positive, and nothing gets closed. B) IndentifyOrderInLoss doesn't identify anything, it closes all order if any is in loss. Rename it.

  5. Then your code is closing all the orders, not just the ones in loss. Post your code.
    What is the difference between CloseAll() and CloseAllInLoss()? Nothing! It closes ALL open orders.



Hi WHRoeder,

Thank you so much to get a look to the code and for advice.

In point 5 you say " What is the difference between CloseAll() and CloseAllInLoss()? Nothing! It closes ALL open orders. "

Do you mean that with the code I want to introduce do not have any advantage ?

Best regards

Luis 

Reason: