Overall Statistics
Total Trades
32
Average Win
0.11%
Average Loss
-0.11%
Compounding Annual Return
-6.831%
Drawdown
0.600%
Expectancy
-0.222
Net Profit
-0.381%
Sharpe Ratio
-2.974
Probabilistic Sharpe Ratio
13.133%
Loss Rate
62%
Win Rate
38%
Profit-Loss Ratio
1.08
Alpha
-0.054
Beta
-0.01
Annual Standard Deviation
0.017
Annual Variance
0
Information Ratio
1.537
Tracking Error
0.295
Treynor Ratio
5.124
Total Fees
$0.00
Estimated Strategy Capacity
$460000.00
Lowest Capacity Asset
AUDNZD 8G
# region imports
from AlgorithmImports import *
# endregion

# ------------------------------------------------------------
ccypair = "AUDNZD"; PERIOD = 21
# ------------------------------------------------------------

class MeasuredRedOrangeChicken(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 5, 1)  # Set Start Date
        self.SetEndDate(2022, 5, 20) # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        self.pair = self.AddForex(ccypair, Resolution.Hour).Symbol
        self.bband = self.BB(ccypair, PERIOD, 2, MovingAverageType.Exponential, Resolution.Hour)
        self.bband_stop = self.BB(ccypair, PERIOD, 4, MovingAverageType.Exponential, Resolution.Hour)
        self.stopMarketTicket = None
        self.stopMarketTicketShort = None

        # Set WarmUp Period
        self.SetWarmup(PERIOD + 1, Resolution.Hour)

    def OnData(self, data: Slice):
        if self.IsWarmingUp:
            return
        
        price = self.Securities[ccypair].Price
        short_stop = self.bband_stop.UpperBand.Current.Value
        long_stop = self.bband_stop.LowerBand.Current.Value

        if not self.Portfolio.Invested:
            # short trade if price his upper band
            if price > self.bband.UpperBand.Current.Value:
                self.SetHoldings(self.pair, -1)
                self.stopMarketTicket = self.StopMarketOrder("AUDNZD", -self.Portfolio["AUDNZD"].Quantity, short_stop)

            # long if price his lower band
            elif price < self.bband.LowerBand.Current.Value:
                self.SetHoldings(self.pair, 1)
                self.stopMarketTicket = self.StopMarketOrder("AUDNZD", -self.Portfolio["AUDNZD"].Quantity, long_stop)

        elif self.Portfolio.Invested:
            if price <= self.bband.MiddleBand.Current.Value:
                self.Liquidate(ccypair, "Sell Take Profit")
            elif price >= self.bband.MiddleBand.Current.Value:
                self.Liquidate(ccypair, "Buy Take Profit")