I’m a bit new to coding so please bear with my silly questions?
I am trying to develop an entry using the Stochastic indicator, but am struggling to set up a couple of conditions.
I want to enter LONG when:
- The Stoch %K has been below 20% i.e. oversold
- Then it Crosses Over Stoch %D
- And then moves above 25%
I am struggling to code the sequencing i.e. has been below 20% but now has crossed over and is above 25% – I guess the main thing I want to know is about setting a condition (trading below 20%) and the the code remembering it for the next phase of the filter?
Any help would be most grateful – I’ve attached my attempt at this part of the code and a marked up screen shot
// Conditions to enter long positions
TIMEFRAME(2 minutes,UpDateOnClose)
indicator1 = Stochastic[15,5](close)
indicator2 = Average[5](indicator1)
Period = (indicator1[1] AND indicator2[1]) OR (indicator1[2] AND indicator2[2])
c1 = Period < 20
c2 = close > close[1]
c3 = (indicator1 > 25)
IF (c1 AND c2 AND c3) AND tcondition AND not daysForbiddenEntry THEN BUY 1 PERPOINT AT MARKET ENDIF
TIMEFRAME(default)
Welcome to the forums – I see this is your first topic and post.
Please use the ‘Insert PRT Code’ button when posting code as it makes it so much easier for others to read. I have tidied up your post for you. 🙂
Firstly, you want to code a strategy, but you posted on the wrong forum (ProBuilder, reserved to indicators/oscillators). I’ll move it to ProOrder.
At line 7 you are assigning PERIOD a logical value, true (1) or false (0). In both case it’s < 20 so C1 at line 7 will ALWAYS be true! (it will be replaced by new lines 11-13). It must be changed to check K has crossed over D:
c1 = indicator1 CROSSES OVER indicator2
Line 10 looks good, it just makes sure the prise is going north.
Line 11 needs to be changed and made of three lines to make sure it has both crossed over 20 and 25 at the same time or it just crossed over 25 and the previous candle had crossed over 20:
c3a = (indicator1 CROSSES OVER 20)
c3b = (indicator1 CROSSES OVER 25)
c3 = (c3a[1] OR c3a) AND c3b
Finally, line 13 cannot be written like that, did you ever test this piece of code? NO, otherwise you’d have been warned about this syntax error. IF and ENDIF cannot be on the same line AND the action to be taken must be in between:
IF (c1 AND c2 AND c3) AND tcondition AND not daysForbiddenEntry THEN
BUY 1 PERPOINT AT MARKET
ENDIF
Thanks for this Robertogozzi,
I appreciate your reply and insight, I’ll give it a go.
Kind regards
Steve