Tracking Order trigger

 

Hi Guys,

I have 4 Short and 4 Long conditions in a single EA that are working fine. Orders are opening , now here is my questions.

Is there a way i can assign a unique identifier to every position that opens so i can track source logic of that order. so that i may tweak individual conditions more?


Thnaks

 
AdnanSyed: I have 4 Short and 4 Long conditions in a single EA that are working fine. Orders are opening , now here is my questions. Is there a way i can assign a unique identifier to every position that opens so i can track source logic of that order. so that i may tweak individual conditions more?

You don't need to "assign" anything. All orders (and positions and deals) already have a unique identifier attached to them. It is called a "Ticket", which you can retrieve and use as an ID for that particular order (or position or deal).

You can also assign and use a common "Magic Number" to group them so that you can identify and separate them from other EAs or instances of the same EA.

 
Fernando Carreiro:

You don't need to "assign" anything. All orders (and positions and deals) already have a unique identifier attached to them. It is called a "Ticket", which you can retrieve and use as an ID for that particular order (or position or deal).

You can also assign and use a common "Magic Number" to group them so that you can identify and separate them from other EAs or instances of the same EA.

Hi Fernando, 

Thanks for the reply.

getting position info is not the issue.

my EA has total 8 if statements. I am trying to see what position was opened by what if statement. so i think if every if statement can add a unique number or code to every order opened i will be able to track the performance of the logic thats working.  

 
AdnanSyed:

Hi Fernando, 

Thanks for the reply.

getting position info is no the issue.

my EA has total 8 if statements. I am trying to see what position was opened by what if statement. so i think if every if statement can add a unique number or code to every order opened i will be able to track the performance of the logic thats working.  

I already stated that you don’t need to add anything. You already have a ticket number so just use that to track it. Alternatively use a different Magic Number for each subgroup.

Is this MT4 or MT5?

Post your code if you need more specific explanations!
 
Fernando Carreiro:
I already stated that you don’t need to add anything. You already have a ticket number so just use that to track it. Alternatively use a different Magic Number for each subgroup.

Is this MT4 or MT5?

Post your code if you need more specific explanations!

MQL 5

Sample Code

if (RSI > 20  && ADX > 50)

            {

               signal=SIGNAL_BUY;

            }

if(signal==SIGNAL_BUY)

        {

         double price      = PRPR;

         double sl         = SLSL;

         double tp         = TPTP;

         //---

         if(trade.Buy(lotsize,NULL,price,sl,tp,NULL))

 
AdnanSyed: MQL 5

Sample Code

Unfortunately your sample code does exemplify nor explain what you are trying to do. However, after placing the "trade.Buy", you should be checking the result of the trade request with ResultRetCode() and then obtaining the Deal ticket with ResultDeal() which you can then use to track it and obtain further information.

 
to see which if conditional opened the position,you can add an comment to the order so you can identify each one.
 
Bilal Said: to see which if conditional opened the position,you can add an comment to the order so you can identify each one.

You should not rely on Order Comments at all as brokers can easily change them or even remove them completely! So why suggest such a limited solution when there is already the Ticket Number and/or Magic Number that is the correct way to implement it and is guaranteed to work every time on every broker?

 
Fernando Carreiro:

You should not rely on Order Comments at all as brokers can easily change them or even remove them completely! So why suggest such a limited solution when there is already the Ticket Number and/or Magic Number that is the correct way to implement it and is guaranteed to work every time on every broker?

Can you explain me how knowing the ticket number of each position will help him to know which if opened it?
Using comment is the fast way to do it without modifying the logic of his ea. 
The best way is magic number off course. 

Edit: now I have seen your comment about ticket.
 
Bilal Said:
to see which if conditional opened the position,you can add an comment to the order so you can identify each one

and thats exactly the question brother, 

I know a comment can be added to order using positionGetXX command. 

if (x=y)  // LOGIC 1

 signal=SIGNAL_BUY;

if (x+1>y-1)  // LOGIC 2

 signal=SIGNAL_BUY;


Position is opened using function below by one of the logic above


if(signal==SIGNAL_BUY)

        {

         double price      = PRPR;

         double sl         = SLSL;

         double tp         = TPTP;

         //---

         if(trade.Buy(lotsize,NULL,price,sl,tp,NULL))


NOW all i am trying to do is after a position is opened and after its closed either by TP or SL; in the report you can see the reason a position was closed TP or SL. 

i just need to know which logic 1 or 2 opened the position.  

 
If you only want to see it in the report, you can just add a comment on the order request.
Reason: