IntraBarOrderGeneration  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
eroleyikan
Posts: 22
Joined: 01 Jun 2016
Has thanked: 4 times
Been thanked: 6 times

IntraBarOrderGeneration

Postby eroleyikan » 01 Jun 2016

Hi,
I am transitioning from TS, so I am new to this forum. I converted most of my code to c#. I have a few shortcomings left.

I am using a Renko chart. I am trying to update the prices of my stop or limit orders based on certain conditions within the bar (ie before the last bar closes). Orders are placed at the end of a bar.

Does anyone know how to enable IntraBarOrderGeneration for a Renko chart?
Or some other way to call the RecalcLastBarAfter() function and have the last bar?

here is a piece of code that I am testing with. The recalc event fires, but the orders do not get updated:

Code: Select all

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
Point = Bars.Info.ASymbolInfo2.MinMove / Bars.Info.ASymbolInfo2.PriceScale;
buy_order.Send(4000);
sell_Limit_1.Send(Bars.Close[0] + 10 * Point, 2000);
sell_Stop_1.Send(Bars.Close[0] - 20 * Point, 4000);
ExecControl.RecalcLastBarAfter (new TimeSpan(0,0,0,45,0));
}

}
protected void OnRecalcLastBarAfterEvent()
{
this.CalcBar();
}
Thank you very much in advance.
Erol

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: IntraBarOrderGeneration

Postby JoshM » 03 Jun 2016

There's an article about Intra-bar order generation here: IOGMode: generating and filling orders intra-bar instead of on bar close. It might help you since it seems that your understanding of intra-bar order generation is different from what it does (also see my comments below).
I am trying to update the prices of my stop or limit orders based on certain conditions within the bar (ie before the last bar closes). Orders are placed at the end of a bar.
If you use intra-bar order generation, you'll need to resubmit managed orders each time the strategy calculates -- otherwise, MultiCharts .NET will cancel the pending orders.

You say here 'at the end of a bar' but your code actually submits orders at the end of the last bar:

Code: Select all

if (Bars.LastBarOnChart)
{
// ......
}
Does anyone know how to enable IntraBarOrderGeneration for a Renko chart?
Enabling intra-bar order generation is the same regardless of the bar/resolution/time frame used. See the earlier article I mentioned for the details.
Or some other way to call the RecalcLastBarAfter() function and have the last bar?
I think you confuse two things here:

* Intra-bar order generation is used to generate orders when the price bar hasn't closed yet. This can be done on historical bars also and makes the strategy quicker to respond to price action happening inside the bar.
* Recalculating a strategy after a fixed time interval is used during real-time trading primarily to ensure that the script keeps 'up to date' even when there might no new price data is incoming. The `OnRecalcLastBarAfterEvent()` method isn't executed when backtesting.

In other words, these are different features for different purposes.
here is a piece of code that I am testing with. The recalc event fires, but the orders do not get updated:
This code generates and submits orders on the very last bar of the data series. And uses that bar's close to determine the limit and stop price. As long as that bar's close don't change (like when the market is closed), then the order prices also don't change.

eroleyikan
Posts: 22
Joined: 01 Jun 2016
Has thanked: 4 times
Been thanked: 6 times

Re: IntraBarOrderGeneration

Postby eroleyikan » 17 Jun 2016

Josh,
Thank you for your earlier response on this. Since the last post I made some progress. Still have some questions, but this time I can be more specific and hopefully clearer..

I have a piece of code like this:

Code: Select all

protected override void CalcBar()
{
//...some logic
if (Bars.LastBarOnChart)
{
//... some more logic specific to the last bar
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 0, 45, 0));
}
} //end of CalcBar

Then based on some other threads that I found on this forum I have the following code in the OnRecalcLastBarAfterEvent():

Code: Select all

protected override void OnRecalcLastBarAfterEvent()
{
if (RecalcRequired)
{
ExecControl.Recalculate();
}
else
{
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 0, 45, 0));
}
}

Based on this code, I hit the OnRecalcLastBarAfterEvent() method every 45 seconds but I get an error on the ExecControl.Recalculate(); line and the system does not recalculate.
It does not even go into the CalcBar() method.

Here is the error message if it helps:
ManagedStudies.details._ELAPI_exception_Wrap_: Error in the application.
at ManagedStudies.details._ELAPI_exception_Wrap_Generator.raise(_ELAPI_exception_Wrap_Generator* )
at PowerLanguage.CExecutionControl.Recalculate()

Any suggestions?
Thanks
Erol

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: IntraBarOrderGeneration  [SOLVED]

Postby JoshM » 18 Jun 2016

Josh,
Thank you for your earlier response on this.

(...)

Here is the error message if it helps:
ManagedStudies.details._ELAPI_exception_Wrap_: Error in the application.
at ManagedStudies.details._ELAPI_exception_Wrap_Generator.raise(_ELAPI_exception_Wrap_Generator* )
at PowerLanguage.CExecutionControl.Recalculate()

Any suggestions?
Thanks
Erol
I figure that Henry's reply in the other thread fixed this error for you? If not, let us know.

eroleyikan
Posts: 22
Joined: 01 Jun 2016
Has thanked: 4 times
Been thanked: 6 times

Re: IntraBarOrderGeneration

Postby eroleyikan » 20 Jun 2016

Thanks for your help Josh. The error issue is resolved. There are still related open questions but I will continue on the other thread. I am marking this solved.


Return to “MultiCharts .NET”