Download MetaTrader 5

How do you call a function from within a second function? Online help is not cutting it

To add comments, please log in or register
nadiawicket
397
nadiawicket  

Hello, Im just almost done coding my EA and am really happy about it, however I am unable to select a function within inside of a second function in this EA, and this is preventing me from finishing my EA.


Heres the EA. I just need to select the second opened sell order after the first one, so as to be able to select the latest opened sell order (using datetime) that is currently active.


I need to be able to open 2 different sells consecutively manually, and then have the EA decipher which is the latest in time.

I then need to be able to select the Order Ticket of this order and I'm finally done. 


The internet is not so specific with mql 4; there are no concrete examples that could get me through this in the documentation.

How can I change the actual code in actual EA that is attached to this message so that it does exactly this? This can be done, I assume as the documentation states that it is possible. I'm breaking my head here for a 2 min explanation and its been like 2 weeks already, big headache.


Normal OrderSelect does not cut it because I need to select the last opened in time, not just the index number in the Order Select function.


Thanks a million for real.

Files:
nicholishen
916
nicholishen  
nadiawicket:

Hello, Im just almost done coding my EA and am really happy about it, however I am unable to select a function within inside of a second function in this EA, and this is preventing me from finishing my EA.


Heres the EA. I just need to select the second opened sell order after the first one, so as to be able to select the latest opened sell order (using datetime) that is currently active.


I need to be able to open 2 different sells consecutively manually, and then have the EA decipher which is the latest in time.

I then need to be able to select the Order Ticket of this order and I'm finally done. 


The internet is not so specific with mql 4; there are no concrete examples that could get me through this in the documentation.

How can I change the actual code in actual EA that is attached to this message so that it does exactly this? This can be done, I assume as the documentation states that it is possible. I'm breaking my head here for a 2 min explanation and its been like 2 weeks already, big headache.


Normal OrderSelect does not cut it because I need to select the last opened in time, not just the index number in the Order Select function.


Thanks a million for real.


So, two things...

First, you can't ever assume that your Orders are sorted. Second, both functions are literally comparing the same order so order open time of one function will always equal the other, always.

nadiawicket
397
nadiawicket  
nicholishen:

So, two things...

First, you can't ever assume that your Orders are sorted. Second, both functions are literally comparing the same order so order open time of one function will always equal the other, always.


 What is the correct methodology then? Sort out orders.  What exact steps are you talking about with as much details as you can so I can get this done asap plz?  

Words can mean many different things, if you dont gimme some code, we can't even talk programming right. I appreciate your time however.

Can you please, in code terms. tell me how to call a function from a different function as per the EA in attachment?


So you suggest creating an array with all the order tickets and then having it be sorted out with array sort. Then I would need to also sort this array out by datetime, so I should then add the Open Order Time to the second set/series of the array (create a multidimensional array instead of normal one at the start for this) and sort them out by that after I get the right Order Tickets? This would be perfect, however MQL is so weird. Would this method work confirmed? Actually works like that? Does it ? Then say something like array[1] (which would be latest the order open time) = OrderTicket() somehow? Ive tried everything. I thought there had to be a way that does not involve messing with arrays. 

Thanks a billion Ill get this done someday. .
nicholishen
916
nicholishen  
nadiawicket:

 What is the correct methodology then? Sort out orders.  What exact steps are you talking about with as much details as you can so I can get this done asap plz?  

Words can mean many different things, if you dont gimme some code, we can't even talk programming right. I appreciate your time however.

Can you please, in code terms. tell me how to call a function from a different function as per the EA in attachment?


So you suggest creating an array with all the order times and then having it be sorted out as in array sort? I thought there had to be a way that does not involve creating an array. 


It's not really clear what you want to accomplish, both your written description and your code is rather nebulous. If all you want to do is select the most recent order by open-time then this will do.

#property strict

#include <MQL4OrderPool.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
    MQL4OrderPool orders();
    orders.Init(Symbol(),0,MODE_TRADES,ORDERS_FILLED,SORT_OPEN_TIME_DESCENDING);
    if(orders.Total() >= 2)
    {
      printf("There are %i open orders and I have selected ticket number %i the most recently opened order.",
      orders.Total(),orders[0].OrderTicket());
    }
}
//+------------------------------------------------------------------+
Files:
nadiawicket
397
nadiawicket  

Cant just call from a call?

nicholishen
916
nicholishen  
nadiawicket:

Cant just call from a call?


You are calling from a call, but your calls are selecting and comparing the (literal) same.exact.order.

nicholishen
916
nicholishen  

This is what you're doing.

int num1()
{
   return 1;
}

bool num2()
{
   if(1>num1())
      return true;
   return false;
}
Always false;
nadiawicket
397
nadiawicket  
nicholishen:

You are calling from a call, but your calls are selecting and comparing the (literal) same.exact.order.



OK ill check out your previous answer, awesome. Ive never worked with an MQH before, Ill sort this out though hopefully. 

nadiawicket
397
nadiawicket  
nicholishen:

This is what you're doing.

Always false;
OK lemme see this must be a very simple thing I am not doing right then
nicholishen
916
nicholishen  
nadiawicket:

OK ill check out your previous answer, awesome. Ive never worked with an MQH before, Ill sort this out though hopefully. 


How do you have it select a different order then? As per your mqh?


The [] is overloaded so you access the order and order properties like an object array. For example, 

Print("The order profit of the second order on array is ",orders[1].OrderProfit());
nadiawicket
397
nadiawicket  

You have been extremely helpful. I had never had such fast replies to a forum posting. Thanks a lot. However I need to be more specific:

"You are calling from a call, but your calls are selecting and comparing the (literal) same.exact.order."

This is why I am using the following code to only select and assign to the secondsellopentime variable when the OrderOPen Time is larger than the order time collected by the previous function.

Why is this code from EA:

         if (OrderOpenTime()>firstsellopentime())
            secondsellopentime=OrderOpenTime();

Not having my desired effect of only selecting the order if its OrderOpenTime() is larger than the previous one?

123
To add comments, please log in or register