Help with loop module
-
Hi,
I was hoping someone could help me, please.
I have created an ea that places an order on every new bar.
The order is placed 4 pips up from the open bar price. when that price is met, a buy trade is opened with TP of 16 pips and the SL of 4 pips (SL level is the same as open bar level)
When the TP is hit, the trade is over and nothing else happens. The order is cancelled if the price goes down 20 pips from the open bar price This is simple.
Bar opens, the pending order is placed 4 pips up. When the price goes 4 pips up from bar open, trade is opened. Thereafter when the price goes 4 pips down from trade open, SL is hit.
I am not experienced and so I tried the loop module, the trade does not place one order each time, it places many. What am I doing wrong?
-
It´s always worthy to share the project (mqX file or, at least, one screenshot) in order to look at the project´s logic instead of the compiled file.
Questions:
-
EA opens a pending order on Candle ID = 0 but the trade does not open because the trigger level is not reached. What do you want to do when a new bar opens: place a new pending order (you will have 2 and so on) or remove the previous one and open a new one (you will have just one)?
-
EA opens a pending order on Candle ID = 0 and trade opens. What do you want to do on when next bar opens: open a new pending order or do nothing while a trade is live?
Those questions are important for the EA´s logic.
-
-
0_1598078671063_WALKER EA buy 2020:08:21 3.mq4 !

Hi Thanks, I have attached my MQ4 file and screenshot.
-
EA opens a pending order on Candle ID = 0 but the trade does not open because the trigger level is not reached. When a new bar opens: place a new pending order (I will have 2 and so on). Do not remove the previous order. This is continuous regardless of how many orders or trades might currently be open. (I know there will be many pending orders and trades open at once, but that's the strength of this strategy.)
-
EA opens a pending order on Candle ID = 0 and trade opens on the trigger level. When the next bar opens: open a new pending order regardless of how many might currently be open.
Thanks
-
-
0_1598079909692_WALKER EA buy 2020:08:22.mq4

Please see my updated mq4 and screenshot. I adjusted the Buy Pending Order parameters to what I initially intended.
-
If you don´t mind how many pending orders are placed or how many trades are live, your logic regarding to blocks "Once per bar" and "Buy pending order" looks correct. When a new bar opens, a "Pending order" is placed.
In relation to what happens with running trades, I would suggest that you give a try this

The logic would be: if a trade is closed by "Stop Loss", a new perding order will open at "Ask" price. In other case (TP hit), nothing will happen. This part of the project is placed in "OnTrade" tab.
-
Can you please share your project
-
@josecortesllobat said in Help with loop module:
In other cas
Thank you for this. It never occurred to me to use 'on trade'.
-
My example was cretaed in MQL5. There are blocks with different name between MQL4 and MQL5.
Yes, you can use both tabs. "OnTick" code is executed when a tick arrives while "OnTrade" regards to position/trade.
Not sure. You will have to check it out by running a backtest in Tick mode to be sure that works as you expect.
-
Thanks for your help, I'll try it out.