Hi guys,
This one is driving me nuts. I’m trying to code a very simple strategy:
“If close within 10% of range – buy on open next day. Then sell on first profitable opening.”
This is what I got so far:
varrange = high - low
varinrange = low + (varrange/10)
//Check if yesterday closed within 10%
IF close > low AND close < varinrange AND intrade = 0 THEN
varbuy = 1
intrade = 1
price = open
ELSE
varbuy = 0
ENDIF
//Check if open above paid price
IF open > price AND intrade = 1 THEN
varsell = 1
intrade = 0
price = 0
ELSE
varsell = 0
ENDIF
// Conditions to enter long positions
IF NOT LongOnMarket AND varbuy = 1 THEN
BUY 50 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
If LongOnMarket AND varsell = 1 THEN
SELL AT MARKET
ENDIF
I got as far as to enter correctly, but I cant exit without at least a days delay. I seems that PRT doesnt work “in the moment”, it looks at an entire bar and takes action the next day. Is there a way to exit as it happens? In this case I want to get out as soon as we open with a win.
Hello Noren,
You are right, each condition are tested only once at each new bar open. This Prorealtime engine behaviour will be soon changed to a whole new way to deal with it : each condition will be tested on every timeframe bars. From the one you are trading to the smaller one below it.
What you can do here with your strategy is to simply test if the price goes up or down at each new bar. So if you are long and price has raised up, exit your position and vice-versa.
Hi Nicolas,
I’m not following, how will that help me? Wouldnt I still get a one day delay with PRT’s behavior?
Even if price goes up, it could still close below. I need to confirm that open above entry before I could do anything and exit immediately once that happens… Perhaps its just not possible without those engine changes…
Cheers
It will help your strategy not to wait an entire day (if you are trading on a daily basis) to see what happened. The backtest engine will loop all timeframes from the daily one to the 1 minute one to test each of your strategy conditions.
Could you kindly provide a simple example to help me understand better?
While your strategy is running on a Daily timeframe (1 bar = 1 day = 24 hours), on backtest, all your conditions will be tested like this :
Backtest of the X bar on Daily TF -> conditions tested on each 1 hour bar -> conditions spotted on the Nth bar of the day -> conditions tests on each minute of the Nth bar previously spotted -> Found the minute where the conditions occured -> Execute SL/TL/TRAILING or anything else on the prices of the bar -> Go on next Y bar on Daily TF -> and so on ..
That I understand, what I dont get is how the actual code for that would look like. I mean what does the code looks like where I check if the price is above entry and exit in the same bar?
Your code don’t have to be adapted to this future improvement of the backtest engine. Actually, if you want to deal with your orders, you can browse all the instructions available in the online prorealtime documentation, Probacktest specific, here : http://www.prorealcode.com/documentation/category/probacktest/
Also, if you want to store your price entry whenever you enter the market, you just have to create new variables and store the open price. Then, make conditional loop for anything you want around this data.
Hope, that I understand clearly your question 🙂
Nicolas I feel that there is a bit of a language barrier here 🙂
I know that there is online documentation, i’ve read it, but i’m still stuck. Could you please provide an actual code example that implements what you are saying. That will allow me to study your solution in a different way.
Cheers
Ok, please find below your strategy modified :
varrange = high - low
varinrange = low + (varrange/10)
//Check if yesterday closed within 10%
conditionBUY = close > low AND close < varinrange
// Conditions to enter long positions
IF NOT LongOnMarket AND conditionBUY THEN
BUY 10 CONTRACTS AT MARKET
openprice = open
ENDIF
// Conditions to exit long positions
If LongOnMarket AND Close-openprice>0 THEN
SELL AT MARKET
ENDIF
Great I will try take a closer look tomorrow. Thank you very much for your patience Nicolas!
ps.
Great site, it is much needed! Not a lot of help out there when it comes to PRT.
Thanks a lot Jerry. I count on you to spread the good news : “PRT SUPPORT? GO PROREALCODE.COM” 🙂
Great stuff Nicolas, works like a charm now, thanks!
Yeah, you can definitely count on me spreading the word. I’m also here to stay 😉
shugParticipant
Junior
Nicolas Hi
I have just came across your code above, (the one you helped Jerry with), I’m no programmer but I thought it would have been simple to modify the same code for just sell trades, couldn’t be further from the truth. What my missing? Its not a massive code, could you share the same code for just sell trades? That would be great if you could. I’m in the process of learning the coding language and the platform most of my trading for the last 7 years is through cmc markets but i’m looking at joining I.G Index to get access to the prorealtime platform.
Hi Shug, below might be the code for SellShort?
Results for Long and Short attached on DAX @ 5 min TF spread = 2 on 10k bars only!
I only did 5 min TF out of interest, the strategy (I believe? ) is for Daily TF?
DEFPARAM CUMULATEORDERS = False
varrange = high - low
varinrange = High -(varrange/10)
//Check if yesterday closed within 10%
conditionSellShort = close < High AND close > varinrange
// Conditions to enter long positions
IF NOT Shortonmarket AND conditionSellshort THEN
SellShort 10 CONTRACTS AT MARKET
openprice = open
ENDIF
// Conditions to exit long positions
If Shortonmarket AND openprice - Close >0 THEN
ExitShort AT MARKET
ENDIF