Hallo,
Nicolas postete dieses System vor ein paar Jahren und ich find das ziemlich gut. Nun hab ich versucht einen Trailingstop einzubauen, aber irgendwie funktioniert es nicht.
Kann mir jemand den Code so umschreiben das es läuft?
Und vielleicht noch eine Grid/Martingal Funktion einbauen?
Vielen Dank.
//10.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam cumulateorders = false
// --- parameters
StartHour = 080000
EndHour = 180000
Size = 1 //position size
StopLoss = 1.05 //0.95 stoploss in points
TakeProfit = 0.15 //0.35 takeprofit in points
LookbackPeriod = 10 //12 lookback period to find highest high and lowest low (price range)
PointsDistance = 1 //1 distance in points to add/substract from highest high or lowest low to put the pending stop orders
// ------------
tcondition = time>StartHour and EndHour and intradaybarindex>=LookbackPeriod*2
if not onmarket and tcondition and barindex-tradeindex(1)>=LookbackPeriod then
BUY Size CONTRACTS AT highest[LookbackPeriod](high)+PointsDistance*pointsize STOP
SELLSHORT Size CONTRACTS AT lowest[LookbackPeriod](low)-PointsDistance*pointsize STOP
endif
SET STOP %LOSS StopLoss
SET TARGET %PROFIT TakeProfit
//************************************************************************
//trailing stop function
trailingstart = 10 //6 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-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+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 tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-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