Closing All Open Positions if LastBarOnChart  [SOLVED]

Questions about MultiCharts and user contributed studies.
LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

Closing All Open Positions if LastBarOnChart

Postby LSs » 15 Nov 2012

I want to close all open positions if the LastBarOnChart is true.

I tried the following code but an error was generated - "Cannot use next bar's price and close order in the same strategy"

Code: Select all

if LastBarOnChart then begin
Sell ("LastBarLE") this bar on Close;
BuyToCover ("LastBarSE") this bar on Close;
end;
Not sure if it is related, but the only two signal orders contained in my script are:

Code: Select all

Buy ("Buy") lots contracts next bar at Market;
SellShort ("Sell") lots contracts next bar at Market
Anyone can correct me where I'm wrong?
Thanks.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Closing All Open Positions if LastBarOnChart  [SOLVED]

Postby TJ » 15 Nov 2012

I want to close all open positions if the LastBarOnChart is true.

I tried the following code but an error was generated - "Cannot use next bar's price and close order in the same strategy"

Code: Select all

if LastBarOnChart then begin
Sell ("LastBarLE") this bar on Close;
BuyToCover ("LastBarSE") this bar on Close;
end;
Not sure if it is related, but the only two signal orders contained in my script are:

Code: Select all

Buy ("Buy") lots contracts next bar at Market;
SellShort ("Sell") lots contracts next bar at Market
Anyone can correct me where I'm wrong?
Thanks.
see post #7
viewtopic.php?f=16&t=10811

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Closing All Open Positions if LastBarOnChart

Postby TJ » 15 Nov 2012


LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

Re: Closing All Open Positions if LastBarOnChart

Postby LSs » 16 Nov 2012

Thank TJ.

Got it. So for solely backtesting only, I will have to change all orders to 'this bar on Close.'
When I'm ready to go live, I will change orders to 'next bar at Market.'

Thanks.


Return to “MultiCharts”