Hello, I want to introduce you to one of my works. I hope for numerous comments and for one or the other idea whether there is still room for improvement.
The system traditionally acts as a setback in the upward trend. Doubled over a grid with greater loss, but is capped at a maximum of 3 positions. So quite risk-free.
I also added a multi-timeframe, but only to get even better results with the trailing stop.
I have been trading a similar system in the H1 for a long time, with great results.
// Festlegen der Code-Parameter
DEFPARAM CumulateOrders = true // Kumulieren von Positionen deaktiviert
DEFPARAM Preloadbars = 300
//timeframe(15 minute, updateonclose)
gridStep = 20 //20
MAXSHARES = abs(COUNTOFPOSITION) <= 1 //1
// Verhindert das Platzieren von neuen Ordern zum Markteintritt oder Vergrößern von Positionen vor einer bestimmten Uhrzeit
noEntryBeforeTime = 010000
timeEnterBefore = time >= noEntryBeforeTime
// Verhindert das Platzieren von neuen Ordern zum Markteintritt oder Vergrößern von Positionen nach einer bestimmten Uhrzeit
noEntryAfterTime = 233000
timeEnterAfter = time < noEntryAfterTime
// Verhindert das Trading an bestimmten Wochentagen
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Long
indicator1 = Average[25](close)//25
indicator2 = Average[180](close)//180
c1 = (indicator1 CROSSES UNDER indicator2)
indicator3 = ADX[14]
c2 = (indicator3 > 10)
indicator4 = ADX[14]
c3 = (indicator4 < 30) //30
IF not longonmarket and (c1 AND c2 AND c3) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//grid
if longonmarket and tradeprice-close>=gridStep*pointsize and maxshares then
buy 2 contract at market
endif
// Longexit
indicator5 = Average[25](close)//25
indicator6 = Average[180](close)//180
c4 = (indicator5 CROSSES OVER indicator6)
IF c4 THEN
SELL AT MARKET
ENDIF
// Stops und Targets
SET STOP pLOSS 75 //75
//timeframe(default) //5 minute
//************************************************************************
//trailing stop function
trailingstart = 8 //8 trailing will start @trailinstart points profit
trailingstep = 1 //1 trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-positionprice>=trailingstart*pipsize THEN
newSL = positionprice+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND positionprice-close>=trailingstart*pipsize THEN
newSL = positionprice-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
You must be logged in to post a comment.
hey my friends, thank you for this great code. my problem is he make no trade open. backtest is in 20.000 witj 5min very perfekt. i have chance from 15 to 5min but not open. my next ask : what is postion 8 ? when put to 0.5 he make only 1 contarkt at back test, this for me perfekt. money is 900 in test account. can you help me please ? thank alot
Ich habe hier mit Spread 2 gerechnet, also etwa dem Mittelwert zwischen Tag und Nacht. Das Grid funktioniert. Man kauft nach wenn die Position zum Kerzen close 20 Punkte im Minus liegt. Aber nur einmal, zur Risikobegrenzung. Im H1 mit veränderten Werten sieht man, das das System auch in Bärischen Phasen funktioniert. Ich habe auch noch eine Version im M1, die funktioniert super. Sollte man aber mit Bedacht einsetzen.
You got some potential here. A couple of things I think about: 1, The opening hours in this script (01.00 - 23.30) is very generous and the spread in reality is very high (5 points) between 22.00 and 08.00. That should be considered. 2, Does the grid work? I get no effect when changing it.
I wrote the code for M15 back then and also variants in H1 and M1. Everything works so far. Note the opening times 01:00 - 23:30. Position 8 is the maximum buy / sell order. You can also try without the martingale. Works in the long term as well. Maybe adjust SL.