BarsSinceExit & Intrabar

Questions about MultiCharts and user contributed studies.
Joogen
Posts: 9
Joined: 27 May 2009

BarsSinceExit & Intrabar

Postby Joogen » 17 Jan 2012

Hi there,

I have a strategy with profit taking limit order (based on 1min bars) and want to keep this order alive in the case the position was exited on chart but still open at broker (IB). If I want to do so only for the bar, the "chart order" was exited, would the following framework (short position with profit taking based on EntryPrice) be a solution? The order should be active asap (exit + 1 tick) and is part of an OCO order.

Code: Select all

[IntraBarOrderGeneration=true];
Vars: IntraBarPersist EP(0),IntraBarPersist MP(0), IntraBarPersist BSE(0);

EP=EntryPrice(1);
MP=MarketPosition;
BSE=BarsSinceExit(1);

if MP = 0 and MarketPosition_at_Broker_for_The_Strategy = -1 and BSE<1 then begin
BuyToCover next bar at EntryPrice(1)-XX points limit;
end;
Thanks for any contribution.

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

Re: BarsSinceExit & Intrabar

Postby Henry MultiСharts » 20 Jan 2012

Hi there,

I have a strategy with profit taking limit order (based on 1min bars) and want to keep this order alive in the case the position was exited on chart but still open at broker (IB). If I want to do so only for the bar, the "chart order" was exited, would the following framework (short position with profit taking based on EntryPrice) be a solution? The order should be active asap (exit + 1 tick) and is part of an OCO order.

Code: Select all

[IntraBarOrderGeneration=true];
Vars: IntraBarPersist EP(0),IntraBarPersist MP(0), IntraBarPersist BSE(0);

EP=EntryPrice(1);
MP=MarketPosition;
BSE=BarsSinceExit(1);

if MP = 0 and MarketPosition_at_Broker_for_The_Strategy = -1 and BSE<1 then begin
BuyToCover next bar at EntryPrice(1)-XX points limit;
end;
Thanks for any contribution.
Hello Joogen.
BuyToCover is an exit order to close the position, it won't work if MP = 0.

What we can recommend is:
1) In order to send "buy to cover" you need to make the position -1 with the help of !From Broker To Strategy MP Synchronizer! signal.
!From Broker To Strategy MP Synchronizer! - Synchronizes the market position inside MultiCharts with the market position at broker by sending a dummy order in charting.

2) !From Strategy To Broker MP Synchronizer! will help you to synchronize the market position at broker with the market position at chart by sending a real order to the broker, in your example MP=0, thus it will send buy market +1.


Return to “MultiCharts”