Line cross entry EA to close trade if the lines uncross
-
Hi all,
I have a straight forward line cross EA that opens and closes trades when 2 lines cross.
Occasionally a line cross will momentarily occur, thus triggering a trade and then the lines uncross and continue in the original direction. This leaves an open trade running in the wrong direction.
I would like the trade to close if the lines uncross. Can anyone offer any suggestions how I may achieve this?
-
@johntyr Two quick questions. Are those lines created manually or with a custom indicator? Are those lines trending or horizontal lines? They cannot be horizontal if they cross each other.
-
@l-andorrà They are 2 different cci lines (one fast, one slow) in a custom indicator in window. When they cross a trade is entered. But being fluid the fast line can cross occasionally and then uncross. I need to close if the lines uncross. I can not find anything to help do this, for example as in the' indicator appear', 'indicator disappear' blocks.
-
@johntyr When you say 'uncross' do you mean crossing first and then uncrossing later? If so, what's the point of that?
-
Hi @l-andorrà , thanks for getting back. The line will cross the other momentarily on the same candle, long enough to trigger a trade, and then flick back to uncrossed again.
If the price then continues in it's original direction a bad trade has occurred. I would like to close this trade immediately the line becomes uncrossed to try minimise the loss.
-
@johntyr This raises anew problem. I don't know how to find two lines are crossed in fxDreema. An interesting question. Does anyone know?
-
@l-andorrà This example explains what I mean. The line crosses, triggers a buy trade (as in the condition block attached) and then uncrosses. Crosses are not visible in the picture because of the line repainting.
When the uncross happens, I would like to do something, either close the false trade or reverse.
I cannot find anything in FxDreema to do this. A solution or any other suggestions are welcome.

-
@johntyr You can use a boolean true/false and what for: a) a 'true' crossing, then if b) a 'false' happens within he same candle you can identify there was an uncrossing there.
-
@l-andorrà , Thank you, I did not give that approach a thought. I will set it up and let you know how it goes.
-
@johntyr Sure. Just share your results here, please.
-
Hi @l-andorrà , I have been trying to do what you suggested, not getting very far. I cannot yet get it to work. Project attached:
https://fxdreema.com/shared/JBMSxChyb
Am I heading in the right direction. Also I do not know how to make sure the actions happen within the current only. Your further help appreciated. Thanks.
-
@johntyr I don't understand wht a boolen and a numeric variables are used. They should be exactly the same one. Blocks 13 and 5 can be boolean too. There is no need to create a numeric variable then.
-
@l-andorrà Thank you. Sorry, typo, they were meant to be boolean. https://fxdreema.com/shared/NOD9Dzj9e . This des not not work as is, what do I need to change?
-
-
@johntyr I forgot to ask what happens if more than one crossing/uncrossing happens before the candle is closed? Are ALL uncrossings considered?
-
@l-andorrà Thank you for getting back to me again. All crossings/uncrossings need to be considered. The most I have seen is about 3, which is tolerable.
If possible they should be filtered but first things first. If I can get the reversals happening then I can then try filtering trades later.
The main goal is to stay in the trade with the trend till it gives another reversal. As in the example above the move was correctly entered and moved 800 pips but all of that was a loss because of the pullback and false signal at the beginning.
-
Can anyone help
-
@johntyr Sorry, I forgot to reply. I recommend you the following (I used another indicator because I don't have yours):

Every time a crossing happens, the variable will add +1. If the variables moves from 0 to 1, that means there was 1 crossing, if it moves to 2 this means there was an uncrossing. Then toy can select another condition block to specufy how many 'uncrossings' you need.
Obviously you will need to reinitialize the variable to zero when necessary.
-
Hi @l-andorrà , Thank you for getting back to me. I tried both your suggestions, true/false variables, and the crossing counter variables, and I am getting no where fast. I have attached both attempts. Obviously I am doing something critically wrong as I cannot get either to work. Can you point out the errors I am making. Once again, your help is very much appreciated.
-
Hi @johntyr! I have looked at your code and from my experience I see that you close with the closing block and option BUY or SELL, if in addition to this you differentiate the groups, you may function since the orders will be exclusive, since you do not have your indicator I have not been able to do tests but In the main blocks (57.58.59.60) in the group filter you give it a number identifying them that will also serve as a recurring filter. I hope I have helped you something.

Ah! Important point, although fxDreema has the option of crossing lines from top to bottom and quite the opposite, it is very important to know that since it is based on MQL4 / 5 in MQL4 / 5 there are no crosses, to make or identify a cross what is done is:
- Identify a line and ask if it is greater or less than the other line (refers to price).
- idem to the above.
With this, MQL knows that one line or curve is above the other, now you have to do the same but asking if the upper line or curve is now lower and the opposite with the other. This is what in MQL identifies a cross, as you can see it is a bit chaotic and the problem is when both are in a vertical point, Mql does not recognize them and it is when it gives you a false Yes or No, this must be taken into account. since for your case you should also give width to the crossing area indicating how many candles there must be in one crossing or another.
