Hi im trying to use the probuilder to create a simple Macd auto strategy that will open both long and short positions on the FX market, but the simple help screen wants to turn each trade off when it makes a new 1.
Knowing that the FX market bounces up and down quite a bit, my aim is to set a take profit point of say 50, and then at some point the trades will close out given the continual up/down nature of the market, im not really concerned with how many open orders it might create initially, but over time all orders should close out. Its just a theory for now, but would like to try it out on the demo b4 going live if it gives some decent results, basically in theory all trades will close out at a profit, its just a matter of time, and its that time factor i want to test.
you can see on the attached chart pic, its creating an order every tic basically, but looking at the Macd chart, theres only 4 times it crosses
heres the code that i have started with, any help would be much appreciated.
Cheers
DJ
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = MACD[6,13,8](close)
c1 = (indicator1 >= indicator1)
IF c1 AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
indicator2 = MACD[6,13,8](close)
c2 = (indicator2 >= indicator2)
IF c2 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET TARGET pPROFIT 50
Conditions C1 and C2 are ALWAYS true, because each bar the indicator is = to itself!
You should change the conditions.
Writing >= is useless, just use = since no indicator can be > itself!
The first candle enters a Long position, since Long’s are evaluated first despite C2 is also true, the next candle Long’s are ignored, despite C1 being true, because you can’t cumulate orders, but C2 is true so it closes any open Long position and enters a Short positions and so on.
It simply does a Close & Reverse each candle.
You should define better conditions to suit your needs.
All good and true advice from Roberto … now you now why it didn’t work.
Try below … should get you going to test your theory out and move forward onto a better strategy (as Roberto advises).
You will need deep pockets though! 🙂
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = MACD[6,13,8](close)
c1 = (indicator1 > indicator1[1])
IF c1 AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
indicator2 = MACD[6,13,8](close)
c2 = (indicator2 < indicator2[1])
IF c2 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET TARGET pPROFIT 50
Good point GraHal, thank you!
cool thanks guys, i knew it would be some thing small, will test run it.
Cheers
DJ
Backtest with fixed spread = 1.5 (on eurusd for example) and tick by tick mode selected else you will get misleading results.
Best you come back on here with any code and results before put real money at risk … we don’t want you to get wiped out. 🙁