Last bar prices wrong in IOG Mode tick chart trading

Questions about MultiCharts .NET and user contributed studies.
r41866
Posts: 6
Joined: 03 Mar 2023

Last bar prices wrong in IOG Mode tick chart trading

Postby r41866 » 03 Mar 2023

I want to write Multicharts.net C# code to do auto entry for my order position in futures in a tick chart. Assume the trade direction is long so my signal bar should be a green bar at a pivot low. The entry is triggered when the signal bar high price is exceeded by the bar following the signal bar. Please look at the example in the chart.

Image

The bar marked by the blue arrow is a pivot low green bar and it is a signal bar. Entry order is triggered if the signal bar high is broken by the following bar (the bar marked by the red arrow).

I turn on the auto trade code all the time but in order to really send an order, I use mouse click to change a Boolean variable to true so that the code knows it is the time to send the order. I can turn on the order before the signal bar is closed or after the signal bar is closed. If the order is enabled before the signal bar is closed, after the signal bar is closed, auto trade code sends a stop order at one tick above the signal bar. Sometimes when the signal bar is too large, in order to reduce the risk, I wait for the signal bar high broken and then the price retraces deep below the signal bar high and then enable the order by the mouse click. For example, I want to fill the order at the price marked by the magenta line. Then I wait for the price to break the signal bar high and then the price retraces below to the magenta line. At that time, I click the mouse to let the code send a market buy order so now I get an entry price better than the stop price.

I wrote the code in IOGMode so orders can be generated within a bar. I wrote the code similar to below. I know double type number comparison can cause errors so I let a price to compare the other price +/- 0.5 x tick value to avoid the error. Yet in the below example, in order to avoid complexity and make it easier to understand, I use direct comparison and assume the comparison is OK for double type numbers.

if (Bars.Status == EBarState.Close && Bars.Close[0] > Bars.Close[1] && Bars.Low[0] < Bars.Low[1])
SBDetected = true; //SBDetected is true means the signal bar is detected.
if (MouseClicked && Bars.LastBarOnChart && SBDetected)
if (Bars.High[0] > Bars.High[1]) Send market buy order;
else send stop market order at Bars.High[1] + 1 tickvalue;

The real code to send the order is much more complicated in IOGMode programming but I make it simple just to show my idea.

When I used the code similar to above, I got the problem. I found Bars.High[0] is not accurate in the last bar in a tick chart. A lot of times, if I click the mouse after the signal bar is closed, the code sends out a market order even if the signal bar high is never broken so I have an open position when the signal bar is never triggered.

Then I used the code below to detect the break of the signal bar.

if (Bars.Status == EBarState.Close){
SBBroken = false; //SBBroken is the Boolean variable to indicate the break of signal bar.
} else {
if (Bars.Close[0] > Bars.High[1]) SBBroken = true;
}

if (MouseClicked && Bars.LastBarOnChart && SBDetected )
if ( SBBroken ) Send market buy order;
else send stop market order at Bars.High[1] + 1 tickvalue;

Yet I got another issue. The signal bar break seems not detected as often as it should be. A lot of times, even when the signal bar has been broken and the price retraces deep below the signal bar high, the code still sends out a stop order. Therefore, I cannot get a better entry price even if the price traces deep below signal bar high.

My question is: how to get the accurate high or low price of the last bar in a tick chart in IOGMode in a signal? Both of my methods don’t work. Thank you very much!

r41866
Posts: 6
Joined: 03 Mar 2023

Re: Last bar prices wrong in IOG Mode tick chart trading

Postby r41866 » 06 Mar 2023

Can any Multicharts support staff reply my posts? I have posted a few questions and a couple of days have passed but no one has ever replied. Even if the problems cannot be solved, I need to know so that I can try to find the other solutions.

HellGhostEvocatorX
Posts: 77
Joined: 10 Feb 2022
Has thanked: 47 times
Been thanked: 9 times

Re: Last bar prices wrong in IOG Mode tick chart trading

Postby HellGhostEvocatorX » 10 Mar 2023

Hello R41866. Unfortunately, it often takes longer to get an answer in the forum, this is unfortunately normal. The more specific you write your answer, the sooner you will get an answer, I also have some open questions here that have never been answered - unfortunately. However, it is sometimes difficult to formulate the questions in an understandable way. I don't fully understand your problem either - perhaps because English is not my mother tongue. However, I might be able to help you further.
I'm also currently working on the IOG mode (but in backtest) Do you use it in live trading? demo trading?
The complete code would help to find the error. There are several pitfalls with IOG mode that you need to be aware of. e.g. marketthisbar order does not work in IOG.
The bar magnifying glass could possibly help in the backtest. and remember that in IOG mode orders have to be resent over and over again as they are only valid for the next tick.
There are some good posts on this forum that deal with such issues.
It might help if you included an Output window for debugging your code. Or you can use the extended debugging options with Visualstudio.
Did your code work in backtest?

If you provide me with your code, I would be happy to deal with your topic. I would only use the code for debugging and maybe learning something myself.

what exactly do you mean by this: "How do I get the exact high or low price of the last bar in a tick chart in IOGMode in one signal? Both of my methods don't work. Thank you!"
Is your chart broken down into a tick chart? otherwise you could just use Bars.High[0].In the tick chart, my approach would be to write all ticks in a list and then filter out the high and low up to the appropriate point in time, e.g. with the .Max() method. The list could then be deleted and rewritten.

A tick chart doesn't have direct highs and lows, or do you mean the highs and lows on a higher timeframe?

However, the support may also find the error more quickly :), but this only works Mon.-Fri. me possibly also on the weekend :P
PS there is a way to mark code as code :)

Vielleicht hilft auch dieser Link weiter: https://www.tradingcode.net/multicharts ... intra-bar/

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: Last bar prices wrong in IOG Mode tick chart trading

Postby Svetlana MultiCharts » 10 Mar 2023

Hi r41866,

Please reproduce the situation in simplified environment (one workspace, one chart, simplified signal) and send us the following files so that we would be able to investigate it:

1. The workspace where the behaviour is reproduced.
2. Export of used symbols (with data) from QuoteManager in .qmd archive.
3. The exported scripts with all dependent functions that are used on the workspace.
4. The screenshots demonstrating the situation.
5. Step-by-step instruction how to reproduce the situation.

Currently it is not quite clear what “Bars.High[0] is not accurate in the last bar in a tick chart” means.


Return to “MultiCharts .NET”