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.
Exit at the open [SOLVED]
Re: Exit at the open
Try this
Code: Select all
if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;
-
- Posts: 742
- Joined: 09 Apr 2010
- Location: Texas
- Has thanked: 483 times
- Been thanked: 274 times
- Contact:
Re: Exit at the open
*************************************************************************Try thisCode: Select all
if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;
Shouldn't it be " if (MarketPosition = 1) "
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Exit at the open [SOLVED]
etrader808, you can use "buy next bar at open next bar" command in your code.
Please refer to the following thread for more details.
Please refer to the following thread for more details.
Re: Exit at the open
Thanks for drawing my attention to error in code I posted earlier ,it should be (MarketPosition=1) or (MarketPosition > 0)*************************************************************************Try thisCode: Select all
if (MarketPosition > 1) and (BarsSinceEntry >=1) and (Open > AvgEntryPrice) then sell next bar at Market;
Shouldn't it be " if (MarketPosition = 1) "
-
- Posts: 2
- Joined: 30 Dec 2013
- Has thanked: 4 times
Re: Exit at the open
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;
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;
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Exit at the open
Look upThanks 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;
IntraBarOrderGeneration
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times