Hello,
Testing this very simple system to understand how the breakeven works compared to MFE. Dow TF 5 min.
DEFPARAM CUMULATEORDERS = FALSE
TIMEFRAME(1 hour)
MAFastH1 = HullAverage[5](close)
MASlowH1 = HullAverage[13](close)
TIMEFRAME(DEFAULT)
MAFastM5 = HullAverage[8](close)
MASlowM5 = HullAverage[21](close)
StoK = Stochastic[8,3](close)
StoD = Stochasticd[8,3,5](close)
////////////
long=0
short=0
if stok>50 and stok<stok[1] and stok<stod and MAFastM5<MASlowM5 and MAFastH1<MASlowH1 then
short=-1
endif
if stok<50 and stok>stok[1] and stok>stod and MAFastM5>MASlowM5 and MAFastH1>MASlowH1 then
long=+1
endif
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket AND long=+1 THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Conditions pour fermer une position acheteuse
If LongOnMarket AND (short=-1 or (stok[1]<stok and stok[1]<stok[2])) THEN
SELL AT MARKET
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
// Conditions pour ouvrir une position en vente à découvert
IF NOT ShortOnMarket AND short=-1 THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
// Conditions pour fermer une position en vente à découvert
IF ShortOnMarket AND (long=+1 or (stok[1]>stok and stok[1]>stok[2])) THEN
EXITSHORT AT MARKET
BUY 1 CONTRACTS AT MARKET
ENDIF
// Stops et objectifs : entrez vos stops et vos objectifs ici
SET STOP %LOSS 1
///2 BREAKEAVEN///////////
once breakeaven = 1//1 on - 0 off
startBreakeven = 35 //how much pips/points in gain to activate the breakeven function?
PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
///2///////////////////////////////////////////////
//reset the breakevenLevel when no trade are on market
if breakeaven>0 then
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice+PointsToKeep*pipsize
ENDIF
//plce the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
IF SHORTONMARKET AND tradeprice-close>startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
endif
GRAPHONPRICE breakevenLevel coloured(0,0,255,255)
The breakeven is set to 35 (result of backtest). But on Jan. 3rd at 00:00 the system takes a short which shows an MFE of +101.20, so much higher than the breakeven, but the trade is closed at a loss of -1.5.
On the graph, when I looked at the entry price and the low of the candle, there were approx. 38 points. May be not enough to trigger the Breakeven given the Spread of 4.8. After this entry candle and until the exit, it was was a loss all the way (not possible to have a positive MFE). But how the MFE is +101 then?
Someone can please help me understand ?
Thanks
It might be because the breakeven uses Close ???
Try replacing it with High (line 65) and Low (line 76)
This usually gives a better result and would certainly explain why it didn’t trigger at 38 points.
Could be that the MFE is just wrong. I’ve often seen some incomprehensible numbers in that column.
Hello Khaled – I suppose that you can set the TimeFrame to 1 second for graphing the gain ? Thus only for that – then back to 1 hour. Then you can see the MFE yourself for this situation ?