Modify pending order after condition met once
-
Hi, I would like to seek guidance on how to setup below instruction.
Flow:
- Condition: MA crossover occurs
- If condition in step 1 is met, it waits until the next candle to form.
- If the next candle closes below previous candle, we place a buy stop order above the high this candle (which just recently close).
- If the next candle after this candle closes below again, it will modify the buy stop order to the above of this new candle.
- If this modification occurs 3 times, then the trade setup becomes invalid (It won't modify for the forth time). It will look for another trade setup.
This is my current project (for buy only):
https://fxdreema.com/shared/PXr8vAete
It is incomplete because I am stuck on the mainly 2 problems:- I wish to know how to modify a pending order when the next candle formed after a condition is met once.
Besides that, I am referring to another similar post in fxdreema when making this EA. This is the post:
http://fxdreema.com/forum/topic/7364/pending-order-adjust/8
My situation is similar to this post but my condition only need to be met once. In my case, its the MA crossover. - Is there a way to limit the number of modification? In my case, I wish to limit to maximum 3 modification only.
I am newbie to fxdreema. I am still learning how to workaround it. Would appreciate it if someone can shed some light on my problems. Sorry, my English isn't good, please let me know and i will clarify on anything that is unclear.
-
This is the illustration of the strategy:


-
@darrow The first problem I see is that MA crossing will never be really confirmed until a new candle is created. That means your Buy stop and Stop Loss proces will not be available until an additional candle is closed. Is that what you want?
-
@l-andorrà Thank you for your reply. I have updated the pic again to add in candle #2,1,0.
The buy stop and stop loss will be placed on candle #1. Hope this explains the matter.
-
@darrow Ok. This is more clear now. So if I understand it corectly you need to modify both buy stop and SL levels every tiem a new candle is complete. Right?
About limiting how many changes are accepted, you will have to create a counter variable and add plus 1 to it every time a modification is done. I guess you are not using variables often. Rught?

-
@l-andorrà Yes, I want it to modify buy stop and SL if candle's high closes below previous candle's high.
You are right. I am still familiarizing with the logic and how to use Fxdreema. I have found bits and pieces info from other Fxdreema forum posts but couldn't find one related to my topic.
As a start, to limit the number of changes, do I start building the block in the "on Trade" event, instead of "on Tick"?
-
@darrow No you need to update all that info. This is why you need to do it on the 'on tick tab' with a variabla and a constant. Try this:
-
@l-andorrà Thank you for showing me the way. I can understand how your example works. Just delete those orders that aren't triggered at every start of bar and start a new order after that.
This is my updated project:
https://fxdreema.com/shared/RPbeu7iecDuring the testing, I noticed that it didn't modify the order when the candle closed lower than previous candle. I believe the reason is due to MA crossing being dynamic.
When the order didn't get triggered and deleted at the start of new candle, the condition for MA crossing at candle ID #2 is not valid anymore. This time, the MA crossing has shifted backward to be candle ID #3.
How do I fixate on the MA crossing while the deleting/opening (modifying) new order for at most 3 times? I have found other post in the Fxdreema forum, in this kind of situation, do we use flags?
-
@darrow I don't see why it shouldn't work in that situation. Do you have any visual example to share, please?
-
@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 Ok. I see. In that case what you need is to specify that MA5 is above MA 20, and not that crosses above. That way a new pending order will be created as you want.
-
@l-andorrà However, what I wanted is MA 5 crossing above MA 20, not MA 5 being above MA 20. This is the condition. I want this condition be fixed as I will be using it as reference to modify the buy pending order later on. I hope this clarify one of my conditions.
Perhaps this can be done is:
- Check if any MA crossing occurred
- If yes, raise flag
- Check if flag is raised
- If yes, check for pullback candle
- If yes, place buy pending order
- If buy pending order triggered, reset flag
- If buy pending order not triggered, delete pending order
- Repeat Step 4 to Step 8, repetition to be capped at maximum 3 times
I haven't explored the flags feature. Do you think it can be done this way? Or maybe there is an easy way? =P
-
@darrow You don't need any flag.
Yes, the crossing is the initial point for your EA to consider if ALL OTHER conditions are true. So you just need to know if both MA are in the correct position. If you do that you can be sure that there was a crossing sometime before. And that is all you need. Look at it this way:- Was there a crossing in the past? Yes.
- Are both MA in the correct position? Yes
- Are high/low levels of candle ID 1 in the correct position compared to candle ID 0? Yes
- Launch pending order.
Easy, isn't it?

-
@l-andorrà I wish to clarify and align again. I want the pullback candle to occur right after the cross, not somewhere after the cross happened.
For example, cross occurred at candle ID #2, if pullback candle occurred at candle ID #1 then place pending order. If they are not connected, then it’s not a valid setup.
Are we on the same page?

-
@darrow Yes, we are. Then your EA is correct. The problem is when it considers the crossing happened. You and me see the crossing 'between' two candles, but an EA just 'sees' once it is complete. In your example, this means it was confirmed once candle 3 was complete, but due to the 'Once per par' block, that is not detected until the opening of candle 2.
If you don't want that, you can remove that block but then you can get dozens of trades on the same bar.
-
@l-andorrà Thank you for getting back. I would not want to have many trades on the same bar either. Is there another way around? or perhaps that is out of the capability of this builder.
-
@darrow You can always limit the masumim number open open trade by using a 'Check trades count' block on top of your block tree.
-
@l-andorrà Sorry to get back to you late. I have tried the 'check trade count' method. What happened is that the EA opens and deletes the orders within candle #1 timeframe until the beginning of candle ID#0. It supposed to keep on opening and deleting in candle #0 timeframe.
Candle #1 timeframe: 9:00 - 9:15
Candle #0: 9:15 - 9:30I am reusing this picture to indicate which candle is candle ID #1 and #0

Actual screenshot:

The result:
The result shows that the ‘opening & deleting' process ended at the beginning of candle #0

-
@darrow Can you please share your project?
-
@l-andorrà This is my project:
https://fxdreema.com/shared/t5kgu1DId