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');
        qtPrevAsk = Quotes.Item('qtAsk');
        if (~isempty(qtAsk)) && (~isempty(qtBid)) && (~isempty(qtPrevAsk))
           if qtAsk.get('IsValid') && qtBid.get('IsValid') && qtPrevAsk.get('IsValid')
               if qtAsk.get('Price') > qtPrevAsk.get('Price')
                   GWConnectionStatus = m_CEL.get('Environment').get('GWConnectionStatus');
                   if strcmp(GWConnectionStatus, 'csConnectionUp')
                       order = m_CEL.CreateOrder(2, Instrument,  m_CEL.Accounts.Item(m_AccountID), 1, 1, qtBid.get('Price'));    
                       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.');
end