If by ‘next bar’ you really mean the current bar that is being checked to see whether the order should be sent to market then the problem is that you are using DHIGH which is the daily high when you should be using HIGH which is the current bars high.
I can highly recommend reading everything in the documentation here to help with understanding PRT coding more fully:
https://www.prorealcode.com/prorealtime-documentation/
Thank you Im currently reading those documents.
What I mean is. After the gap criteria has been meet. If price than crosses under the 50ma for the first time (a low will do). Than the next bar’s high must be higher than the 50ma. Than on the open of the following bar take the trade. So Im looking for confirmation the 50ma will hold as support. What Im trying to avoid is if prices just fall straight through the 50ma I dont want to take that trade.
Let me know if that clears it up? Cheers
starttime = 000000
startday = 1
gapneeded = 20 * pipsize
ma20 = average[20](close)
ma50 = average[50](close)
ma200 = average[200](close)
magap = ma20 - ma200
if (opentime = starttime and opendayofweek = startday) or onmarket then
crossflag = 0
gapflag = 0
endif
if ma20 crosses over ma200 then
crossflag = 1
endif
if crossflag and magap > gapneeded then
gapflag = 1
endif
if ma20 crosses under ma200 then
crossflag = 0
gapflag = 0
endif
if not onmarket and crossflag[1] and gapflag[1] and low[1] < ma50 and high > ma50 then
buy 1 contract at market
endif
SET STOP pLOSS 25
SET TARGET pPROFIT 25
thanks mate that works well !
I’ve got code below on Fwd Test on Demo, attached is equity curve for an open trade which was at > 55 gain and yet my Set TP = 30 didn’t trigger.
Anybody any ideas why TP not triggered (or do I need more coffee 🙂 )?
//-------------------------------------------------------------------------
// Main code : MA Hit DAX 5M v1.0
//-------------------------------------------------------------------------
//https://www.prorealcode.com/topic/first-hit-of-a-moving-average/page/2/
DEFPARAM CUMULATEORDERS = False
starttime = 000000
startday = 1
gapneeded = 2 * pipsize
ma20 = average[20](close)
ma50 = average[50](close)
ma200 = average[200](close)
magap = ma20 - ma200
if (opentime = starttime and opendayofweek = startday) or onmarket then
crossflag = 0
gapflag = 0
endif
if ma20 crosses over ma200 then
crossflag = 1
endif
if crossflag and magap > gapneeded then
gapflag = 1
endif
if ma20 crosses under ma200 then
crossflag = 0
gapflag = 0
endif
if not onmarket and crossflag[1] and gapflag[1] and low[1] < ma50 and high > ma50 then
buy 1 contract at market
endif
SET STOP pLOSS 25
SET TARGET pPROFIT 30
Did the order actually ever go to market or was it rejected for some reason? Check your orders list and on the chart to see if there is an order connected to the trade?
Yes the equity curve above is from clicking on Performance in the Auto-Trading window. Its is still trading see attached.
No cancelled or rejected in the Orders List for that System
Typical, I did a Technical Report, pressed send and the Platform has frozen now!
Don’t know if Technical Report went before the freeze up or not and of course there is no acknowledgment sent out!
I had to use Task Manager to close Platform!
Anyway the SAME trade has gone above gain of 30 AGAIN (I’m liking this strategy! 🙂 ) but the Set TP 30 has not triggered for the second time … well weird ???
2nd Technical Report sent! 🙁
@Vonasi … attached is the Order you were asking about.
That last image is the BUY order at 12506.4. There should also be an order to SELL at 12536.4
FYI – depending on where you live (I live in Australia), don’t set the start time @ 000000
I had this system on real trading and it took the first candle at the open which was a wide range bar with a very wide spread.
In fact, I couldn’t even see the price trade at the level I was stopped out at the same time I entered? very strange.
In any case I changed the start time to 100000 to avoid the opening mess
Ahaha … gotcha!
There are two pending orders, one for the Stop and one for the Limit. but the Limit of 30 has been met at least twice but not triggered a close / exit.