Help identifying a mistake in this simple Forex breakout code
Forums › ProRealTime English forum › ProOrder support › Help identifying a mistake in this simple Forex breakout code
- This topic has 2 replies, 2 voices, and was last updated 7 years ago by
Juan Salas.
-
-
06/25/2017 at 12:14 PM #38990
Hi Colleagues,
I am posting this strategy well known by most of you, but with some slight modifications. I would APPRECIATTE if someone could identify what is wrong.
It seems to work but I cannot get all the conditions right in the backtest. I am new with programming, and I am frustrated with this system because I cannot get one operation everyday, or when I get it, the system is launching the orders at the same time everyday, etc.
The system is a simple morning breakout for EUR-USD (TF: 15 min).
1.Starts at 08:00h and collect the highest and lowest from the last 12 candlesticks (from 05:00 to 08:00h).
2. After 08:00h, when the price breaks the highest of the channel + 3 pips, or the lowest of the channel– 3 pips, buy long or sell short (in the same candle, not at the opening of the next candle).
3. Stops and Target Profits finish the trading.
4. Only operates once a day, regardless if the trade was positive or negative.
5. The system will shut down at 14:00h. Any open trade will be close at that time.
6. I have included a NON OPERATING condition, in case the range of the channel of the 12 candlesticks is bigger than 32 pips.
Although it seems very basic and the equity curve is not very attractive right now, I like the fact that I can control the operations once a day and limit and daily monitoring the results. It is a matter of adding other currencies everyday, and creating different schedules for US and Asian markets (i.e.- I could have 5 currencies from 0800 to 1400, 5 from 1500 to 2200, and other five overnight for Asian market). It is just a matter, once it works, to change the time in the code).
Thanks so much in advance,
Juan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// FOREX BREAKOUT// 15 MIN// One trade per day, from 08:00h to 14:00. The system shuts-down at 14:00h// Everyday Channel formation from 0500 to 0800 (Highest-Lowest)// Maximum Range 32pipsDEFPARAM CUMULATEORDERS = false// OPERATIONAL TIMEDEFPARAM FLATBEFORE = 080000DEFPARAM FLATAFTER = 140000Operationaltime = TIME > 080000 AND TIME < 140000// ONE TRADE PER DAY. It resets the variable each new dayIF INTRADAYBARINDEX = 0 THENalreadytraded = 0ENDIF// RANGE between 0500h to 0800hIF TIME=080000 THENchannelhigh = Highest[12](high)channellow = Lowest[12](low)ENDIF// NO ACTIVITY if the range (highest-lowest)is >= 32 pipsIF channelhigh-channellow>=32*pipsize THENtradeok=0ELSEtradeok=1ENDIF// LONG Positions-OpeningIF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THENBUY 1 CONTRACT AT channelhigh + 3*pipsize STOPtradeok = 0alreadytraded = 1ENDIF// SHORT Positions-OpeningIF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THENSELLSHORT 1 CONTRACT AT channellow - 3*pipsize STOPtradeok = 0alreadytraded = 1ENDIF// STOP & PROFITSET STOP LOSS 8*pipsizeSET TARGET PROFIT 12*pipsize06/25/2017 at 12:37 PM #38995Your pending stop orders will only last 1 single bar in your code. Pending orders must be set each bar, because they only last 1 candlestick. In order to let the system put the STOP Orders continuously at each new bar until one of them triggered you should try this modified code instead:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// FOREX BREAKOUT// 15 MIN// One trade per day, from 08:00h to 14:00. The system shuts-down at 14:00h// Everyday Channel formation from 0500 to 0800 (Highest-Lowest)// Maximum Range 32pipsDEFPARAM CUMULATEORDERS = false// OPERATIONAL TIMEDEFPARAM FLATBEFORE = 080000DEFPARAM FLATAFTER = 140000Operationaltime = TIME > 080000 AND TIME < 140000// ONE TRADE PER DAY. It resets the variable each new dayIF INTRADAYBARINDEX = 0 THENalreadytraded = 0ENDIF// RANGE between 0500h to 0800hIF TIME=080000 THENchannelhigh = Highest[12](high)channellow = Lowest[12](low)ENDIF// NO ACTIVITY if the range (highest-lowest)is >= 32 pipsIF channelhigh-channellow>=32*pipsize THENtradeok=0ELSEtradeok=1ENDIF// LONG Positions-OpeningIF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THENBUY 1 CONTRACT AT channelhigh + 3*pipsize STOPENDIF// SHORT Positions-OpeningIF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THENSELLSHORT 1 CONTRACT AT channellow - 3*pipsize STOPENDIF//test if an order is on marketif onmarket thentradeok = 0alreadytraded = 1endif// STOP & PROFITSET STOP LOSS 8*pipsizeSET TARGET PROFIT 12*pipsizeThis is a rough and quick Sunday afternoon fix, not tested 😉
06/25/2017 at 1:46 PM #38997Hi Nicolas,
Thanks so much for your prompt response, especially on Sunday. You are super reliable for everyone here.
I will test it myself 😉
Have a great day,
Juan
-
AuthorPosts
Find exclusive trading pro-tools on