Fei_Participant
Junior
Hi,
It seems like countofposition will not work on earlier timeframe then the default time frame. is this a bug or a natural error ??
Eg.
timeframe (15minutes, updateonclose)
if countofposition[1]>0 then//this will not work...
Show15=1
//Do something on chart
endif
timeframe(default)
if not longonmarket then
buy 1 contract at market
endif
if longonmarket and countofposition[50]>0 then
Sell at market
endif
if Show15=1 then
SHow1=1
endif
Graph show1 as "show1"
show1=0
In your program, all codes below the “timeframe (15minutes, updateonclose)” line will be read and evaluated only once each 15 minutes. If you remove the “updateonclose”, it will be evaluated once every default timeframe period.
Fei_Participant
Junior
Hi Nicolas,
This would means that my code for the 15 minutes will hit 3 times (if the default time frame is 1 minute).
Right now it wont hit at all, as the countofposition[1]>0 (15minute) will not hit at all.
It seems to be stuck in countofposition constant zero.
Thanks for your speedily response btw!
Line 21 will display the final value of SHOW1 (which is 0), despite being the last line. It does not matter where you place GRPAH, it will always show values retained at the end of the code.
This would means that my code for the 15 minutes will hit 3 times (if the default time frame is 1 minute).
Without UpdateOnClose, it would refresh 15 times since there is 15 bars of 1 minute in a 15-minutes TF.
Without UpdateOnClose, it would refresh only 1 time at the end of the 15-minutes TF period.
But the result of your show15 variable will most likely be the same as the COUNTOFPOSITION[1] is the previous 15-minutes bar count of position !
la période de TF 15 minutes.
nicolas meant
with UpdateOnClose, it will refresh only 1 time at the end of the 15 minute TF period.
Fei_Participant
Junior
Hi Guys,
Thanks for replying, you can do a simple test on your end that you know will work for you too.
Just need to made use of countofposition as the key function in the higher timeframe then default.
i modify the code below to show exactly what i meant. You can just copy the code below to see if my interpretation is wrong.
Since 15 minutes, updateonclose. It should hit at least 5 times. but not once will it hit..
timeframe (15minutes, updateonclose)
if countofposition[1]>0 then
Show15=1
elsif countofposition[1]=0 then//even after multiple 15 minutes the count of position will still be 0
Show15=-1
endif
timeframe(default)/// set to 1minute
if not longonmarket and countofposition[100]=0 then
buy 1 contract at market
endif
if longonmarket and countofposition[100]>0 then
Sell at market
endif
if Show15=1 and longonmarket then
Show1=1
elsif show15=-1 and longonmarket then
show1=-1
endif
Graph show1 as “show1”
show1=0
>> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
🙂
Fei_Participant
Junior
Hi Nicolas,
because for the 15 minutes code, i use countofposition[1]>0 and for the 1 minute code i locked it to 100 countofposition.
So after the first 15 minutes and subsequent 15 minutes it should hit.
countofposition[1]>0 to countofposition[6]>0 should be valid in 15minutes timeframe
So it should hit 6 times :0
Fei_Participant
Junior
Hi All,
Just to further illustrate the error:
it seems that the error will occur only when using [] on count of position in the higher timeframe:
Please copy the code below to try it on your end and it will be clear.
timeframe (15minutes, updateonclose)
COP=0
if countofposition>0 then//long on market and Count of position should work the same
COP=1
endif
if COP[1]>0 then
COP15=1
else
COP15=0
endif
if countofposition[1]>0 then//long on market and Count of position should work the same
Show15=1
else
SHow15=0
endif
timeframe(default)/// set to 1minute
if not longonmarket and countofposition[100]=0 then
buy 1 contract at market
endif
if longonmarket and countofposition[100]>0 then
Sell at market
endif
if Show15=1 then// this should give same result as below//but this wont show
Show1=1
else
show1=0
endif
if COP15=1 then// this should give same result as below
COP1=1
else
COP1=0
endif
Graph show1 as "show1"
Graph COP1 as "COP1"
Thanks
Your code is a little confusing so I created this simple test code to try to see what is happening:
timeframe (15minutes, updateonclose)
COP15 = countofposition
COP15Back1 = countofposition[1]
timeframe(default)/// set to 1minute
if not longonmarket and countofposition[100]=0 then
buy 1 contract at market
endif
if longonmarket and countofposition[100]>0 then
Sell at market
endif
COP1=countofposition
COP1Back1 = countofposition[1]
Graph COP15 as "COP15"
Graph COP1 as "COP1"
Graph COP15Back1 as "COP15[1]"
Graph COP1Back1 as "COP1[1]"
The images show the results for both UPDATEONCLOSE and DEFAULT on the 15 minute time frame. There is definitely something weird going on because in UPDATEONCLOSE mode the 15 minute count of position does not change until the 15 minute bar closes which is what we would expect but if we check the previous bar it has changed to zero.
Then in DEFAULT mode the fifteen minute back one bar is not updating until the close of the fifteen minute bar when it should be updated every minute.
Hmmm ok, let me check before I ask how COUNTOFPOSITION is expected to work with MTF.