I would like to set a take profit condition for a proorder strategy.
The take profit must be set at the level of the daily pivot point when the position is opened.
I tried with this code:
1
2
3
4
5
6
7
// Conditions for exiting long positions
indicator6=(DHigh(1)+DLow(1)+DClose(1))/3
c26=(close<=indicator6)
IFc26THEN
SELLATMARKET
ENDIF
unfortunately with this code the pivot point is updated according to the new price trend. I would like to set the take profit at the level of the daily pivot point at the time the order is opened.
Just save the value at the time that the buy order is placed and then place a pending sell stop order at each bar close. Alternatively just sell at that price or below that price as you did in your code.
Pending Sell Stop Order
1
2
3
4
5
6
7
8
9
if(yourconditions)then
buy1contractatmarket
exitprice=(DHigh(1)+DLow(1)+DClose(1))/3
sellatexitpricestop
endif
IFlongonmarketTHEN
sellatexitpricestop
ENDIF
Sell if close is below or equal to exitprice
1
2
3
4
5
6
7
8
if(yourconditions)then
buy1contractatmarket
exitprice=(DHigh(1)+DLow(1)+DClose(1))/3
endif
IFlongonmarketandclose<=exitpriceTHEN
sellatmarket
ENDIF
Note: Please use the ‘Insert PRT Code’ button when putting code in your future posts as it makes it easier for others to read. I have tidied up your post for you. 🙂
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.