Next Bar Open  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Next Bar Open

Postby GTrader » 05 Dec 2012

Do you have an example of how to do the equivalent of a
"Next Bar on Open" order in EL? It is for a opening gap strategy
that I am porting over where I want to process the order after
the opening tick of a new session (as i filter whether to place the
trade based on where the opening price is) and submit the order
after the opening tick (not on the close or during the first bar).

GT

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Next Bar Open

Postby Henry MultiСharts » 06 Dec 2012

Hello GTrader,

For "Next Bar on Open" command you can use IOrderCreator.MarketNextBar method.
You can determine the opening tick of a new session with IInstrument members such as IInstrument.Sessions and/or IInstrument.Status.

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: Next Bar Open

Postby GTrader » 06 Dec 2012

Hi Henry,
To be more specific ... this is the basics of what I am trying to replicate.

Code: Select all

NextDate = Next Bar Date;
LastTickOfDay = NextDate <> Date;
If LastTickOfDay then begin
NextOpen = Next Bar Open;
Gap = NextOpen - Close;
if Gap>0 then
SellShort ("se") Next Bar on Open
else if Gap<0 then
Buy ("le") Next Bar at Open;
end;
SetExitOnClose;
It changes the processing of the strategy from the closing tick of each bar to the opening tick of each bar. This makes it possible for me to check (for example) if the open is a gap up /down and get to submit the order essentially on the second tick of the bar if I want to fade/go with the opening gap. It also allows me to backtest a gap strategy using normal time bars with out the need of intrabar order generation. I don't see a way to do the equivalent of shifting the processing to the opening tick of each bar so I tried intrabar order generations but it doesn't seem to be working. Here is my code:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
public class Gt_Gap : SignalObject {
public Gt_Gap(object _ctx):base(_ctx){}
private IOrderMarket le_order;
private IOrderMarket se_order;
private IOrderMarket lx_order;
private IOrderMarket sx_order;
}
protected override void Create() {
le_order = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default,EOrderAction.Buy));
se_order = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
lx_order = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
sx_order = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover));
}
protected override void StartCalc() {

}
protected override void CalcBar(){
if (Bars.Status == EBarState.Open){
double gap = Bars.Open[0] - Bars.Close[1];
if (gap > 0){
se_order.Send();
}
else if (gap < 0)
{
le_order.Send();
}
}
if (Bars.LastBarInSession)
{
if (StrategyInfo.MarketPosition == 1)
{
lx_order.Send();
}
else if (StrategyInfo.MarketPosition == -1){
sx_order.Send();
}
}
}
}
}
Also, is there a nicer way to post code as the formatting when I copy and paste from the editor gets all messed up and the post becomes centered instead of left justified.

Thanks,
GT

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Next Bar Open  [SOLVED]

Postby Henry MultiСharts » 14 Dec 2012

Hello GTrader,

Accroding to you PLE code you are using Next Bar Date functionality. Such studies reference the next bar and are calcualted differently compared to regular studies.
There is no such functionality in MultiCharts .Net at the moment, but we are going to add it in one of the future versions.
Also, is there a nicer way to post code as the formatting when I copy and paste from the editor gets all messed up and the post becomes centered instead of left justified.
Does not happen to me using Firefox or Chrome. Are you using one of these or IE ?


Return to “MultiCharts .NET”