So I’ve made a beginner system, but that’s not important I’ve set it up for when stochastic goes below 75 it should sell and when above 25 it should buy. why the hell is it not doing anything?
I placed some red lines where I belive it should’ve taken action but it didn’t…
any suggestions welcome thanks!
We need code to tell what’s going wrong.
Hi Robert, good idea. Thank you for your reply.
<
//-------------------------------------------------------------------------
// Main code : 1 Hour 100/200 SMA STO 14,3,3
//-------------------------------------------------------------------------
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[100](close)
indicator2 = Average[200](close)
c1 = (indicator1 CROSSES OVER indicator2)
indicator3 = Stochastic[14,3](close)
c2 = (indicator3 > 25)
IF c1 AND c2 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
// Conditions to enter short positions
indicator4 = Average[100](close)
indicator5 = Average[200](close)
c3 = (indicator4 CROSSES UNDER indicator5)
indicator6 = Stochastic[14,3](close)
c4 = (indicator6 < 75)
IF c3 AND c4 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 150
SET TARGET pPROFIT 300
It is difficult to tell from your image as I can’t tell which lines are which averages but your code expects the cross and the level of stochastic conditions to be met on the same bar whereas from your image it appears that you are expecting the cross to happen and then a trade to be entered when the stochastic level is crossed a few bars later. Am I right?
Yes that’s correct, thank you for your reply. Id like the stochastic to work after the cross happens on the SMA. How would you go about fixing this? I’m very much a beginner…
You would need to set a flag when each event happens and then only enter when both flags are true. Something like this might work but I’ve not tested it:
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[100](close)
indicator2 = Average[200](close)
indicator3 = Stochastic[14,3](close)
if indicator1 CROSSES OVER indicator2 then
cross = 1
endif
if indicator3 crosses over 25 then
stochlevel = 1
over
if indicator1 CROSSES UNDER indicator2 then
cross = -1
endif
if indicator3 crosses under 75 then
stochlevel = -1
IF cross = 1 AND stochlevel = 1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
IF cross = -1 and stochlevel = =1 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 150
SET TARGET pPROFIT 300
Thanks for your reply Vonasi.
I’ve not come across this problem before, it says I have a syntax error on line 34 yet I don’t have a line 34? how on earth do I fix that?
Assistance much appreciated.
Line 12 and line 20 are both missing a matching ENDIF, so at the end of the code an error message is output.
..also line 27 has an extra = instead of a – sign..
More haste, less speed, Vonasi!
More haste, less speed, Vonasi!
Looking at the time that I posted it is probably more haste, less beer!
I think we should all leave a line or two out of our code when providing it for others and see if they can work it out on their own. Nothing in life should come too easy!
Of course the endifs where missing! I managed to correct line 27 myself but am still learning. Thanks for your help!
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[100](close)
indicator2 = Average[200](close)
indicator3 = Stochastic[14,3](close)
if indicator1 CROSSES OVER indicator2 then
cross = 1
endif
if indicator3 crosses over 25 then
stochlevel = 1
endif
if indicator1 CROSSES UNDER indicator2 then
cross = -1
endif
if indicator3 crosses under 75 then
stochlevel = -1
endif
IF cross = 1 AND stochlevel = 1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
IF cross = -1 and stochlevel = -1 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 150
SET TARGET pPROFIT 300
Just to redeem myself the above is the corrected code – I still have no idea if it works or is what you want but at least this one was done after only one beer! 🙂