Hi,
I cant get this to work, I opens one order per bar:
defparam preloadbars =4000
// Conditions to enter long positions
indicator1 = close
indicator2 = TriangularAverage[4000](close)
c1 = (indicator1 > indicator2)
c2 = (indicator1 < indicator2)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF c2 THEN
sellshort 1 CONTRACT AT MARKET
ENDIF
// Counts the number of open shares or lots.
MAXSHARES = COUNTOFPOSITION <= 3
//let's add another order while price continue to get higher (more than 10 points)than the last order taken with a condition of 5 bars elapsed since then
IF TRADEINDEX(1)>n AND Close-TRADEPRICE(1)>10 AND LongOnMarket AND MAXSHARES THEN
BUY 1 SHARES AT MARKET
ENDIF
//let's add another order while price continue to get lower (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then
IF TRADEINDEX(1)>n AND TRADEPRICE(1)-Close>10 AND ShortOnMarket AND MAXSHARES THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
//trailing stop for the whole orders
SET STOP pTRAILING 15
Please help.
Hi,
Where is defined your “n” variable?
What is your problem exactly? You mentioned that you opened an order per bar, which is correct at first view of your code. Because, while c1 or c2 is true you open a trade and they are always true obviously! 🙂
IF NOT ONMARKET THEN
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF c2 THEN
sellshort 1 CONTRACT AT MARKET
ENDIF
ENDIF