Modify pending order after condition met once
-
@darrow You are requiring the MA crossing happening specifically between candle 2 and 3. As new candles are formed, the crossing condition will never be true. In your previous image you wanted that at the opening of candle ID 0 a new pending order was programmed at candle ID 1's high. At that moment, the crossing happenend betwqeen candles 3 and 4.
Can you see now why it will never work? You need to liberate the crossing condition from the high/previous high condition in order to get future pending orders.
-
@l-andorrà Sorry, it seems that I am back to circle again. I noticed this problem back then and I said in below post.
The MA crossing is dynamic. This means that, for every new bar is formed, the occurrence of crossing is shifted back. How do I make it such that the crossing is fixed as reference? I want that the condition (crossing) to be met once then take action (either open new order or modify order).
@darrow said in Modify pending order after condition met once:
@l-andorrà Below is the updated project. I only changed the buy pending order offset to zero for easier visualization.
https://fxdreema.com/shared/TyrVeu5ubExample:

The EA is placing the buy stop order and SL correctly after it detects the MA crossing between candle #2 and 3 as well as a followup pullback candle #1.After 1 candle bar later:

After 1 candle bar later, the buy stop order did not get triggered and was then removed. The EA should place a new buy stop and SL to the new candle #1. However, the EA did not place any order.I believe this is because the MA crossing condition is not met. After 1 bar later, the MA crossing now occurred between candle #3 & 4 while the EA is tasked to check if there is MA crossing occurring between candle #2 & 3.
More info:
Currency pair: EURUSD
Timeframe: 15 min
Time occur: 2020/01/16, between 9 - 9.15AM
Below shows that there is no new order after the deletion.

I hope this helps explaining my obstacle

-
@darrow Use a boolean variable. When the crossing is confirmed, move that variable from false to true. Then you can use that as a condition block previous to your other conditions. As far as that crossing condition is true, no matter how many new candles are formed, it will still be true for all the other ones.
Then don't forget to change it to false again when a reverse crossing happens.
-
@l-andorrà Thank you for the solution. I am definitely on the right track now.
This is my current project, with boolean variable implemented:
https://fxdreema.com/shared/uDRvr9FzbWhen MA cross + pullback occurred, variable 'MA cross' gets modified to 1
When there is a trade detected or more than 3 modification of pending order occurred, variable 'MA cross' gets modified back to 0It works now, at least it did what I wanted this time.
Result:


However, there are 2 hiccups:
- From the table of results, the next buy order was opened at timing 09:18. I was expecting it open the buy stop order at timing 09:15.
- After the trade was closed due to hitting SL at timing 09:28, the EA immediately opened another buy stop order at that same timing. I thought variable 'MA cross' would be turned 0 when there is a trade detected.

-
@darrow You need to reinitialize that variable to 0 again when a reverse crossing happens. And you also need to connect block 27 between blocks 21 and 28. You want both conditions to be true at the same time.
-
@l-andorrà This is my updated project:
https://fxdreema.com/shared/oKcYdYsQcIs this what you mean by reverse crossing? For my case, I set the variable 'MA cross' to 2 when 20 MA crosses below 5 MA (the opposite condition for selling setup).
Or do I have to set it to 0?
As for the connection between block 27, 21, 28, I only need one of the conditions to be true to reset the variable:
- When there is trade
- When 'change' = 'max change'
Note both variables 'change' and 'MA cross' are reset to zero here
For example, buy stop may have been triggered before the 'max change' is reached.
Or buy stop is not triggered but 'max change' reached
Please correct me if I am wrong here. -
@darrow I'm a bit lost now. According to block 18, MA_cross must be 1 for a pending order to be prgrammed. Why that same variable need to be modified to 2? What I suggested is that its current reinitialization to value 0 should be modified, but this whole new structure befuddles me. What do you exactly need?
-
@l-andorrà All the while, I am using a buy setup as an example. The reason I set 'MA_cross' to 2 because I am going to use the same variable for selling signal.
This is the updated project:
https://fxdreema.com/shared/5sVJ5wWeb
I have added mirrored condition for sell setup.
So when 'MA_cross' = 1, buy signal triggered
When 'MA_cross' = 2, sell signal triggered
When 'MA_cross' = 0, waiting for waiting to MA cross to happen (either buy or sell)
I should have added this portion in my previous project. I apologize for the confusion. -
@darrow That looks much better. If I understand it correctly, now it works. Right?
-
@l-andorrà The logic seems alright but it still did not work out the way i want it. My project:
https://fxdreema.com/shared/ZPsLbKjAbIn this example: Selling signal detected at 2020.01.16, time 03:00
-
Expectation: The EA to open an sell stop order based on previous low.
Reality: The EA opened an sell position instead.

-
Expectation: There should not be any more sell order to be created after the sell position at 03:00. According to 'If trade' logic, the variable 'MA_cross' would have been turned to 0.
Reality: The EA still opened a sell stop order/sell position as if 'MA_cross' is still in value 2.
2 sell order/sell position opened, as shown.


-
-
@darrow Your points
-
Look at the open price compared to the pending order price. They are too close, so the platform simply opened it due to spread.
-
I recommend you to change your MA_cross variable with two boolean variables (true/false). One for buys only and the other one for sells only. This way you will get a yes/no action for your requirements and they wil be easier to track if not working properly.
-
-
@l-andorrà Thanks for your recommendation. I have changed the MA_cross variable to two boolean variables, namely 'MA_cross_buy' and 'MA_cross_sell'.
This is the updated project:
https://fxdreema.com/shared/WjmtonxDbFor point 2, I have tested the EA and I get the same outcome.

I believe this is because variable 'MA_cross_sell' is not able to be reset back to 'false' after the 'if trade' condition is met.The EA bought at 03:00 and closed with SL at 03:12. There is a 12 mins window for the EA to detect any trade (the 'if trade' condition) and then reset the 'MA_cross_sell' to false.
This is quite odd. What do you think could be causing the error here? -
@darrow You need to specify that when MA-cross-buy is true, at the same time, MA-cross-sell is false. You can do that just adding the other variable inside blocks 17 and 31. Just use another slot insode them. That way you wil be sure that a buy can be done and a sell will never be done until a reversal crossing happens. Onviously you will have to opdate the positions of those variables accordingly.