This version waits for the breakout to occur, then places pending LIMIT orders to enter at a better price when it retraces to the range border (but you can enter AT MARKET if you prefer):
defparam flatafter = 210000
if longonmarket then
alreadybuy=1
endif
if shortonmarket then
alreadysell=1
endif
if intradaybarindex=0 then
alreadybuy=0
alreadysell=0
myprofit=strategyprofit
endif
if time = 060500 then
yh = highest[85](high)
yL = lowest[85](low)
endif
tcondition = time>074500 and time<205000
if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
if close>yh and not alreadybuy then
buy 1 contract at yh limit
endif
if close<yl and not alreadysell then
sellshort 1 contract at yl limit
endif
endif
set stop ploss 15
set target pprofit 15
Roberto, Many thanks for all your help. 😉
5mins, Wall Street.
Using today as an example, a LIMIT order would have entered at 12:00, after the re-test.
AT MARKET would have entered at 07:45, after the close under the yl.
Is it not possible to enter during the 07:40 candle, as it crosses the yl line, using any code?
I have changed the settings, crossover yl, low of yl, but the code seems to require a close below the yl, to setup the trades.
I have attached a chart to show examples, I would like to buy on the cross (not necessarily the close) of the yl or yh?
I can set a deal to open / limit order, through IG and they will buy/sell whenever.
I think I am going to have to give up shortly, but being so close and after all the help you have given me, it seems a shame. ;(
Replace LIMIT with STOP at lines 25 and 28, since you are willing to enter a new trade at a worse price, while LIMIT should be uses to enter at a better price, instead.
If the entry price is not exactly the one you wanted (which I experienced backtesting the trade you pointed out in your screenshot), I guess it’s due to the current price (last pending order placed at the closing of the bar preceding the entry one) being too close to your desired entry price.
Roberto,
Many thanks for looking into it again. 😉
I have changed it to STOP, but as you experienced in the backtest, it still doesn’t work all the time.
I’ll have to monitor it.
Thanks for all your help, it is much appreciated. 🙂
You can use IF…ENDIF to make it work at all times:
IF close > yH THEN //if current price is higher than YH then...
buy 1 contract at yH limit //... buy at a most favourable price
ELSIF close < yH THEN //if it lower, then...
buy 1 contract at yH stop //... buy at a worse price
ELSE //should it be the same price...
buy 1 contract at market //... buy immediately
ENDIF
if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
IF close > yH and not alreadybuy THEN//if current price is higher than YH then...
buy 1 contract at yH limit //... buy at a most favourable price
ELSIF close < yH THEN //if it lower, then...
buy 1 contract at yH stop //... buy at a worse price
ELSE //should it be the same price...
buy 1 contract at market //... buy immediately
ENDIF
IF close < yl and not alreadysell THEN//if current price is higher than YH then...
sellshort 1 contract at yl limit //... buy at a most favourable price
ELSIF close > yl THEN //if it lower, then...
sellshort 1 contract at yl stop //... buy at a worse price
ELSE //should it be the same price...
sellshort 1 contract at market //... buy immediately
ENDIF
ENDIF
This is picking up trades I was expecting, but it is also taking more trades.
I have added AND NOT ALREADY BUY / SELL to the above code, but it still produces 7 trades today, I was after 1 long / 1 short per day. (which is coded)
It should have entered at 08:25 only today. (Screenshot attached) For some reason it also entered at 08:30,13:45,13:50 etc.
The other point is that on the 24/10/18, even after your amended code, the short trade at 07:40 does still not occur. (Screen shot attached.)
Is it to do with the candle close and it going straight through the yl / yh.
The problem with ALREADYBUY/ALREADYSELL is that at lines 3 and 6 ProOrder takes 1 bar to become aware of being OnMarket. In case (as it happens) the pending orders is entered and exited within the same bar ProOrder will never be aware of them, thus leaving those variables unset.
That’s why so many trades are entered!
There’s no work around, unless you use MTF to launch your strategy from a lower TF (say 1 minute), but this won’t grant you that a single 1-minute bar cannot have a range of 15+ pips! For sure this solution will work in most cases, though not always. MTF is still being beta tested and not recommended for real trading.
Roberto,
Many thanks again. 🙂
I will have to keep monitoring the trades for the anomalies that are deleted by prorealtime.
Last question, (I sound like Columbo, 😉 ) Is there anyway prorealtime will alert me, SMS, when a trade is deleted?
I know they can SMS, when a trade is: opened/closed / edited.
What do you mean by DELETED?
Anyway, I think I cannot help you because I’ve never used that kind of alert.
I trade through IG and the trades get set up through the pro-order automatic trading system.
On the 24/10/18, Wall Street, 5m, using the system I had running, I had orders in the system at 25303.1 BUY & 25165.1 SELL.
At 7:40, Instead of selling short at 25165.1 the order got deleted (by ProOrder)
This happens every now and again, I don’t know why the trades get deleted?
(I did amend the time to 0730-2050 so it isn’t a time issue)
Thanks for your reply anyway. 🙂
All pending oreders are DELETED at every bar’s closure.
You need to place then again and again, bar after bar, if you wish to keep them pending.