Help on coding EA

 

Hi there,


I need to make a change on a simple expert advisor that is based on 2 slope direction lines.

This lines, changes to blue when on uptrend and red when on downtrend.


The expert advisor gets a global variable=1 when both uptrend (2 slope=blue) and a global variable=2 when both on downtrend (2 slope=red).

When global variable=1 the ea opens a position BUY, when global variable=2, the ea opens a position SELL.


The problem is that when the profit is reached, it closes the position but if both signals are still there, it opens an additional position. For instance, I am on a position BUY when both slopes are blue with a profit targer=20. When 20 pips are reached, the position is closed BUT IF BOTH SLOPES ARE STILL BLUE, it opens another position...


Can anyone help me with a code that does not open a second position like this? I want to be able to open several positions for the same currency pair, but not when one of them is closes.

I need something that creates a second global variable that after a position is closed it adds a value to it that will be also compared when both slopes gets with the same color, and besides the BLUE / RED conditions it also tests this global variable.


I have been thinking on the following:

- Both slopes becames RED;

- EA opens SELL;

- Second variable gets the NoOpenCondition=TRUE;

- When the position reaches its profit target (or stoploss) it is closed;

- The advisor waits for NoOpenCondition = FALSE and from this moment it waits for a new signal for potential positions.


This NoOpenCondition can be tested by waiting that at least one of the slopes became on the oposite color and when they get the same color again it is a moment for new positions.


Hope you can help me


Best regards


Paulo

 

is hard to 'see' code and make valid comment. ie, no matter how much talki talki, code is best medium for comment

can you attach code?

Best