BigBe
228
BigBe  

Last Trade Problem

I want to avoid taking a trade if a trade just closed UNprofitably in the direction I am considering.

How do I get my EA to check the current and the previous bar to see if an unprofitable trade closed, and whether it was long or short?

(If it closed uprofitably in the opposite direction, that would be OK.)

Show code if you can.

luxinterior
403
luxinterior  
Big Be:
I want to avoid taking a trade if a trade just closed UNprofitably in the direction I am considering.

How do I get my EA to check the current and the previous bar to see if an unprofitable trade closed, and whether it was long or short?

(If it closed uprofitably in the opposite direction, that would be OK.)

Show code if you can.

You would need to search the history. Also check the close time of the order to see if it falls within your exclusion range. Something like the following...

void CheckOrderHistory(){

// orders history is most recent at the bottom

// zero based so OrdersHistoryTotal()-1

for(int i=OrdersHistoryTotal()-1; i > -1;i--){

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

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC_NUMBER && (OrderType() == OP_SELL || OrderType() == OP_BUY)){

switch(OrderType()){

case OP_BUY:

// do something here...

return(0);

break;

case OP_SELL:

// do something here

return(0);

break;

default:

break;

}

}

}

}

richest
129
richest  

request script that closes the last two orders

Hi, I was wondering if you guys could help me on creating a script that enables to close the last two opposite type orders depending on the current orders.

e.g if the current OP is sell, therefore if the script executed then the script will close the last two buy positions made historically according to the time they are opened.

Appreciate all the help I can get, thanks.

paaluu
10
paaluu  

Any News to that ?

This drawdown value is a key number!

Do you had any success for a script / EA that is calculating and storing this value?

@all

The question is not, if the trade was profitable or not.

The question is the maximum negative amount against us accruing during the trade. That is the drawdown.

I am looking for such an EA / script.

fercan
19
fercan  

what's the difference? between

val=High;

and

val=iHighest(NULL,PERIOD_H1,MODE_HIGH,20,4);

will the value be differents every new bar?

Roger09
167
Roger09  
fercan:
what's the difference? between

val=High;

and

val=iHighest(NULL,PERIOD_H1,MODE_HIGH,20,4);

will the value be differents every new bar?

iHighest - it is a number of the bar with Highest price

High - the high price of this bar

fercan
19
fercan  
Roger09:
iHighest - it is a number of the bar with Highest price High - the high price of this bar

Base from my example, what is the different between the 2?

luxinterior
403
luxinterior  
fercan:
Base from my example, what is the different between the 2?

As explained above iHighest will return the shift of the bar with the highest value and High will tell you the actual high value of a bar.

So if the current bar is shift 0 and you ask the iHighest of say the last 13 bars the result may be, for example 9, meaning the 10th bar back had the highest value. Now if you wanted to actually know what the value was you'd need to use the High function.

Good luck

Lux

fercan
19
fercan  
luxinterior:
As explained above iHighest will return the shift of the bar with the highest value and High will tell you the actual high value of a bar.

So if the current bar is shift 0 and you ask the iHighest of say the last 13 bars the result may be, for example 9, meaning the 10th bar back had the highest value. Now if you wanted to actually know what the value was you'd need to use the High function.

Good luck

Lux

ok thanks lux..

Limstylz
198
Limstylz  

Total long and short positions

Hi Everyone,

Can someone please advise me how to programatically find the total number of long positions open and the total number of short postions open in MT4? I do not want the total number of all positions open together. My requirement is that I keep the same number of short and long positions open at the same time. eg:

Lets say I have a user-defined number of trades which are open concurrently, with an equal number of long and short positions. Some short and long positions close. I need to reopen an equal amount of short and long positions up to the user-defined limit.

Thanks in advance