Hi, i wanna create a really simple exit strategy for stocks and apply it to some other simple strategies i am trying out with stocks.
What i want to do is create a exit strategy that exits the position if the position is in profit 5 minutes before market closing. It should keep doing this for 4 days and on the 5th day sell either way (despite being in loss) 5 minute before market closes.
Here is a simple strategy for entering stochastics (2,3) on 30 and exit at 70 (and short the opposite). Now i want to add in the above exit strategy. What code do i write?
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Stochastic[14,2](close)
c1 = (indicator1 CROSSES OVER 30)
IF c1 THEN
BUY 50 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = Stochastic[14,2](close)
c2 = (indicator2 CROSSES UNDER 70)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator3 = Stochastic[14,2](close)
c3 = (indicator3 CROSSES OVER 70)
IF c3 THEN
SELLSHORT 50 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
indicator4 = Stochastic[14,2](close)
c4 = (indicator4 CROSSES OVER 30)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
I appreciate any help and tips. I am quite new to prorealtime so i am very open to critique and learning.
Regards,
Jolln
Hi
Did you sort this ?
I also want to exit the firt day in profit in the end of the day if possible
Now my algo exit the first bar in profit instantly with this code
if longonmarket and (barindex=tradeindex+5 or close > tradeprice) then
sell at market
Because codes are only read once at Close of the bar, and if you are using this code on a daily timeframe, it is not possible to make it do things before the end of the day. Until we get the multitimeframe support, I do not see any accurate solution I’m sorry!