Short Orders execution on Long only strategy
Forums › ProRealTime English forum › ProOrder support › Short Orders execution on Long only strategy
- This topic has 15 replies, 3 voices, and was last updated 4 years ago by Bi.
-
-
05/05/2020 at 10:41 AM #129985
Hi
I am trying to build a long only strategy where I have the below trade management rules.
- StopLoss set at 1 ATR (14)
- First Target set at 1 ATR(14)
- Trailing stop starting at 2 ATR(14) and trailing step at 1.5 ATR(14)
My StopLoss, First target and trailing seems to work but for some weird reason system is opening short positions even though I have no Short orders. The only sell orders I have exit ones, I tried add the code “Longonmarket” as well as “Countofpositions” still I am getting short orders
Much appreciate if you could let me know where I am going wrong please?
LongOnly Strategy123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// Definition of code parametersDEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated// Conditions to enter long positionskeltnersma = ExponentialAverage[20](close)keltnerpos1atr = keltnersma+ExponentialAverage[20](AverageTrueRange[1](close)*1)keltnerneg1atr = keltnersma+ExponentialAverage[20](AverageTrueRange[1](close)*-1)longindicator1 = Call Strategy01LongV1longindicator2 = Call Strategy02LongV2l1 = (longindicator1 = 1)l2 = (longindicator2 = 1)within1ATR = close >keltnerneg1atr and close<keltnerpos1atr//trade managementlotsize = 2 //original position sizeLot2Close =1 //close one lot while reaching first targetstoploss = Averagetruerange[14](close)*SLFactorfirsttarget= Averagetruerange[14](close)*PTFactortrailingstart = Averagetruerange[14](close)*2trailingstep = Averagetruerange[14](close)*1.5//trade entry and exitsif l1 or l2 and within1ATR thenBuy lotsize LOT AT MARKETSET STOP PLOSS stoplossendif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THENIF newSL=0 AND close-tradeprice(1)>=firsttarget THENSell lot2close LOT At MarketnewSL=tradeprice(1)+firsttargetENDIF//first move (breakeven)IF newSL>0 AND close-newSL>=trailingstart THENnewSL = newSL+trailingstartENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//stop order to exit the positionsIF Countofposition>0 and LONGONMARKET AND newSL>0 THENSELL AT newSL STOPENDIF(See attached strategy and code)
05/05/2020 at 11:11 AM #12999805/05/2020 at 11:19 AM #129999Thank you, below the v1,v2 code. I believe rest of the conditions are in the strategy code itself.
This is the V1 and V2 code123456789101112131415161718192021222324252627282930//v1atr = AverageTrueRange[14](close)*1/4v1low = ABS(low - low[1])> atrv1lowcheck = low<low[1]v1close= close>close[1]if v1low and v1lowcheck and v1close thenvalue = 1elsevalue = 0endifreturn value//V2atr = AverageTrueRange[14](close)*1/4v1low = ABS(low[1] - low[2])> atrv1lowcheck = low[1] < low[2]notv1= close[1] < close[2]v2close1 = close > close[1]v2close2 = close > close[2]v2low = low>low[1]v2gap = abs(close[1]-open)<=atrif v1low and v1lowcheck and notv1 and v2close1 and v2close2 and v2low and v2gap thenvalue = 1elsevalue = 0endifreturn value1 user thanked author for this post.
05/05/2020 at 11:33 AM #13000105/05/2020 at 11:41 AM #130003I confirm same … so you are not seeing things! Unless we are both deluded!? 🙂
I get 1 short trade when running on DJI 1000 bars and 5 min TF and spread = 2.
When I put spread = 4 I do not get a short trade on DJI 1000 bars and 5 min TF.
That’s one of the weirdest thing I’ve ever come across since I’ve been using PRT??
05/05/2020 at 11:50 AM #13000605/05/2020 at 12:15 PM #13000705/05/2020 at 12:31 PM #130009Various values for ptfactor will give shorts or stop shorts also
1firsttarget= Averagetruerange[14](close)*PTFactorSeems there are several changes that will stop the Shorts, but how can a System go short when there is NO SellShort command in the code??
Very worrying!!??
05/05/2020 at 12:54 PM #130015thank you for looking into it. I do agree this is odd.
Also I understand scaling out on a auto-trading is not possible but I am only try to backtest my strategy how I would manually trade it. Hence the first target close is important. But why market is shorting even with the below condition is beyond my understanding.
1IF Countofposition>0 and LONGONMARKET AND newSL>0 THEN05/05/2020 at 6:08 PM #13011105/05/2020 at 6:39 PM #130116Yeah at certain conditions you are selling 3 after buying 2 (?) … still weird though as I would have expected a System Reject / Stop covered by one of IG’s ambiguous screen messages!?
Maybe one day somebody might be able to make profitable use of this loophole!? 🙂
05/05/2020 at 6:47 PM #13011905/05/2020 at 6:49 PM #13012005/05/2020 at 6:56 PM #130121I do have shorts as well with the same logic reversed but wanted to keep the strategies Long only and Short only to review the results accurately. Also I am testing this on US shares where there is a long bias but have to test this out in other markets like FX or Commodities where trends are not one sided.
Please feel free to improve it, if you do manage to please do let me know.
05/05/2020 at 7:17 PM #130123Please feel free to improve it
I had a quick go this morning … I could see that it needed a filter to stop Longs when price was clearly in a big downtrend.
I tried below and I used values of up to x = 10000 on a 5 min TF, but still it was taking Longs … I thought more weirdness!? 🙂
1Close > Average[x](Close) -
AuthorPosts
Find exclusive trading pro-tools on