@all
hi, yesterday I replaced the trailing with nicolas function and back test matches in demo system results. I fear that the problem is the trailing owns in PRT function. The problem of Nicolas function that is activated only if the market goes in the direction of the trade so we must enter a stop loss otherwise we risk substantial losses. I attach my own version of the strategy with the nicolas script.
// Definición de los parámetros del código
DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivada
DEFPARAM FlatAfter =173000
Margin = 60
Lottfree = 0
orderSize = max(1,1+ROUND((strategyprofit-lottfree)/Margin))
ordersize=min(50,ordersize)
HoraEntradaLimite = 090100
HoraInicio = 090000
HoraEntradaLimite1 = 090600
HoraInicio1 = 090500
HoraEntradaLimite2 = 091100
HoraInicio2 = 091000
HoraEntradaLimite3 = 091600
HoraInicio3 = 091500
//Monday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=1 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=1 then
n=1
endif
if Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=1 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=1 then
n=1
endif
//Tuesday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=2 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=2 then
n=1
endif
if Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=2 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=2 then
n=1
endif
//Wednesday
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=3 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=3 then
n=1
endif
////Thrusday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=4 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=4 then
n=1
endif
////Friday
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=5 then
n=1
endif
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=1 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=1 or Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=1 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=1 or Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=2 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=2 or Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=2 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=2 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=3 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=3 or Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=4 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=4 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=5 then
c1 = open < close-2
if not onmarket then
IF c1 THEN
buy n*ordersize contract AT close+2 stop
endif
c2= open > close-1
IF c2 THEN
sellshort n*ordersize contract AT close-1 stop
endif
endif
endif
//trailing stop
trailingstop = 5
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//SET STOP PLOSS 5
@nicolas @all
Yes, I have test also your version and backtest equal to the result in demo account. Is tt correct to add also a stop loss because if the market goes in the opposite direction of the trade we must have high lossess ? Thanks
// Definición de los parámetros del código
DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivada
DEFPARAM FlatAfter =173000
Margin = 60
Lottfree = 0
orderSize = max(1,1+ROUND((strategyprofit-lottfree)/Margin))
ordersize=min(50,ordersize)
HoraEntradaLimite = 090100
HoraInicio = 090000
HoraEntradaLimite1 = 090600
HoraInicio1 = 090500
HoraEntradaLimite2 = 091100
HoraInicio2 = 091000
HoraEntradaLimite3 = 091600
HoraInicio3 = 091500
//Monday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=1 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=1 then
n=1
endif
if Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=1 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=1 then
n=1
endif
//Tuesday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=2 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=2 then
n=1
endif
if Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=2 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=2 then
n=1
endif
//Wednesday
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=3 then
n=1
endif
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=3 then
n=1
endif
////Thrusday
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=4 then
n=1
endif
if Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=4 then
n=1
endif
////Friday
if Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=5 then
n=1
endif
if Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=1 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=1 or Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=1 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=1 or Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=2 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=2 or Time >= HoraInicio2 and time <= HoraEntradaLimite2 and dayofweek=2 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=2 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=3 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=3 or Time >= HoraInicio and time <= HoraEntradaLimite and dayofweek=4 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and dayofweek=4 or Time >= HoraInicio3 and time <= HoraEntradaLimite3 and dayofweek=5 then
c1 = open < close-2
if not onmarket then
IF c1 THEN
buy n*ordersize contract AT close+2 stop
endif
c2= open > close-1
IF c2 THEN
sellshort n*ordersize contract AT close-1 stop
endif
endif
endif
//trailing stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //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
SET STOP PLOSS 5
@emanuele, can you post your equity curve of the last 20000 bars please?
Hi,
attached back with these parameters of trailing Nicolas. I think that that the strategy not perform very well and I stop trading in real with this strategy. Thanks
//trailing stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //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
SET STOP PLOSS 5
The fact of using a trailing is for those days of great price movements. But what about the other days? The other days represent 95% of the days, imagine, with a trailing if the price moves in our favor 5 points and then turns around, we would stay at 0, if you move 10 points in our favor and then give The return, we would earn 5 points, we would need the price to rise, without going back, 15 points to ensure we earn 10 points.
Except that 5% of days that the price moves without going back, it is rare that the price moves more than 15 points without going back 5. With the trailing, for example, if the price goes up 14 points and turns around, we will win 5 Points, if you raise 11 and turn around, we would earn 5 points.
We would be letting out many points most days. Would not it be better not to be looking for those big price moves always and reap profits every day? I explain, if we place a take profit at a distance of 10 points and a normal stop of 5 or even a trailing of 5, someday we will stop making some money but in the long run I think it would be more convenient when it comes to scalping.
On the other hand, I understand that the trailing stop added to the code is only updated every 5 minutes, that’s a short time strategy I think it will never work. That is, when placing the order at 9, also places the trailing, the price can raise the first minute 50 points that the trailing is not going to move until 9.05 to recalculate it.
Imagine that the first 3 minutes goes up 20 points and the minute 4 falls 30 points, the operation would be losing when touching the stop even if we had won. This is how I understand the trailing code works.
CNParticipant
Senior
I agree, how can we make the 10pts sl insted of trailing?
CNParticipant
Senior
Antoher day with loss, 1 win 1 big loss.
How come the backtest shows win on v3 if you look yday and today?
Hey guys!
I totally agree with the trailingstop discussion you have here. I´m running the latest V3 system live and it definitely dosen´t match the backtest. Look at the picture. Real trades on the left and backtest at the right.
Since this is a scalping strategy, with no indicator needed, I still wonder why no one has launched it on a 1 second timeframe already? Ok.. you need first to calculate the 5 minutes Open/Close bar if I’m correct?
Trailing stop will be updated every 1 second, what else is needed? Tick trading, ok that’s no possible, but 1sec would be fair enough I believe!
CNParticipant
Senior
I agree with @Nicolas.
What does @raul and @emauele say?
Hello! Yesterday I tried it in 1 minute with the trailing of PRT, today I will try in 1 second with the trailing of Nicolas. I suppose it will be necessary that the opening of the 9 is less closing at 9.05, ie, 5×60 = 300 seconds. Close [300] <open-2 for purchase and close [300]> open-1 for sale.
I suppose it will be necessary that the opening of the 9 is less closing at 9.05, ie, 5×60 = 300 seconds. Close [300] open-1 for sale.
For this specific purpose, I think that we can’t do it like this, because with a 1 second timeframe, some candlesticks may not exist because of no new quotation. I think that a better option would be to have an indicator that calculate them like this instead:
if time=090000 then
val0900=close
endif
if time=090500 then
val0905=close
endif
return val0900, val0905
Hi Nicolas, I’m trying out what he told me right now in demo live in 1 second timeframe. What happens is that you place the order and the next second you remove it, how can I do to place the order in that first second and keep it until it touches the price?
Depends of much time you want the order to remain on market? In fact you only need your trading conditions to remain true and the pending order will be set at each new candlestick, until the condition is set to false.