Struggling to code a DAX scalping strategy
Forums › ProRealTime English forum › ProOrder support › Struggling to code a DAX scalping strategy
- This topic has 3 replies, 4 voices, and was last updated 3 years ago by
smp.
-
-
04/19/2021 at 11:57 AM #167501
Ladies and gents
I am struggling to code a strategy to scalp the open of the DAX that I think should be vey simple,
Staggery is,
1min candles on the open of the DAX,
At the open find the high and the low from the pre trading (7pm to 8pm UK time)
1.when the price breaks above or below this point enter a trade with a 15pt stop loss and a 30 Take profit,
so far this works fine, however I am struggling to code the next bit, the attached code just does not seem to work
2. if the profit goes up to 15 points (1R) move the stop loss to break even
3. if I get stopped out I re-enter if the price crosses the original entry point in the same direction as the original trade
my full code is below
re-entry not working123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 080100timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 093000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0///set pounds per pointppp=1// set variables to zeroonce tradestoday =0Once shorttradestoday =0Once longtradestoday =0if time = 010000 thenlongtradestoday =0shorttradestoday =0tradestoday =0endif//// the pretrade high amd lowif time = 080000 thenpretradehigh= highest[60](high)pretradelow= lowest[60](low)Endif// Conditions to enter long positions on first movec1 = close > pretradehigh And (Time < 083000) And tradestoday <1 and longtradestoday=0 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntryIF c1 THENBUY PPP PERPOINT AT MARKETlongtradestoday =longtradestoday+1tradestoday = tradestoday+1ENDIF// Conditions to enter short positions on first movec2 = close < pretradelow And (Time < 083000)And tradestoday <1 AND shorttradestoday=0 And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntryIF c2 THENSELLSHORT PPP PERPOINT AT MARKETshorttradestoday = shorttradestoday+1tradestoday = tradestoday+1ENDIF// Conditions to enter long positions againc10 = longtradestoday =1 and close > pretradehigh And (Time < 092000) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not OnmarketIF c10 THENBUY PPP PERPOINT AT MARKETlongtradestoday =longtradestoday+1tradestoday = tradestoday+1ENDIF// Conditions to enter short positions againc20 = shorttradestoday = 1 And close < pretradelow And (Time < 092000)And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not OnmarketIF c20 THENSELLSHORT PPP PERPOINT AT MARKETshorttradestoday = shorttradestoday+1tradestoday = tradestoday+1ENDIF/// set new SL to break evenIf LongOnMarket And High > (tradeprice(1) +15) ThenSET STOP pLOSS 0EndifIf ShortOnMarket and low < (tradeprice(1) -15) ThenSET STOP pLOSS 0Endif// Stops and targetsSET STOP pLOSS 15Set Target pProfit 3004/19/2021 at 11:49 PM #167558Try this one:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 080100timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 093000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//set pounds per pointppp=1// set variables to zeroonce tradestoday =0Once shorttradestoday =0Once longtradestoday =0if time = 010000 thenlongtradestoday =0shorttradestoday =0tradestoday =0endif//reenter in case SL is hitif StrategyProfit < StrategyProfit[1] thenIF LastTrade = 1 THENlongtradestoday =1ELSIF LastTrade = 2 THENshorttradestoday =1ENDIFendif// the pretrade high amd lowif time = 080000 thenpretradehigh= highest[60](high)pretradelow= lowest[60](low)Endif// Conditions to enter long positions on first movec1 = close > pretradehigh And (Time < 083000) And tradestoday <1 and longtradestoday=0 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntryIF c1 THENBUY PPP PERPOINT AT MARKETlongtradestoday =longtradestoday+1tradestoday = tradestoday+1ENDIF// Conditions to enter short positions on first movec2 = close < pretradelow And (Time < 083000)And tradestoday <1 AND shorttradestoday=0 And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntryIF c2 THENSELLSHORT PPP PERPOINT AT MARKETshorttradestoday = shorttradestoday+1tradestoday = tradestoday+1ENDIF// Conditions to enter long positions againc10 = longtradestoday =1 and close > pretradehigh And (Time < 092000) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not OnmarketIF c10 THENBUY PPP PERPOINT AT MARKETlongtradestoday =longtradestoday+1tradestoday = tradestoday+1LastTrade = 1ENDIF// Conditions to enter short positions againc20 = shorttradestoday = 1 And close < pretradelow And (Time < 092000)And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not OnmarketIF c20 THENSELLSHORT PPP PERPOINT AT MARKETshorttradestoday = shorttradestoday+1tradestoday = tradestoday+1LastTrade = 1ENDIF// Stops and targetsSET STOP pLOSS 15Set Target pProfit 30//Breakeven of 15 pips reachedIF Not OnMarket THENExitPrice = 0LastTrade = 0ENDIFIF (PositionPerf * PositionPrice) >= 15 * PipSize THENExitPrice = PositionPriceENDIFIF ExitPrice THENSELL AT ExitPrice STOPEXITSHORT AT ExitPrice STOPENDIF04/20/2021 at 9:03 AM #167577- Give your topic a meaningful title. Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’. Your title has been edited.
11/11/2021 at 4:14 PM #181456I am struggling to code a strategy to scalp the open of the DAX that I think should be vey simple,
Try this, active risk management to the upside as the downside always go straight to stop if wrong. A little 5 min direction to stop false breaks
See what you think?
-
AuthorPosts
Find exclusive trading pro-tools on