Hi Everyone,
I need a little help understanding whats happening with a simple cross over using the smooth stochastic.
I trade the us500 on 10min and dont seem to be always getting a buy single on the cross over of 28. Please refer code.
While a lot of the triggers seem correct some I believe are missed.
Any ideas would be appreciated.
Regards
Carter
Do not embed files in your post. Use the SELECT FILE button only for attachments.
Thank you 🙂
It works like a charm, it skips crossovers when there are 2 positions open, as C5 (line 17) makes sure there are less than 2 positions to add another one.
Hi Robert.
Thank you for your reply.
I have checked what you have mentioned but I dont believe this is the issue. I have picked a couple of recent dates where a trigger is expected and there are no open positions. 4/4/22 and 17/1/22.
Thanks
Carter
//-------------------------------------------------------------------------
// Main code : US500 Multiple entry multiple exit
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = true // Cumulating positions activated
defparam preloadbars = 5000
// Conditions to enter long positions
i1 = SmoothedStochastic[509,80](close)//505,80
c1 = i1 crosses over 28//37
c5 = countoflongshares < 2
c6 = longonmarket = 0
IF c1 and c5 and c6 then
BUY 1 CONTRACT AT MARKET
ENDIF
c7 = (positionprice - close) > 1
if c1 and c5 and c7 then
buy 1 contract at market
endif
//Trailing Stop
if barindex > 30 then
i10 = close - positionprice
if i10 > 68 then
llowest = 228//228
else
llowest = 352
endif
i11 = (llowest - (i10 * 3))//409,3 - 4700,30
i12 = round(i11)
i16 = max(1,i12)
i17 = lowest[1](i16)//6
i18 = lowest[i17](low)
C19 = i10 > 17//20
c18 = close crosses under i18[2]//10
IF c18 and c19 THEN
SELL AT MARKET
endif
endif
//tp = a * AverageTrueRange[b](close)
set target pprofit 93
Replace line 27 with this one:
if barindex > 30 and OnMarket then
because if you don’t check if you are already on market, it will execute BUY, then SELL, thus invalidating the trade.