DEFPARAM CumulateOrders = False
ONCE TradeON = 1
ONCE myProfit = 0
ONCE MaxProfits = 200
ONCE Negative = 0
ONCE MaxNegative = 2
ONCE TradeON = 0 = 2
IF IntradayBarIndex = 0 THEN
// Définissez à nouveau la variable TradeON pour redémarrer le trading chaque nouveau jour.
TradeON = 1
myProfit = 0
Negative = 0
ELSE
// Mettre à jour le bénéfice (ou la perte) temporaire
myprofit = myProfit + (StrategyProfit - StrategyProfit[1])
ENDIF
// Si le profit est >= N, arrêtez le trading jusqu'au lendemain
IF myProfit >= MaxProfits THEN
TradeON = 0
ELSIF (StrategyProfit - StrategyProfit[1]) < 0 THEN
// Si les pertes sont >= MaxNegative, arrêtez de trader jusqu'au lendemain
Negative = Negative + 1
IF Negative >= MaxNegative THEN
TradeON = 0
ENDIF
ENDIF
// Indicateurs et conditions d'entrée en Long ou en Short
Sma = average[20,0](close)
BullishCross = close CROSSES OVER Sma
BearishCross = close CROSSES UNDER Sma
IF Not OnMarket AND TradeON THEN
IF BullishCross THEN
BUY 1 Contract at Market
ELSIF BearishCross THEN
SELLSHORT 1 Contract at Market
ENDIF
SET STOP %LOSS 0.5
SET TARGET %PROFIT 0.5
ENDIF
// Debugging data
graph TradeON coloured("Green")
graph myProfit >= MaxProfits coloured("Red")