"EXITSHORT" command not closing a short position
Forums › ProRealTime English forum › ProOrder support › "EXITSHORT" command not closing a short position
- This topic has 5 replies, 3 voices, and was last updated 7 years ago by Munkanu.
-
-
12/28/2016 at 5:49 PM #19266
Hi there,
I am running the code below, which is meant to exit a short position if it closes above the 50EMA, and then quit the code.
The command to exit the short and then quit is at the bottom of the code below. Strangely, it successfully quits the code, meaning it must be running the code within this IF statement, but it does not exit the short position. Instead it quits the code and leaves the position open. Can you help me figure out why?
Many thanks
Chris
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970//-------------------------------------------------------------------------// Main code : MegaTrend1//-------------------------------------------------------------------------//-------------------------------------------------------------------------////-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//Define the indicatorsi1 = closei2 = ExponentialAverage[20](close)i3 = ExponentialAverage[50](close)//define the conditions for actionsc1 = (i1 > i2) //close above the 20MAc2 = (i1 < i2) //close below the 20MAc3 = (I1 < i3) //price closes under the 50MAc4 = (i1 > i3) //price closes above the 50MATrend = CALL "UpTrend/DownTrend" //call the up/down trend indicatorUpTrend = (Trend = 1) //uptrend in actionDownTrend = (Trend = -1) //downtrend in action//Money ManagementCapital = 35000 //Starting pot of £35kRisk = 0.01 //1% risk on each tradeIF UpTrend thenStopLoss = close-i3 // Initial stop loss at 50EMAENDIFIF DownTrend thenStopLoss = i3-closeENDIF//Calculate position sizeequity = Capital + StrategyProfit //Initial capital + current profitsmaxrisk = round(equity*Risk) //Equity times 1% rounded to whole numberPositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)// Conditions to enter positionsIF NOT ONMARKET THENIF c1 THENIF UpTrend THENBUY PositionSize PERPOINT AT MARKETSET STOP pLOSS StopLossENDIFENDIFIF c2 THENIF DownTrend THENSELLSHORT PositionSize PERPOINT AT MARKETSET STOP pLOSS StopLossENDIFENDIFENDIF// Conditions to exit positionsIF LONGONMARKET THENIF c3 THENSELL AT MARKETQUITENDIFENDIFIF SHORTONMARKET THENIF c4 THENEXITSHORT AT MARKETQUITENDIFENDIF12/28/2016 at 9:01 PM #19300Hi Munkanu
Try below and let us know how you get on.
123456<span class="token keyword">IF</span> <span class="token keyword">SHORTONMARKET</span> AND c4 <span class="token keyword">THEN</span><span class="token keyword">EXITSHORT</span> <span class="token keyword">AT</span> <span class="token keyword">MARKET</span><span class="token keyword">QUIT</span><span class="token keyword">ENDIF</span>Cheers
GraHal12/28/2016 at 9:34 PM #19303Hi GraHal,
Many thanks for your reply. I have tried this and still get the same result – the code quits (meaning the IF statement seems to be working) but the short position is left open (meaning the EXITSHORT command) does not seem to be working. Very odd.
Not sure what to try next as the code looks fine, can anyone help? Am I missing an argument on the EXITSHORT command?
Many thanks
Chris
12/28/2016 at 9:46 PM #19304I’ve never used “quit” pretty much at the same time as sending an order, so I’m only wondering here, rather than talking from experience: could it be that “quit” is instantaneous in such a way that the “exitshort at market” order is cancelled at the same time as exiting the strategy before it has any chance of being executed? Might be worth trying to delay your “quit” instruction by at least one candle after sending the exitshort order, just to see if it gives more time for the exitshort order to happen…
12/28/2016 at 10:15 PM #19307To delay by one candle, many ways to do it, but for example something like this should allow for the experiment:
adding at the beginning of the code :
1quitting=0and modifying the end with:
123456789IF SHORTONMARKET THENIF c4 THENEXITSHORT AT MARKETquitting = 1ENDIFENDIFif quitting[1]=1 thenquitendif1 user thanked author for this post.
12/28/2016 at 11:35 PM #19314 -
AuthorPosts
Find exclusive trading pro-tools on