//--------------------------------------------------------------------
// Pseudo Source Code of EURUSD_H4_Strategy 0.3671599
//
//   Generated by StrategyQuant X Build 125 for MetaTrader
//   at 11/27/2019 23:24
//--------------------------------------------------------------------

//--------------------------------------------------------------------
//  Strategy Parameters
//--------------------------------------------------------------------
int MagicNumber = 11111;
int RSIPeriod = 20;
int CCIPeriod = 50;
int QQERSIPeriod = 14;
double PriceEntryMult = 1.9;
int BarsValid = 6;
double ProfitTargetCoef = 1.8;
double TrailingStopCoef = 1;
int Period = 30;
int ATRPeriod = 50;
int BarsValid2 = 19;
int Period2 = 20;

Main chart = Current Symbol / Current TF;

//--------------------------------------------------------------------
// Trading rule: Trading signals (On Bar Open)
//--------------------------------------------------------------------                   
LongEntrySignal = (RSI(Main chart,RSIPeriod, PRICE_MEDIAN)[2] is rising for 3 bars);

ShortEntrySignal = ((CCI(Main chart,CCIPeriod, PRICE_CLOSE)[1] is rising for 3 bars  at 2 bar ago)
   and (QQE(Main chart,QQERSIPeriod, 5, 4.2)[4] < QQE(Main chart,QQERSIPeriod, 5, 4.2)[3]));

LongExitSignal = false;

ShortExitSignal = false;



//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if LongEntrySignal
{
    // Action #1
    Open Long order at (Lowest(Main chart, Period, PRICE_WEIGHTED)[5] + (PriceEntryMult * ATR(Main chart,ATRPeriod)[3])) Stop;
        Order valid for BarsValid bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        
        Profit target = ProfitTargetCoef * ATR(22);

        Trailing Stop = TrailingStopCoef * ATR(115);

}


//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if (ShortEntrySignal
   and Not LongEntrySignal)
{
    // Action #1
    Open Short order at Lowest(Main chart, Period2, PRICE_MEDIAN)[5] Stop;
        Order valid for BarsValid2 bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        

}


//--------------------------------------------------------------------
// 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;

}




