DEFPARAM cumulateOrders = False
Defparam flatafter = 160000
once StartE = 80000
once StartL = 113000
once Period = 15
once Period2 = 15
Series = (open+high+low+Close)/4
Seriesv2 = (open+high+low+Close)/4
OTD = Barindex - TradeIndex(1) > IntradayBarIndex
TSL = round(100/10000*close)
////////////////////////////////////
REM Money Management
Capital = 10000
Risk = 0.01
StopLoss = 10// Je voudrais ici que ma variable TSL soit utilisé.
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
//PUT AFR AND AFRv2 HERE//
Period = MAX(Period, 2)
alpha = 2 / (1 + Period)
IF BarIndex = 0 THEN
p1 = Series
p2 = Series
ELSE
p1 = p1[1] + alpha * (Series - p1[1])
p2 = p2[1] + alpha * (p1 - p2[1])
ENDIF
AFR = (((2 - alpha) * p1 - p2) / (1 - alpha))
Period2 = MAX(Period2, 1)
MA1 = ExponentialAverage[Period2](Seriesv2)
MA2 = ExponentialAverage[Period2](MA1)
MA3 = ExponentialAverage[Period2](MA2)
MA4 = ExponentialAverage[Period2](MA3)
MA5 = ExponentialAverage[Period2](MA4)
MA6 = ExponentialAverage[Period2](MA5)
MA7 = ExponentialAverage[Period2](MA6)
MA8 = ExponentialAverage[Period2](MA7)
AFRV2 = (8 * MA1) - (28 * MA2) + (56 * MA3) - (70 * MA4) + (56 * MA5) - (28 * MA6) + (8 * MA7) - MA8
/////////////////////////////////////
wAFR = exponentialaverage[30](AFR)
wAFRv2 = exponentialaverage[30](AFRv2)
if time >= StartE And time <= StartL and OTD then
IF wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] then
BUY PositionSize CONTRACTS AT MARKET
SET STOP PLOSS TSL
//SET STOP PTRAILING TSL
//SET TARGET PPROFIT TSL
else
if wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] then
SELLSHORT PositionSize CONTRACTS AT MARKET
SET STOP PLOSS TSL
//SET STOP PTRAILING TSL
//SET TARGET PPROFIT TSL
endif
endif
endif