Hi All,
In the past I have successfully programmed snippets of code in VBA and other languages … but I am struggling with counting in ProRealTime.
Having played with the variables and ran it in ProBacktest – it’s not getting much clearer to me.
What I am trying to do is Buy or Sell based on Condition 1 (C1) or Condition 2 (C2) respectively and close at the end of what would be the same 5 minute bar.
As I need to buy at the beginning of the 5 min candle and sell at the end, I have set the bar to 10 second so that I can buy 10 seconds after C1 or C2 is satisfied (beginning of second bar) and then count 29 more bars to close after 5 minutes i.e. 300 seconds.
// SET MARKET TIME TO 10 seconds
//DEFPARAM stuff here
IF time < 145000 THEN
stake = 1
x = 1
ENDIF
// time entry and exit limits here
IF timeEnterbefore AND timeEnterAfter AND NOT daysForbiddenEntry THEN
IF x = 1 THEN
IF NOT ShortOnMarket AND C1 THEN
BUY stake PERPOINT AT MARKET
SET STOP pLOSS 20 // Safety Stop
ENDIF
IF NOT LongOnMarket AND C2 THEN
SELLSHORT stake PERPOINT AT MARKET
SET STOP pLOSS 20
ENDIF
ENDIF
//End of Buying section and if nothing bought then onto bar increment x anyway
x = x + 1
IF x = 30 THEN
IF LongOnMarket THEN
SELL stake PERPOINT at MARKET
ENDIF
IF ShortOnMarket THEN
EXITSHORT stake PERPOINT at MARKET
ENDIF
x = 1
ENDIF
ENDIF
When run on Probacktest I get counts of 29 and other times 95 or other number of bars on the market.
I did start using a FOR/Next loop but had other problems …
Any ideas most welcome, Thank you!
What are timeEnterbefore AND timeEnterAfter?
Did you try to GRAPH x? To know if it is correctly incrementing?
Hi Nicolas,
The variables TimeEnterBefore = 150000 and TimeEnterAfter = 210000
I will have a look at ‘GRAPH x’
Thank you
The variables TimeEnterBefore = 150000 and TimeEnterAfter = 210000
I’m not sure you gave me the right values 🙂 It should be 2 boolean variables, and they are not!
Hi Nicolas,
The preceding lines were:
noEntryBeforeTime = 150000
timeEnterBefore = time >= noEntryBeforeTime
noEntryAfterTime = 210000
timeEnterAfter = time <= noEntryAfterTime
Thanks
Hi Nicolas,
Thank you for your time … suggesting ‘Graph x’ has allowed me to see step by step what is going on.
I haven’t figured out yet why I am losing a count of one but feel confident that being able to zoom in and examine the execution of the code in relation to the count of ‘x’ using ‘Graph’ I’ll have it sorted.
Thank you for your patience and advice.
Joe