Is there anyone who got ChangeMarketPostion running ?

Questions about MultiCharts and user contributed studies.
PeterSt
Posts: 31
Joined: Jun 18 2024
Has thanked: 5 times
Been thanked: 11 times

Jul 20 2024

image_2024-07-20_115235250.png
(47.93 KiB) Not downloaded yet
I know, this is .Net code, but the .Net board seems a bit dead to me, so posting it here ...

The command you see is the command which makes the Strategy Position and Average Price equal to the Position and Average price at the Broker. Well, that is the intention of it. But I can't get it to work.
And I can't use this either :
image_2024-07-20_115508190.png
(10.14 KiB) Not downloaded yet
- knowing that people will tell me to use that.

The problem I am facing is that I work in AA (Asynchronous) mode with tick data, and that there does not seem to be a moment I can catch the not being equal (Broker vs Strategy) to be in order. I feel that this is related to this :
image_2024-07-20_115804960.png
(10.79 KiB) Not downloaded yet
- the second section you see in there. This, with the notice that in older versions of MC the option existed to not do anything at all, but today (15, 15 R2) we always have to let the general/internal MC code be ahead of things - which is earlier than my program code is in order (say that I tried in Create, StartCalc and CalcBar).
Please notice that the option "Always show dialog window" also does not bring the desired result in any of its variations, as only the Broker Position is obtained and not the Average Price. Hence, the CurrentOpenProfit starts out with 0 always, while in reality it could be -1000. The effect ? when the code is restarted and reaches the set TP of e.g. 50, it goes out at a loss of -950.

With all I tried (which must be over 100 times on Live), I can not get this Synchronization to run as it should. Thus also not with the standard Signal for it (as shown in the 2nd attachment).
Keywords seem to be : AA Mode, Code calls at the Tick level, Not IOG mode (while the standard Indicator uses that) and perhaps the impossibility to Sync at the tick level because all will choke.

On the latter : I only need to synchronize once. And not at each bar and most certainly not on each tick. Theoretically I need to do this before any other line of code is executed, but there just seems to be no way. A way which starts with If BrokerPosition != StrategyPosition (pseudo code).
I have turned every stone, but the "Sync" tag you see given in the first attachment, just never shows up (in very rare occasions the standard similar tag in the standard Indicator, may - but this seems a coincidence, plus it would be in the situation that the indicator is called each tick, which is not possibly in practice).

Anyone, please ?
Or questions ?

HellGhostEvocatorX
Posts: 143
Joined: Feb 10 2022
Has thanked: 68 times
Been thanked: 23 times

Jul 20 2024

I don't know much about the problem, but I'm afraid that what you're trying to achieve will be difficult. If you use an asynchronous mode, the name already says that the data on your local PC and that of the broker are not synchronized and can therefore hardly ever be the same.
Imagine that your logic receives the price from the broker; the price is $100. Now your logic calculates that it wants to buy and sends the buy order. Due to the delays in the calculation and receiving/sending, etc., the buy signal only arrives at the broker at $101. The broker sees that the price of $100 has not been reached and rejects the order.
It also says in the multicharts wiki that the asynchronous mode is just a kind of live backtest, but that there is no longer any synchronization.

A possible workaround could be to use "Events" from the .NET framework. But I have no idea if and how you could implement this and I also wonder if it is really necessary if there is a synchronous mode.

So please answer, why should it be asynchronous mode?

What is your actual goal, what do you want to achieve?

PeterSt
Posts: 31
Joined: Jun 18 2024
Has thanked: 5 times
Been thanked: 11 times

Jul 21 2024

The answer to your question : simple, be able to trade with tick data without everything collapsing in a few minutes; As I tried to point out : we can't expect that all runs smoothly if we'd ask the Broker status at each tick (which could be 10000 per second at e.g. News times, but which normally already is hundreds per second for more volatile instruments).
If you use an asynchronous mode, the name already says that the data on your local PC and that of the broker are not synchronized and can therefore hardly ever be the same.
I really appreciate your thinking along with me, but here you have (my) practice against you;
5K+ Live trades further (but it shows after a first couple of test runs already), there is no single moment in time that both Broker and Strategy run out of sync. However, it surely is true that the Broker lags (for the reasons you mentioned and more) but this is no big deal at all. That is, if you know very well what you are doing and how the various systems behind the scenes behave (and how latency is involved from all angles).
Of course there is no by MC provided standard Strategy which anticipates that, but we can make that ourselves (which is obviously what I did).

A prerequisite is that you work with Market Orders ...
The broker sees that the price of $100 has not been reached and rejects the order.
so that is not in order as well. So, such a strategy is a technical strategy within itself, and when executed in consistency throughout, there won't be any of such problems (which you - again - well touched).

What we could summarize is that MC provided a means for starting-through, but to me this seems completely unnecessary if SA mode is used in the first place (the S part causes the synchronization inherently). So what is the explicit Synchronization made for ? right. AA mode.
But it does not work - or at least not any more.

Anyway envision two systems happily living next to each other and you have guaranteed yourself that the one (Broker) WILL do what the other did too (Strategy). Dangerous ? no (Broker outages left alone, but you will be told by the MC environment soon enough). For the faint-hearted ? possibly Yes. This is mainly because you can test this on Live trading only, and Backtesting requires heavy interpretation of what will be going on for real later (on Live) and how to mimic that.
Deeply investigate the behavior of Slippage, and you're ready for lift off (and lose money on the first trials).

That said, the Synchronization thus does not work, despite the so many pages written about it; it would be a key element of MC, especially with pyramid trading and such, which people may do but at quite an other level (call that in an other universe and we would be close).

Let me unsolicitedly add a reason why people may not even notice the being out of sync : the sheer fact that your Strategy is kicked out because of plain MC internal faults (this is for another thread). Thus, a Strategy may run for an hour (performing 50+ trades) it may run for 5 hours (and 250+ trades) but eventually will fail. So envision for this one Strategy (and one Instrument) me "starting-through" that Strategy 4-5 times a day and envision too that this was meant to be Autotrading and not Manual trading. It comes down to the latter now, because I'd have to decide when to restart that Strategy hence observe the current loss and trend etc. This is tiring. And thus ... while this kicking out is a problem in itself, the starting-through becomes a hurdle which should not be there.

The idea of finding events which may do the job is a good one, but I already investigated the formally exposed events and found not much really. However, I can imagine many more MC-dedicated exist, but they are not told about (?).