function CEL_OnInstrumentChanged(Source, EventID, Instrument, Quotes, props, varargin)

global m_CEL;
global m_AccountID;
global m_OrderID;

try
    % Placing limit buy order on current bid if current ask is higher than
    % the previous.
    if strcmp(m_OrderID, '')
        qtAsk = Instrument.get('Ask');
        qtBid = Instrument.get('Bid');
        qtPrevBid = Quotes.Item('qtBid');
        if (~isempty(qtAsk)) && (~isempty(qtBid)) && (~isempty(qtPrevBid))
           if qtAsk.get('IsValid') && qtBid.get('IsValid') && qtPrevBid.get('IsValid')
               if qtBid.get('Price') > qtPrevBid.get('Price')
                   GWConnectionStatus = m_CEL.get('Environment').get('GWConnectionStatus');
                   if strcmp(GWConnectionStatus, 'csConnectionUp')
                       stopPrice = double(qtAsk.get('Price') + 2 * Instrument.get('TickSize'));
                       limitPrice = double(0);
                       
                       order = m_CEL.CreateOrder(3, Instrument, m_CEL.Accounts.Item(m_AccountID), 1, 1, limitPrice, stopPrice, '');
                       
                       % eOrderExecutionInstruction.oeiQTS (enum index = 8)
                       order.get('Properties').Item('opExecutionInstructions').set('Value', int32(8));
                       % Setting DOM Threshold property
                       order.get('Properties').Item('opTriggerQuantity').set('Value', uint32(1000));
                       
                       order.Place;
                       
                       m_OrderID = order.get('GUID');
                       disp (['Placing an order with ''', m_OrderID, ''' GUID.']);
                   else
                       disp (['The order has not been placed, because GW connection status is ', GWConnectionStatus]);
                   end
               end       
           end
       end
    end
catch
    CEL_ShutDown;
    disp('An error occurred in CEL_OnInstrumentChanged.m file.');
    disp(lasterr);
end