Hello!
I’m a rookie when it comes to trading but I’m very interested in evolving within this area.
I just started to use PRT and I would like to find a good automatic strategy (don’t we all?). The way I’m trying to configure my strategy isnt really working because I need to enter the code-console and modify the code to be a little bit more complex than the regular UI allows me to build.
Is there any kind soul out there that would bother to help me with the code?
Criterias (see attached picture for number examples [1224.35] / [1227.00]):
- EXAMPLE: Go long WHEN; [Price (X)] / [Bolinger – (Y)] <= 0,99
- EXAMPLE: Go short WHEN; [Price (X)] / [Bolinger + (Z)] >= 1,01
I would very much appreciate help solving this!
Thanks in advance,
CJ
I assume Y and Z are in points/pips?
Do you want a simple indicator that plot the signals on the price chart or a complete automatic trading system?
Hello Nicolas,
Y and Z are points yes. Im trying to use this for backtesting as a start. I’ve tried to write some code by my own but it doesnt seem to do that I want.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
GoLong = close/BollingerDown[20](close)
c1 = (GoLong >= 0.9984)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
GoShort = close/BollingerUp[20](close)
c2 = (GoShort <= 1.001)
IF c2 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 4
SET TARGET pPROFIT 6
> 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! <<
Well, firstly did you try to graph your conditions?
graph c1 as "buy condition"
graph c2 as "sell condition"
So that you see clearly when a condition is met or not.
Oh thank you. I will do that in the future.
Yes I have tried to backtest it. currently im trying out the long-position.
As you can see in the attached picture you can see the code. Im trying to get -> IF price / bollinger down, in this example bollinger down is 1185 and price is 1183. 1183 / 1185 = 0,998. In the code im trying to specify so that take LONG position if the quote of price / bollinger down < 0.999 which would then go long in this example.. but it doesnt! Any clue why? Thank you for your fast replies btw!
GoLong = close/BollingerDown[20](close)
c1 = (GoLong < 0.999)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
Got hundreds of positions when I try your strategy. What timeframe and instrument did you test?
Hello,
I was trying to apply it on Gold 15 min. But although my attached example above was not triggered.. So it seem to be something wrong with my code, dont you think when looking at the example above? Thank you for trying out the code in your system!
Hi again Nicolas,
Basically what I want to do is a) Measure the difference between PRICE (not closing price) and BOLLDOWN. If the quota of these two variables (PRICE / BOLLDOWN) are for example <= 0,97 THEN I would like to go long with 1 contract. It feels like my code should do the work but when validating it by taking samples it doesnt take positions where I want it to.
Thank you,
CJ
Ok, I modify the logic of your code, I made 2 settings for the orders to trigger if the Close exceed the Bollinger Down (for a buy order) or the Bollinger Upper band (for a short order). The triggers are in percentage.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
buypercent = 0.1
sellpercent = 0.1
bc = (bollingerdown[20]-close)/bollingerdown[20]
sc = (close-bollingerup[20])/bollingerup[20]
if bc>=buypercent/100 then
buy at market
endif
if sc>=sellpercent/100 then
sellshort at market
endif
set target pprofit 10
set stop ploss 20
Thank you very much. It does what I want it to 🙂 Very very much appreciated! you’re a pro!