Hi Traders,
I am new to the ProReal Time software as well as coding. I am working on a basic Breakout strategy to get started. I have some problems with setting the breakout time correctly and it seems like the the “HIGH” and “LOW” are 10 minutes before my settings in the code. Example below the breakout time is set between 09:00 and 09:30 but when running the backtest it seems to take the high and low 08:50 – 09:20. Accept for that it seems to be working. there can only be 1 trade per day and the TP and SL are set value. Please comment if you see anything alse that could be improved when it comes to coding. I know this strategy doesnt deliver any great result at this point, but right now I am just interesting in learning the ProReal Time coding.
Thanks!
Defparam cumulateorders = false
// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the “FLATBEFORE” time.
DEFPARAM FLATBEFORE = 093000
// Cancel all pending orders and close all positions at the “FLATAFTER” time
DEFPARAM FLATAFTER = 172459
n = 240
//code
ONCE hi=undefined
ONCE lo=undefined
Rule1b = (barindex-tradeindex>=(12*10))
if time<090000 then
hi=high
lo=low
elsif time<093000 and time>=090000 then
hi=max(high,hi)
lo=min(low,lo)
trade = 0
ENDIF
IF trade = 0 AND Rule1b THEN
BUY n SHARES at HI STOP
ENDIF
IF longonmarket THEN
trade = 1
SET STOP pLOSS 36
SET TARGET pPROFIT 40
ENDIF
IF trade = 0 AND Rule1b THEN
SELLSHORT n SHARES at lo STOP
ENDIF
IF shortonmarket THEN
trade = 1
SET STOP pLOSS 56
SET TARGET pPROFIT 28
ENDIF
To write code, please use the <> “insert PRT code” button to make code easier to read and understand. Thanks.
Roberto
TIME refers to the Close of the candlesticks, you can use OPENTIME instead.
For 1 trade each day, you can use the code provided in this topic: trade only once per day.
(there are also a lot of other topics in forums about it!).
Maybe the LOW’s and HIGH’s before 090000 are not broken from 090000 and 093000!
Add these two lines after line 35 to debug their values and identify what the issue might be:
GRAPH hi
GRAPH lo