Why an Order Was or Was Not Executed

From MultiCharts
Jump to navigation Jump to search

It is a common situation when a customer expects an order to be generated and executed or vice versa not be generated and not to be executed at a particular place on chart. Combination of 2 following methods of studying nature of fillment or non-fillment of orders sent from MultiCharts during auto trading should help you in understanding the situation.

Order and Position Tracker

If an order was generated and sent from script to broker plugin, it is displayed in Order and Position Tracker on Orders tab. If an order is filled you can see it execution price and details (see Orders Tab).
There are 2 possible reasons why an order is not placed at broker:

  1. The order was rejected either by MultiCharts, or by broker (in most cases you can find the reason of rejection on Logs tab of Order and Position Tracker (see Logs Tab)
  2. The order was cancelled from script. According to logic of EasyLanguage/PowerLanguage, an order will be maintained as long as the conditions for its generation are met on each calculation. Once a condition is not met, it will be cancelled.


Monitoring from Script

This method is extremely useful not only for backtesting, since Order and Position Tracker has nothing in common with the process of historical calculation, but also for live auto trading because you can see the strategy logic printed out in real-time. Adding the following line under the same conditions right before the line, generating your buy/sell orders will help you to understand at what particular bar, when and at what price is your order triggered in code:

print("The date is ", DateToString(DateToJulian(Date)), ", time is ", TimeToString(ELTimeToDateTime(Time)), ", bar # is ", maxbarsback+currentbar-1, ", market position on chart is", MarketPosition, ", market position at broker is", MarketPosition_at_Broker, ", here a LIMIT/STOP order to BUY/SELL is generated by the script at ", "100 price (example)");

Example: ...
If condition1 = true and condition2 = false then begin
print("The date is ", DateToString(DateToJulian(Date)), ", time is ", TimeToString(ELTimeToDateTime(Time)), ", bar # is ", maxbarsback+currentbar-1, ", market position on chart is", i_marketposition, ", market position at broker is", i_MarketPosition_at_Broker, ", here a LIMIT/STOP order to BUY/SELL is generated by the script at ", "100 price");
sellshort next bar at 100 limit;
end;


If the script is applied to your chart and it is opened in PowerLanguage Editor, you will be able to see the following line in the Output tab:

The date is 03.07.2012, time is 18:45:00, bar # is 4362.00, market position on chart is 1.00, market position at broker is 1.00, here a LIMIT order to SELL is generated by the script at 100 price