Hi , I am trying to learn hoe to code a programme and I am having some issues. I would like to try optimization , but I am not sure where to put my variable for a stop.
My variable is called “stop” ,
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = MACDline[12,26,9](close)
indicator2 = ExponentialAverage[9](indicator1)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = MACDline[12,26,9](close)
indicator4 = ExponentialAverage[9](indicator3)
c2 = (indicator3 CROSSES UNDER indicator4)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = MACDline[12,26,9](close)
indicator6 = ExponentialAverage[9](indicator5)
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = MACDline[12,26,9](close)
indicator8 = ExponentialAverage[9](indicator7)
c4 = (indicator7 CROSSES UNDER indicator8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET stop pLOSS 30
I have tried replacing the 30 with [stop] but it does not work. Any help really appreciated for a newbie.
Please use the ‘Insert PRT Code’ button when putting code in your posts. I have tidied up your post for you.
Also in future posts please try to use a topic title that means something rather than just ‘Basic coding help’. I will change your topic title to something more meaningful.
You can not use the variable name ‘stop’ as it is an instruction used in PRT code already. Change it to SL or something similar.
The last line of your code would then be:
set stop ploss SL
Perfect , thanks. And will make sure I do it right next time,
indicator7 = MACDline[12,26,9](close) indicator8 = ExponentialAverage[9](indicator7) c4 = (indicator7 CROSSES UNDER indicator8) IF c4 THEN EXITSHORT AT MARKET ENDIF
You sure you don’t want above to read CROSSES OVER ??
Great username Forexsake btw! 🙂
Hi Grahal. I will have a look at that tonight thanks. I did think a lot about my username and I now use it for all forums etc.. I was quite impressed I came up with something a tad humorous..