- carlosenrick_: My point is, HOW can i avoid that operation to happen?
Stop making assumptions about the order of events.
carlosenrick_: The YELLOW line shows that the stop loss was triggered, ok, THEN, it should go to TradeTransaction, update the varBlockTradeUntil variable, THEN go back (or async) to OnTick to perform a new Deal or Order like in the RED line.Set your variable when you create the order (onTick). Update your variable when the position closes (onTrade).
Or, on a new bar (onTick) check for a position open before creating a new one.
-
There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
-
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
-
Stop making assumptions about the order of events.
Set your variable when you create the order (onTick). Update your variable when the position closes (onTrade).
Or, on a new bar (onTick) check for a position open before creating a new one.
That's the point, the "logical" process i fully understand, but it didnt go as it usually should go.. let me brief my EA programming diagram..
> Oninit, confirms if inputs are valid, create handles, choose the signal method, etc.
> OnTick:
> refreshrates function
> check if trading is allowed due time filter inputs
> check for new signals (inside that function, signals are generated only when a new bar is born)
> check if theres an opened expert position
> if exists, do the trailing stop, breakeven, whatever's enabled
> if not:
> check if TimeCurrent()>varBlockTradeUntil and allow opening position
> open position since global bool variables "varLongSignal" or "varShortSignal" was setted to true back there
> keep doing that loop.
>OnTradeTransaction: > if theres a DEAL_ENTRY_IN or DEAL_ENTRY_OUT, it setts the varBlockTradeUntil to the TimeCurrent()
SO FAR, everything LOGICALLY speaking is in right place.. but, sometimes it DOESNT give the enough time to work.. because sometimes: the boolean variable for signals and setted to True, and the OnTick accepts to open a new position BEFORE the OnTradeTransaction got the change to update the varBlockTradeUntil
I've tried for far to:
> check if the ontrade got delay for any logical process, but even when i put a AlertFlag right after the OnTrade {} it still printing AFTER the trade was opened
> block signal from being generated if seconds higher than 5, eg: 09:33:06 would skip the signal.
> many other things..
-
Stop making assumptions about the order of events.
Set your variable when you create the order (onTick). Update your variable when the position closes (onTrade).
Or, on a new bar (onTick) check for a position open before creating a new one.
-
There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
-
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
I've read your comments like that in other posts, i just place pending orders, cause it is more "comfortable" to the user to see what could possibly happen when price walks in chart..
and, it like you said it helps on Slippage and Spread, cause yes, i trade M1 on Brazillian index market.
For some reason it makes sense to have like 150 milliseconds sleep in the beginning of OnTradeTransaction yo make sure that the other actions on server side have already run through.
Sleep doesn't do anything in the strategy tester.
For some reason it makes sense to have like 150 milliseconds sleep in the beginning of OnTradeTransaction yo make sure that the other actions on server side have already run through.
No, it does not make sense. It IS the server that invokes OnTradeTransaction.
Exactly, its irrelevant.. all this question is about its just the fact tho: OnTradeTransaction doesnt see to be fast enough! OnTick goes FIRST/FASTERS than it, so, a new position on the same candle is opened if FOR SOME REASON it coincides with a new signal was generated by OnTick, and then, an open position just hitts TP or SL, then BEFORE OnTradeTransaction had enough time to update my variable, OnTick confirms that is the signal boolean is True, and do the OrderSend function..
and for those wondering: why dont you put a filter that DOESNT allow to signal be generated if theres an open position? cause my EA allow new signal to invert trade direction.
There is no problem with OntradeTransaction. The problem is in your logic and understanding of events. There is no chronological order for event handlers for example.
Also
https://www.mql5.com/en/docs/event_handlers/ontradetransaction
There is no problem with OntradeTransaction. The problem is in your logic and understanding of events. There is no chronological order for event handlers for example.
Also
yes, i've read that before, and many other things.. nothing really helpful, so i consider this topic closed, cause i gonna fix it my own.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys, i've been trying to fix something bugging hell out of me.
The situation is:
I have the code to prevent multiple trades on the same Bar/Candle, works most of time, but sometimes on StrategyTester... it doesnt.
The code works with OnTradeTransaction(), when theres a DEAL_ENTRY_OUT, it stores the datetime of the deal in a variable,
then back there on OnTick() it checks if TimeCurrent()>varBlockTradeUntil .. but look the screenshot, and code, and the logs..
Looks like the OnTick got priorized instead of OnTradeTransaction, who gives not enough time to the Anti Multiple Bar Trade code to work.
Looks fine until now, right? But.. look at the bugg.png attachment:
And, look what we got on the log:
The YELLOW line shows that the stop loss was triggered, ok, THEN, it should go to TradeTransaction, update the varBlockTradeUntil variable, THEN go back (or async) to OnTick to perform a new Deal or Order like in the RED line.
And, for those wondering, unfortunately due to the strategy, RIGHT in the moment that the Trade was closed due to StopLoss, a new TradeSignal was generated for the BEGINNING of 12:04:00 candle.
My point is, HOW can i avoid that operation to happen?