Can you post the date & time of at least one trade that shows the issue? (from your first pic I can’t tell exactly when).
Hi Roberto,
I actually fixed this code last night see addition at lines 67 to 69 in the below code. However, sadly when accounting for a 2pt spread on the NASDAQ what is a highly profitable strategy becomes a losing strategy. Back to the drawing board then.
// Intraday trend following strategy. Entries and Exits defined by EMA crossovers. Position size determiend by distance to stop loss and percent of equity at risk. Initial stop loss set at recent swing low or high. Profits are protected by a stoploss that moves to breakeven after a defined number of points
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FlatBefore = 230000
DEFPARAM FlatAfter = 211500
EMAfast = 11
EMAslow = 38
//Risk Management
Capital = 36000
Risk = 0.01
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSizeL = abs(round((maxrisk/StopLossL)/PointValue)*pipsize)
PositionSizeS = abs(round((maxrisk/StopLossS)/PointValue)*pipsize)
// Conditions to enter long positions
indicator1 = ExponentialAverage[EMAfast](close)
indicator2 = ExponentialAverage[EMAslow](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 THEN
BUY PositionSizeL PERPOINT AT MARKET
StopLossL = abs(close - LOWEST[10](Low)) + 1.5 * pointsize
set stop loss StopLossL
ENDIF
// Conditions to exit long positions
indicator3 = ExponentialAverage[EMAfast](close)
indicator4 = ExponentialAverage[EMAslow](close)
c2 = (indicator3 CROSSES UNDER indicator4)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = ExponentialAverage[EMAfast](close)
indicator6 = ExponentialAverage[EMAslow](close)
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELLSHORT PositionSizeS PERPOINT AT MARKET
StopLossS = abs(close - HIGHEST[10](High)) + 1.5 * pointsize
set stop loss StopLossS
ENDIF
// Conditions to exit short positions
indicator7 = ExponentialAverage[EMAfast](close)
indicator8 = ExponentialAverage[EMAslow](close)
c4 = (indicator7 CROSSES OVER indicator8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
//trailing stop function
TrailingStart = AverageTrueRange[10] * pipsize //trailing will start @trailinstart points profit
TrailingStep = -2 * pipsize
if not onmarket then
newsl=0
endif
if ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
newsl=0
endif
if longonmarket then
if close-tradeprice(1)>= TrailingStart then
newsl=TRADEPRICE(1) + TrailingStep
endif
endif
if shortonmarket then
if tradeprice(1)-close>= TrailingStart then
newsl= TRADEPRICE(1) - TrailingStep
endif
endif
if longonmarket and newsl>0 then
sell at newsl stop
endif
if shortonmarket and newsl>0 then
exitshort at newsl stop
endif
Hi I’m curious about this.. Where do you place the Stoploss..
StopLossL = abs(close – LOWEST[10](Low)) + 1.5 * pointsize does this meam swing low??
Yes, it’s the lowest low within the last 10 bars, so it could be a swing point (+ 1.5 pips), within 40+ bars would grant a greater accuracy.
thanks very much for the clarification!!