Exit at the open  [SOLVED]

Questions about MultiCharts and user contributed studies.
etrader808
Posts: 2
Joined: 30 Dec 2013
Has thanked: 4 times

Exit at the open

Postby etrader808 » 30 Dec 2013

I'm trying to create a exit based on the first profitable open price. Meaning if I have a long position in the market and tomorrow's open is above my entry price then exit at that open price.

Another way of putting it, is I'm trying to sell at a limit price (above my entry price) only at the market open time.

Without being able to reference tomorrow's open price (open[-1]) in the code, I'm can't seem to get it to work.

If marketposition >= 1 and openpositionprofit > 0 then
Sell("LongExit") next bar at open;

As you can see from my coding above doesn't quite to the job.

Any help would be greatly appreciated.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Exit at the open

Postby SUPER » 30 Dec 2013

Try this

Code: Select all


if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Exit at the open

Postby sptrader » 30 Dec 2013

Try this

Code: Select all


if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;
*************************************************************************
Shouldn't it be " if (MarketPosition = 1) "

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

Re: Exit at the open  [SOLVED]

Postby Henry MultiСharts » 30 Dec 2013

etrader808, you can use "buy next bar at open next bar" command in your code.
Please refer to the following thread for more details.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Exit at the open

Postby SUPER » 30 Dec 2013

Try this

Code: Select all


if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;
*************************************************************************
Shouldn't it be " if (MarketPosition = 1) "
Thanks for drawing my attention to error in code I posted earlier ,it should be (MarketPosition=1) or (MarketPosition > 0)

etrader808
Posts: 2
Joined: 30 Dec 2013
Has thanked: 4 times

Re: Exit at the open

Postby etrader808 » 31 Dec 2013

Thanks guys for the reply.

sptrader, I've tried the code you posted it seems to skip most of the open that are profitable. see attached.

The closest I've come is using the "sell next bar at open next bar limit;" but I can't seem to get it to exit only when the open price if above entry price.

input: DOW(1);

If marketposition <> 1
and DayOfWeek(Date) = DOW and close < close[1] and open < close[1] then
Buy("LongEntry") next bar at High stop;

if MarketPosition = 1
then sell next bar at open next bar limit;

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

Re: Exit at the open

Postby TJ » 31 Dec 2013

Thanks guys for the reply.
sptrader, I've tried the code you posted it seems to skip most of the open that are profitable. see attached.
The closest I've come is using the "sell next bar at open next bar limit;" but I can't seem to get it to exit only when the open price if above entry price.
input: DOW(1);
If marketposition <> 1
and DayOfWeek(Date) = DOW and close < close[1] and open < close[1] then
Buy("LongEntry") next bar at High stop;
if MarketPosition = 1
then sell next bar at open next bar limit;
Look up

IntraBarOrderGeneration

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

Re: Exit at the open

Postby TJ » 31 Dec 2013

ps:
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713


Return to “MultiCharts”