Overall Statistics
Total Trades
447
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
0.000%
Drawdown
0.000%
Expectancy
0.000
Net Profit
0.000%
Sharpe Ratio
-0.069
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
0.81
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-49.182
Tracking Error
0
Treynor Ratio
0.007
Total Fees
$0.00
namespace QuantConnect
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        private Symbol _symbol;
        private RelativeStrengthIndex _rsi;
		private const decimal limitDiff = 0.0046m;
		private const decimal stoptDiff = 0.0050m;

        public override void Initialize()
        {
        	SetStartDate(2017,1,1);
            SetEndDate(2018,12,20);
            SetCash(100000);
            SetBrokerageModel(BrokerageName.OandaBrokerage);
            
            _symbol = AddForex("EURUSD", Resolution.Hour, Market.Oanda).Symbol;
            
            _rsi = RSI(_symbol, 14, MovingAverageType.Wilders, Resolution.Hour);
            
            var properties = Securities[_symbol].SymbolProperties;
            var lotSize = properties.LotSize;
            var order = properties.ContractMultiplier;
            
            var orderQuantity = 20180.12m;
            Debug($"the order size is {Math.Round(orderQuantity/lotSize)*lotSize} for lot size of {lotSize}");
        }

        
        public override void OnData(Slice data)
        {
        	if (Portfolio.Invested || !_rsi.IsReady)
            {
            	return;
            }
            	
            var price = data[_symbol].Close;
            //Log($"{Time} :: RSI: {_rsi}. Price: {price}");
            	
            if (_rsi <= 30 && _rsi >= 25)
            {
            	var marketOrder = MarketOrder(_symbol, 1, false);
            	Log($"{marketOrder}");
            	LimitOrder(_symbol, -1, price + limitDiff);
            	StopMarketOrder(_symbol, -1, price - stoptDiff);
            }
            	
            if (_rsi >= 70 && _rsi <= 75)
            {
            	var marketOrder = MarketOrder(_symbol, -1, false);
            	Log($"{marketOrder}");
            	LimitOrder(_symbol, 1, price - limitDiff);
            	StopMarketOrder(_symbol, 1, price + stoptDiff);
            }
        }
        
        public override void OnOrderEvent(OrderEvent orderEvent)
        {
        	if (orderEvent.Status != OrderStatus.Filled)
        	{
        		return;
        	}
        	
        	var order = Transactions.GetOrderById(orderEvent.OrderId);
        	if (order.Type == OrderType.Market)
        	{
        		Log($"{order}");
        		return;
        	}
        	
        	Transactions.CancelOpenOrders(_symbol);
        }
    }
}