//--------------------------------------------------------------------
// Pseudo Source Code of XU_H1_910122122_L_LW_CF_SQX
//
//   Generated by StrategyQuant X Build 142 for MetaTrader
//   at 09/23/2025 17:50
//
//   Backtested on XAUUSD_M1_UTC2 / H1, 2006.01.01 - 2023.07.24
//   Backtest engine: MetaTrader4
//--------------------------------------------------------------------

//--------------------------------------------------------------------
//  Strategy Parameters
//--------------------------------------------------------------------
int MagicNumber = 910122122;
int LinRegBarClosesPrd1 = 14;
double PriceEntryMult1 = 0.5;
double ProfitTarget1 = 1715;
double StopLoss1 = 1520;
double TrailingStop1 = 900;
int LWMAPeriod1 = 50;
int BBRangePeriod1 = 138;

Main chart = Current Symbol / Current TF;

//--------------------------------------------------------------------
// Trading options logic
//--------------------------------------------------------------------

Don't Trade On Weekends = false (Friday 1900 - Sunday 2300);
Exit at End Of Day = false (1500);
Exit On Friday = true (2100);
LimitSignalsTimeRange = false (1400 - 2100, Exit at End: true, Orders to close: All);
LimitMaxDistanceFromMarketPrice = false;   //Limit max distance
MaxDistanceFromMarketPct = 0;   //Max distance %
MaxTradesPerDay = 0;
Min SL: 0, Max SL: 0, Min PT: 0, Max PT: 0; // in ticks/pips, 0 means unlimited


//--------------------------------------------------------------------
// Trading rule: Trading signals (On Bar Open)
//--------------------------------------------------------------------           
LongEntrySignal = Close[1] above LinReg(Main chart,LinRegBarClosesPrd1)[1];

ShortEntrySignal = Close[1] below LinReg(Main chart,LinRegBarClosesPrd1)[1];

LongExitSignal = false;

ShortExitSignal = false;


//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------           
if LongEntrySignal
{
    // Action #1
    Open Long order at (LWMA(Main chart,LWMAPeriod1, PRICE_CLOSE)[1] + (PriceEntryMult1 * BB Range(Main chart,BBRangePeriod1, 2.1, PRICE_CLOSE)[2])) Limit;
        Order valid for 15 bars;
        Duplicate trades: disabled;
        Replacing pending orders: allowed; 
        Stop Loss = StopLoss1 pips;
        Profit target = ProfitTarget1 pips;

        Trailing Stop = TrailingStop1 pips;
}

//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------           
if (ShortEntrySignal
   and Not LongEntrySignal)
{
    // Action #1
    Open Short order at (LWMA(Main chart,LWMAPeriod1, PRICE_CLOSE)[1] - (PriceEntryMult1 * BB Range(Main chart,BBRangePeriod1, 2.1, PRICE_CLOSE)[2])) Limit;
        Order valid for 15 bars;
        Duplicate trades: disabled;
        Replacing pending orders: allowed; 
        Stop Loss = StopLoss1 pips;
        Profit target = ProfitTarget1 pips;

        Trailing Stop = TrailingStop1 pips;
}

//--------------------------------------------------------------------
// Trading rule: Long exit (On Bar Open)
//--------------------------------------------------------------------           
if ((LongExitSignal
   and Not LongEntrySignal)
   and (MarketPosition("Any", MagicNumber, "") is Long))
{
    // Action #1
    Close Full position for Symbol = Any and Magic Number = MagicNumber;

}

//--------------------------------------------------------------------
// Trading rule: Short exit (On Bar Open)
//--------------------------------------------------------------------           
if ((ShortExitSignal
   and Not ShortEntrySignal)
   and (MarketPosition("Any", MagicNumber, "") is Short))
{
    // Action #1
    Close Full position for Symbol = Any and Magic Number = MagicNumber;

}



Broker: 0