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
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 080100
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 093000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
///set pounds per point
ppp=1
// set variables to zero
once tradestoday =0
Once shorttradestoday =0
Once longtradestoday =0
if time = 010000 then
longtradestoday =0
shorttradestoday =0
tradestoday =0
endif
//// the pretrade high amd low
if time = 080000 then
pretradehigh= highest[60](high)
pretradelow= lowest[60](low)
Endif
// Conditions to enter long positions on first move
c1 = close > pretradehigh And (Time < 083000) And tradestoday <1 and longtradestoday=0 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry
IF c1 THEN
BUY PPP PERPOINT AT MARKET
longtradestoday =longtradestoday+1
tradestoday = tradestoday+1
ENDIF
// Conditions to enter short positions on first move
c2 = close < pretradelow And (Time < 083000)And tradestoday <1 AND shorttradestoday=0 And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry
IF c2 THEN
SELLSHORT PPP PERPOINT AT MARKET
shorttradestoday = shorttradestoday+1
tradestoday = tradestoday+1
ENDIF
// Conditions to enter long positions again
c10 = longtradestoday =1 and close > pretradehigh And (Time < 092000) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not Onmarket
IF c10 THEN
BUY PPP PERPOINT AT MARKET
longtradestoday =longtradestoday+1
tradestoday = tradestoday+1
ENDIF
// Conditions to enter short positions again
c20 = shorttradestoday = 1 And close < pretradelow And (Time < 092000)And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not Onmarket
IF c20 THEN
SELLSHORT PPP PERPOINT AT MARKET
shorttradestoday = shorttradestoday+1
tradestoday = tradestoday+1
ENDIF
/// set new SL to break even
If LongOnMarket And High > (tradeprice(1) +15) Then
SET STOP pLOSS 0
Endif
If ShortOnMarket and low < (tradeprice(1) -15) Then
SET STOP pLOSS 0
Endif
// Stops and targets
SET STOP pLOSS 15
Set Target pProfit 30
Try this one:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 080100
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 093000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
//set pounds per point
ppp=1
// set variables to zero
once tradestoday =0
Once shorttradestoday =0
Once longtradestoday =0
if time = 010000 then
longtradestoday =0
shorttradestoday =0
tradestoday =0
endif
//reenter in case SL is hit
if StrategyProfit < StrategyProfit[1] then
IF LastTrade = 1 THEN
longtradestoday =1
ELSIF LastTrade = 2 THEN
shorttradestoday =1
ENDIF
endif
// the pretrade high amd low
if time = 080000 then
pretradehigh= highest[60](high)
pretradelow= lowest[60](low)
Endif
// Conditions to enter long positions on first move
c1 = close > pretradehigh And (Time < 083000) And tradestoday <1 and longtradestoday=0 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry
IF c1 THEN
BUY PPP PERPOINT AT MARKET
longtradestoday =longtradestoday+1
tradestoday = tradestoday+1
ENDIF
// Conditions to enter short positions on first move
c2 = close < pretradelow And (Time < 083000)And tradestoday <1 AND shorttradestoday=0 And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry
IF c2 THEN
SELLSHORT PPP PERPOINT AT MARKET
shorttradestoday = shorttradestoday+1
tradestoday = tradestoday+1
ENDIF
// Conditions to enter long positions again
c10 = longtradestoday =1 and close > pretradehigh And (Time < 092000) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not Onmarket
IF c10 THEN
BUY PPP PERPOINT AT MARKET
longtradestoday =longtradestoday+1
tradestoday = tradestoday+1
LastTrade = 1
ENDIF
// Conditions to enter short positions again
c20 = shorttradestoday = 1 And close < pretradelow And (Time < 092000)And timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry And Not Onmarket
IF c20 THEN
SELLSHORT PPP PERPOINT AT MARKET
shorttradestoday = shorttradestoday+1
tradestoday = tradestoday+1
LastTrade = 1
ENDIF
// Stops and targets
SET STOP pLOSS 15
Set Target pProfit 30
//Breakeven of 15 pips reached
IF Not OnMarket THEN
ExitPrice = 0
LastTrade = 0
ENDIF
IF (PositionPerf * PositionPrice) >= 15 * PipSize THEN
ExitPrice = PositionPrice
ENDIF
IF ExitPrice THEN
SELL AT ExitPrice STOP
EXITSHORT AT ExitPrice STOP
ENDIF
smpParticipant
Average
I 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?