Hi All
How to count the buy order will be realy executed and stop buying after 3 time :
Defparam cumulateorders = True
SMA10 = Average[10](close)
SMA20 = Average[20](close)
SMA100 = Average[100](close)
C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
IF C1 THEN
BUY 1 CONTRACTS AT MARKET
Count = Count + 1 // Only if the Purchase is executed
ENDIF
or a line number for Snippet also will be ok
Best Reguards,
ZeroCafeine
You have to use COUNT in your entry conditions, provided it is cleared when not on market:
Defparam cumulateorders = True
IF Not OnMarket THEN
Count = 0
ENDIF
SMA10 = Average[10](close)
SMA20 = Average[20](close)
SMA100 = Average[100](close)
C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
IF C1 AND (Count < 3) THEN
BUY 1 CONTRACTS AT MARKET
Count = Count + 1 // Only if the Purchase is executed
ENDIF
tks you so much for your quick answer, So I have to think like, I’m or not in market, when I see your answer it’s seems like easy, but I don’t know to think like that, I hope soon 😉
You have to use COUNT in your entry conditions, provided it is cleared when not on market:
tks again for your answers, But Once again, I have phrased my question incorrectly :
– How to count in the case of Limit order ? you can see in the photo, The conditions for the purchase were met except for the price limit
– we can also met the same situation in the case of my Buy order is filled (so at this time we are OnMarket) But if my order is closed because of a stop loss so we will be in the case of Not OnMarket (So Count = 0) even we execute the Buy only one time
I found this solution, maybe you have an other idea :
Defparam cumulateorders = True
if intradaybarindex=0 then // we reset Count every day
Count = 0
endif
SMA10 = Average[10](close)
SMA20 = Average[20](close)
SMA100 = Average[100](close)
C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
IF C1 AND (Count <= 3) THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
IF OnMarket AND Not OnMarket[1] THEN
Count = Count + 1 // Like thit we are sure to add 1 only if we are on market and the candle just before we are not on market
ENDIF
A better solution is to reset COUNT at the beginning of a new trading day:
IF IntraDayBarIndex = 0 THEN
Count = 0
ENDIF
the issue with pending orders can be addressed with this code, which detects a new entry (to be tallied when there are more positions on market than there were the prior candle:
Defparam cumulateorders = True
IF IntraDayBarIndex = 0 AND Not OnMarket THEN
Count = 0
ENDIF
SMA10 = Average[10](close)
SMA20 = Average[20](close)
SMA100 = Average[100](close)
myPos = abs(CountOfPosition)
Count = Count + (myPos > myPos[1])
C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
IF C1 AND (Count < 3) THEN
BUY 1 CONTRACTS AT low - 10*PipSize LIMIT
ENDIF
set target pprofit 100
set stop ploss 100
Actually, instead of checking positions, you might use:
Count = Count + LongTriggered
My subconscious found the solution while I slept last night, but with your solution on top of it, I’m lost …. 😅
Actually I’m joking 😊, again thank you for your answer I totally understand your solution and I will try to understand it even better,
About line 15, wouldn’t it be better to use the Close than Low, also maybe the Close +2 pips in limit for exemple
With a buy at Low – 10 pips, do I risk not getting executed and the market going without me ?
in the continuity of my code I realise that if I am in position and I take another position then my line 16 does not work so I had to add this :
IF OnMarket AND Not OnMarket[1] OR ABS(CountOfPosition) > ABS(CountOfPosition[1]) THEN
Count = Count + 1ENDIF
It seems to work, I’ll come back at the end of the day to do more tests and compare with your solution @robertogozzi which seems much simpler than mine and I think it does the job
That’s how it takes me more than 4 hours on Wednesday to have 15 minutes of concentration to understand what it is, I’m sick of this temporary office 🤣🤣🤣🤣
Wish me luck