Hi, I’m struggling to pick up the lingo – mainly the financial stuff as I’ve got programming experience (but not been trading much). Apologies therefore for some stupid questions.
I’m looking for a very simple example that I can build on, e.g.:
1. Open 2 positions: BUY and SELL
2. If the BUY price goes up by X% compared to the opening rate, close the BUY position and then open another
3. If the SELL price goes down by X% compared to the opening rate, close the SELL position and then open another
4. If either position goes into the red by Y%, close it and then open another in the same direction
I only want one open position in each direction at any given time to limit exposure.
I tried the below but it didn’t seem to work (opened too many positions?):
Test code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Defparamcumulateorders=false
n=50// Number of shares
x=10// Profit
y=20// Max loss
// Only ever have one position open in each direction
IFNOTLONGONMARKETTHEN
buynsharesatmarket
ENDIF
IFNOTSHORTONMARKETTHEN
sellshortnsharesatmarket
ENDIF
// Close at profit or loss
set target%profitx
set stop%lossy
A few questions also:
a) Is the order fee taken into account for profit or loss (the last two lines in my example)?
b) I also can’t figure out why, when I use the ProBacktest, the timescale resolution drives the number of positions that get opened? I only want two (one in each direction) at any given time. What settings should I use to simulate this?
c) Do I need to set restrictions around trading days, e.g. not to buy/sell on Saturdays or Sundays or will orders for these days just be ignored?
Many thanks in advance for any pointers! Once I get up to speed I will of course share my success (fingers crossed) 🙂
a) No, orders in backtests are sent at mid level, order fees are added in the settings window manually.
b) It is not possible to hedge order with a contrarian one with ProBacktest/ProOrder. You can only buy or sell at the same time in the same strategy. Code is also read once per bar, at its Close.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue