Hi Everyone
I am quite new to ProRealTime. I have made a number of short programs, but am puzzled by my latest program which gives entries and exits seemingly at random. I have created the program with ‘simplified creation’ and then modified it slightly (same result without any modification as well).
It is very simple. When two moving averages (21 and 50 period) are both moving up I want to create a buy order. When the 21 starts to move down I want to close the position. I am running the code on the US 500 Cash 5 min market. The code even enters a buy when both moving avergaes are moving down. I am very confused.
Last point, if one creates a Hull moving average with the simplified creation, the code defaults to simple moving average. There does not seem to be a programming option for the Hull at all. I have seen other people say similar on the forums but no definitive answer to date.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[21](close)
c1 = (indicator1 >= indicator1[1])//21 period average is sloping positive
indicator2 = Average[50](close)
c2 = (indicator2 >= indicator2[1])//50 period average is sloping positive
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = Average[21](close)
c3 = (indicator3 < indicator3[1])//close when 21 period average is sloping negative
IF c3 THEN
SELL AT MARKET
ENDIF
What timeframe are you running your code on?
I ask because if a low TF (1 min, 5 min) then it may be difficult to spot the difference of say 1, 2 or a few pips on the MA’s??
Give an example of a random entry / exit date & time and I’ll try and reproduce on my Platform.
Hi GraHal
I am using this on the 5 min chart. See attachment for trades over the last few hours. Time is CET +1.
At 22:15 there is an entry an 1 candle later an exit. Both MA’s are moving downwards so there should not be any entry.
Thank you
Analyst – Welcome to the forums.
Your topic has been moved to the ProOrder forums as it is a strategy related topic rather than a general discussion. Please try to post in the correct forum with future topics. 🙂
What instrument are you testing on? It is not mentioned in your first post or shown in your screen shot. We cannot recreate what is happening without all the info!
Also are you sure that the MA’s on your chart are the same as in your code? Just trying to eliminate the usual basic mistakes before delving deeper.
Using GRAPHONPRICE to show the MA values directly from the strategy is usually a good way to avoid confusion.
I am doing this on the US 500 Cash (see first post). The attachment is for this market.
There you go … using GRAPH and Cursor details (as Vonasi suggested) … shows that in fact Ind1 and Ind2 are rising as per your entry code.