JASSParticipant
Junior
That is exactly my experience! So either there is a problem in the code or there is a problem between IG and PRT. And then we are back to the “needle-in-a-haystack”. Can you spot anything else in the code that might cause this?
I might be speaking too soon, but I changed so SP = 2 and it has not been Rejected (yet!).
SP = 1 // Stochastic Period
I might be speaking too soon
Still no Rejection after 16 mins so SP = 1 looks like the problem?
I’ll keep monitoring and report back.
Rejected again but it took nearly 1 hour this time!
Well weird??
I’ll like to help but I do not see anything in the code that would suggest this behavior. But please test these, in the same order:
- restrain the whole code to a time condition: if time>=010000 and time<073000 then …. YOUR CODE …. endif
- use a period of more than just 1 period for the calculation of the stochastic (variable SP)
- Did you try on a 5-minutes timeframe? (I know it is not the desired TF, but ..)
SP = 2 on 1 min TF stopped again but it took about 3 hours this time (1 hour last time).
SP = 1 on 5 min TF got stopped, but it took about 3 hours.
SP =10 on 1 min TF is still running after 3 hours.
JASSParticipant
Junior
Thanks GraHal for your big effort here, I really appreciate it!
I have replaced the stochastic with one line of code, since I only need an intrabar view on the close vs. high and low. The code now looks like this:
K = ((close-low)/(high-low))*100
Very close to stochastic, but now I don’t have to worry about the highest/lowest in relation to one bar only.
The strategy still stops though.
Then I have followed suggestion from Nicolas and “wrapped” all code in an “if time>=010000 and time<073000 then” statement, though after the defparam lines, since they need to come before anything else in any code as far as I remember. I suppose I will have to wait and see till tomorrow morning if this has an influence.
I will revert.
I’ve incorporated the changes you mention above and set that version going so we can compare!
Sleep Well! 🙂
All versions stopped except SP = 10.
In backtest SP = 10 makes zero / 0 Profit (due to zero Trades over 100k bars).
Why is the SP = 10 System the only System (out of our trials) that does not get stopped??
No entries for any stoppages under Rejected / Cancelled in the Orders List.
Stopped error message is attached. All my versions stopped have DEFPARAM PreLoadbars = 10000.
Point to Note:
Stoppages occur outside of trading hours (see numerous evidence in comments above) so it is not when a System tries to execute a trade that the System is stopped.
JASS and I have tried numerous versions, so for reference … below is the only code version that has NOT been stopped.
The version below has been running since 14:37 yesterday 6 Jan 20.
//-------------------------------------------------------------------------
// Main code : A107 Pullback Rev JPN 1M v04
//-------------------------------------------------------------------------
//https://www.prorealcode.com/topic/trading-system-automatically-stopped/#post-115990
//**********************************************************************************
// Title: A107 Pullback Rev JPN 1M v04
// Chart: JAPAN225 / NIKKEI 1M
// Note: Exploiting one bar pullbacks in steep trending market
//**********************************************************************************
DEFPARAM CumulateOrders = True
DEFPARAM PreLoadBars = 10000
DEFPARAM FLATBEFORE = 000000
DEFPARAM FLATAFTER = 063000
//**********************************************************************************
// Variables
//**********************************************************************************
PositionSize = 1
tp = 138 // Target profit
sl = 28 // Stop loss
EMAp1 = 34
EMAp2 = 29
EMAp4 = 41
SMAp2 = 40
SP = 10 // Stochastic Period
v10 = 10 // Stochastic lower line
v90 = 94 // Stochastic upper line
emadiff = 1.95 // EMA difference to ensure steep trend
MOMp = 51 // Momentum period
MOMLv = 40 // Momentum long value
MOMSv = -100 // Momentum short value
PBLp = 25 // Power bar long period
PBSp = 25 // Power bar short period
PBLv = 12 // Power bar long value
PBSv = 33 // Power bar short value
LBL = 20 // Large bar long
LBS = 15 // Large bar short
COSH = 4 // Count of shares
//**********************************************************************************
// Indicators and Math
//**********************************************************************************
// Stochastic
C = Close
HH = Highest[SP](high)
LL = Lowest[SP](low)
K = ((C-LL)/(HH-LL))*100
// EMA
c01 = exponentialaverage[EMAp1](close)
// Momentum
c03 = momentum[MOMp](close)
// SMA
c04 = average[SMAp2](close)
// Power bar long - no powerbar for the last PBLp number of periods before entry
PBL = close - open
IF highest[PBLp](PBL) < PBLv THEN
c13 = 1
else
c13 = 0
ENDIF
// Power bar short - no powerbar for the last PBSp number of periods before entry
PBS = open - close
IF highest[PBSp](PBS) < PBSv THEN
c33 = 1
else
c33 = 0
ENDIF
c05 = abs(c01[0]-c01[1]) > emadiff
c06 = exponentialaverage[EMAp2](((2*close)+open)/3)
c07 = exponentialaverage[EMAp4](((2*close)+open)/3)
//**********************************************************************************
// Entry/exit conditions
//**********************************************************************************
// Enter long conditions
c10 = c01[1] > c01[2]
c11 = countoflongshares < COSH
c12 = c03 > MOMLv
c14 = K[0] < v10
// Exit long conditions
c20 = c04[0] < c04[1]
c21 = close[0]-open[0] > LBL
c22 = c06[0] < c06[1]
// Enter short conditions
c30 = c01[1] < c01[2]
c31 = countofshortshares < COSH
c32 = c03 < MOMSv
c34 = K[0] > v90
// Exit short conditions
c40 = c04[0] > c04[1]
c41 = open[0]-close[0] > LBS
c42 = c07[0] > c07[1]
//**********************************************************************************
// Enter Long
//**********************************************************************************
if c05 and c10 and c11 and c12 and c13 = 1 and c14 then
buy PositionSize contract at market
endif
//**********************************************************************************
// Exit Long
//**********************************************************************************
if longonmarket and (c20 or c21 or c22) then
sell at market
endif
//**********************************************************************************
// Enter Short
//**********************************************************************************
if c05 and c30 and c31 and c32 and c33 = 1 and c34 then
sellshort PositionSize contract at market
endif
//**********************************************************************************
// Exit Short
//**********************************************************************************
if shortonmarket and (c40 or c41 or c42) then
exitshort at market
endif
//**********************************************************************************
// Stops and Targets
//**********************************************************************************
set stop ploss sl
set target pprofit tp
//GRAPH ((C-LL)/(HH-LL))*100
Ok, so my conclusion goes for the stochastic period, that must be superior to 1. If there is no bar (or “phantom bar”), the 1 period calculation leads to a division by zero at line 50.
You could also try this version of the calculation, it should also work with a 1-period:
K = ((C-LL)/max(pointsize,(HH-LL)))*100
JASS got rid of the stochastic and it was still stopped, but maybe he still ended up with a divide by zero error (if no bar or phantom bar) with his amended code. See his post here …
https://www.prorealcode.com/topic/trading-system-automatically-stopped/page/2/#post-116086
I will try your code Nicolas thank you.
Over 2.5 hours … so far so good using Nicolas code!
The no bar / phantom bar causing a divide by zero error would account for the Rejection / Stop being random … due to a no bar occurrence being random!
JASSParticipant
Junior
just returned home after a long day, will answer tomorrow
I moved the topic into the ProOrder section, it is now more related to automated trading coding than a platform issue.