MQL4 Learning - page 101

 

ea correlation - HELP

hello,

I'm not a programmer, this is a start and I hope someone help me finish it or show me where I can finish it. This EA is based on the opening of two positions on two related pairs and to achieve a total profit x is closed and reopened.

I tried on a broker but I open up infinite positions mergini exhausted.

Who can help me please?

Thank you all.

Files:
 
mbforex74:
hello,

I'm not a programmer, this is a start and I hope someone help me finish it or show me where I can finish it. This EA is based on the opening of two positions on two related pairs and to achieve a total profit x is closed and reopened.

I tried on a broker but I open up infinite positions mergini exhausted.

Who can help me please?

Thank you all.

i belive i did an ea for this as well or very close to it and uploaded at "Hedge EA" thread see if that helps. There are more ea on that thread use what helps u most.

-guyver

 

get last order direction

Hi

is there a command for an ea to get the direction (buy/sell) of the last closed order? like GetLastOrderDir(0,0) or something?

thanks in advance

 
surfer90:
Hi

is there a command for an ea to get the direction (buy/sell) of the last closed order? like GetLastOrderDir(0,0) or something?

thanks in advance

Not exactly with GetLastOrder() but instead you would need to check with Order History .. ( orders which are closed and available in history of the terminal )

-guyver

 
Stiffler:
I must apologize, I have no idea what you directed me to do. I've attached two indicator ex's to help explain what I'm trying to do. I can't seem to only get the MA's bars to show up on the grid instead of the blue boxes and red and green verticle lines.

have u found any other indicator for the above?

 
Guyver:
Not exactly with GetLastOrder() but instead you would need to check with Order History .. ( orders which are closed and available in history of the terminal ) -guyver

okay and how would i do that?

 
surfer90:
okay and how would i do that?

ahh i see.. well it not one line code

You will need to use looping to go over the OrderHistoryTotals() to get total number of orders in History ( see mql help file for OrderHistoryTotal() usuage ) which is very similar to OrdersTotal().

e.g int x = OrdersHistoryTotal()...

then inside that loop check all the orders using the OrderSelect Statement

see the mql4 reference for OrderSelect statement

for e.g OrderSelect()

Once that is done use the OrderType to find out what was the last order etc

use the mql4 reference to read more about the OrderType() and other commands ..

There you go one way to achieve your goal .. this could be a good research for you this is why i didn't write the code

-guyver

 
Guyver:
Not exactly with GetLastOrder() but instead you would need to check with Order History .. ( orders which are closed and available in history of the terminal ) -guyver
Guyver:
ahh i see.. well it not one line code

You will need to use looping to go over the OrderHistoryTotals() to get total number of orders in History ( see mql help file for OrderHistoryTotal() usuage ) which is very similar to OrdersTotal().

e.g int x = OrdersHistoryTotal()...

then inside that loop check all the orders using the OrderSelect Statement

see the mql4 reference for OrderSelect statement

for e.g OrderSelect()

Once that is done use the OrderType to find out what was the last order etc

use the mql4 reference to read more about the OrderType() and other commands ..

There you go one way to achieve your goal .. this could be a good research for you this is why i didn't write the code

-guyver

to be honest with you: i am realy not good at coding, i just found an ea that might work out pretty well if this function would be included. so if you know the code, please just tell me, because i would already fail at trying to make a loop.

thanks in advance

 

you could have atleast tried or lied . anyways i just wrote it here now should be fine change what is needed

it is a function so copy the whole thing

-guyver

string GetLastCloseOrder(){

int cnt = 0;

for (int i = 0; i < OrdersHistoryTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false)

{

Print("Error in history!");

break;

}

cnt = OrderType();

}

if(cnt == 1 ){ return ("SHORT");}

if(cnt == 0 ){ return ("LONG");}

}

This function will bring the string back you can change it to whatever you need,,,

 
Guyver:
you could have atleast tried or lied . anyways i just wrote it here now should be fine change what is needed

it is a function so copy the whole thing

-guyver

string GetLastCloseOrder(){

int cnt = 0;

for (int i = 0; i < OrdersHistoryTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false)

{

Print("Error in history!");

break;

}

cnt = OrderType();

}

if(cnt == 1 ){ return ("SHORT");}

if(cnt == 0 ){ return ("LONG");}

}

This function will bring the string back you can change it to whatever you need,,,

oh yeah, exactly what i was looking for =) thank you very very much, you realy helped me bigtime! big ups for you! keep up the good work!

Reason: