Want to have a time limit how long a position may be open.
How does such a code look like?
Barney
WingParticipant
Veteran
once Counter=0
counter=counter+1
If counter>10 then
sell at market
endif
if buyconditions=true then
buy 1 lot at market
counter=0
endif
’10’ in this case is the amount of bars that the trade will stay open.
“Error in line 9 character 18
Please complete the syntax of the line”
When i past your code.
Perhaps i paste the code in wrong place?
Here is my code!
OMX30 15 min and 0,5p spread.
It don’t work good in downtrend, therefore i must have something that stops algon in long term downtrend.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[80](close)
indicator2 = Average[5](close)
c1 = (indicator1 CROSSES UNDER indicator2)
IF c1 THEN
BUY 2 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET TARGET pPROFIT 3
WingParticipant
Veteran
The last four lines of my code represent your own buy conditions, so you need to put this right after you buy the contracts.
counter=0
I have to be sluggish in the head.
Can you post the code where it should be. 🙂
I am new to coding…
WingParticipant
Veteran
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
once counter=0
counter=counter+1
if counter>10 then
sell at market
endif
// Conditions to enter long positions
indicator1 = Average[80](close)
indicator2 = Average[5](close)
c1 = (indicator1 CROSSES UNDER indicator2)
IF c1 THEN
BUY 2 CONTRACT AT MARKET
counter=0
ENDIF
// Stops and targets
SET TARGET pPROFIT 3
Does that work?
Yes, it works fine.
But my system did not like it.
It works well but in downtrend it don’t work so good.
What can i do to fix my problem…….
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[80](close)
indicator2 = Average[5](close)
c1 = (indicator1 CROSSES UNDER indicator2)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET TARGET pPROFIT 3
WingParticipant
Veteran
A stop loss maybe? Seeing as you have a a very low take profit, on relatively high time frame, make sure your system does not trick you because of the ‘zero bar issue’ though.