Backtesting: Buy order Problem ie BarIndex
Forums › ProRealTime English forum › ProOrder support › Backtesting: Buy order Problem ie BarIndex
- This topic has 4 replies, 3 voices, and was last updated 3 years ago by Nicolas.
-
-
08/09/2020 at 8:24 PM #141242
So I am still learning Pro Real Code syntax. I have a successful trading system i been using for years but finally want to get into automated trading and i want to do some back testing first.
So the system consist of 3 different conditions
- Todays close – The 10 day Moving Average of the close.
- Todays 10 day Moving Average – The 10 day Moving Average from 10 days ago
- Todays close – the close from 40 days ago.
if all three conditions are met (count = 3) then i want to buy 1 contract and go long. if all 3 conditions are not met (countb= -3) then i want to sell 1 contract. once we get long (or short) we tighten or loosen the stop depending on what the condition count (or count b) is at +3 +2 +1 -1 -2 -3.
I use daily (time frame) and regardless of the units (i use 200 units). Starting the backtest i need to skip the first 40 days of the data as all three of the conditions have not had time to be tested yet. I would assume i can use the “bar index” to determine when i can finally activate buy or selling but the system just doesn’t seem to work as I thought. If you use AMD you can see in my screen shot that the first buy signal is at 50 days it it should be may 18th on the 40th day. So my question is how do I use bar index or some other code to ensure that the buying and selling happens after the first 40 days?
Conqueror 3 Condition12345678910111213141516171819202122232425262728293031323334353637!!!!!!!!!!!Add to Variables!!!!!! x[1], Period[40], ATR[14]count=0countb=0MA = Average[period](Dclose(period))cond1= dclose(0)-average[period](close)cond2= average[period](close)-MAcond3= dclose(0)-dclose(x)if cond1>0 thencount=count+1endifif cond2>0 thencount=count+1endifif cond3>0 thencount=count+1endifif cond1<0 thencountb=countb-1endifif cond2<0 thencountb=countb-1endifif cond3<0 thencountb=countb-1endif// Buyingif barindex >40 thenif not LongOnMarket and count =3 thenbuy 1 contract at marketendifendifAny help would be greatly appreciated.
08/09/2020 at 9:30 PM #141252Todays close – the close from 40 days ago.
If TF = Daily then below code will satisfy condition.
PreLoad Bars are a default of 2000 so why wait 40 days using bar index?
1Close - Close[40]08/09/2020 at 10:31 PM #141256Sorry for my inexperience, but I am not sure what the “TF” means?
I attached another screen shot. the first arrow shows a 3+ condition. that should have been my first purchase not 10 days later. I just dont know why my code is not making the first purchase on the correct day. Clearly the indicator at the bottom says its a +3 day just not sure why the backtest is not picking it up correctly.
08/10/2020 at 8:16 AM #14127308/10/2020 at 8:16 AM #141274Because your code is waiting for barindex to be more than 40 bars, while it is not needed because history is preloaded and your MA and daily Close are already known at first bar when you launch the strategy. Try with this modified code:
1234567891011121314151617181920212223242526272829303132// !!!!!!!!!!!Add to Variables!!!!!! x[1], Period[40], ATR[14]count=0countb=0MA = Average[period](Dclose(period))cond1= dclose(0)-average[period](close)cond2= average[period](close)-MAcond3= dclose(0)-dclose(x)if cond1>0 thencount=count+1endifif cond2>0 thencount=count+1endifif cond3>0 thencount=count+1endifif cond1<0 thencountb=countb-1endifif cond2<0 thencountb=countb-1endifif cond3<0 thencountb=countb-1endif// Buyingif not LongOnMarket and count =3 thenbuy 1 contract at marketendif -
AuthorPosts
Find exclusive trading pro-tools on