Why an Order Was or Was Not Executed

It's common for a customer to expect an order to be generated and executed or vice versa, not be generated and not to be executed at a particular place on a chart. A combination of the 2 following methods should help you understand why an order was filled or not during auto trading.

Order and Position Tracker

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

  1. The order was rejected either by MultiCharts, or by the broker (in most cases, you can find the reason for rejection in the Logs tab of the Order and Position Tracker (see Logs Tab)
  2. The order was cancelled from the script. According to the 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 the Order and Position Tracker has nothing in common with the historical calculation process, 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, when generating your buy/sell orders, will help you to understand at what particular bar, when, and at what price your order is triggered in the code:

Var: Scale(0);

Condition1 = close > close[1];

If MinMove < 10 then
Scale = 1;
If MinMove > 99 and MinMove < 1000 then
Scale = 2;
If MinMove > 999 and MinMove < 10000 then
Scale = 3;
If MinMove > 9999 and MinMove < 100000 then
Scale = 4;
If MinMove > 99999 and MinMove < 1000000 then
Scale = 5;

If Condition1 = true then begin
print( "======================", NewLine,
"The date is ", DateToString(DateToJulian(Date)), ",", NewLine,
"time is ", TimeToString(ELTimeToDateTime(Time)), ",", NewLine,
"bar # is ", maxbarsback+currentbar, ",", NewLine,
"current bar open is ", open, ",", NewLine,
"current bar high is ", high, ",", NewLine,
"current bar low is ", low, ",", NewLine,
"current bar close is ", close, ",", NewLine,
"market position on chart is", MarketPosition, ",", NewLine,
"market position at broker is", MarketPosition_at_Broker, ",", NewLine,
"Condition1 is true, so at close of this bar the limit order to buy at ", NumToStr(close,scale), " is generated by the script", NewLine,
"to be executed at bar # ", maxbarsback+currentbar+1);
Buy next bar at close limit;

end else begin
print( "======================", NewLine,
"The date is ", DateToString(DateToJulian(Date)), ",", NewLine,
"time is ", TimeToString(ELTimeToDateTime(Time)), ",", NewLine,
"bar # is ", symbol_currentbar, ",", NewLine,
"current bar open is ", open, ",", NewLine,
"current bar high is ", high, ",", NewLine,
"current bar low is ", low, ",", NewLine,
"current bar close is ", close, ",", NewLine,
"market position on chart is", MarketPosition, ",", NewLine,
"market position at broker is", MarketPosition_at_Broker, ",", NewLine,
"Condition1 is false, so no order is generated.");
end;

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

======================
The date is 10/8/2013,
time is 4:00:00 PM,
bar # is 995.00,
current bar open is 865.32,
current bar high is 865.98,
current bar low is 851.63,
current bar close is 853.67,
market position on chart is 1.00,
market position at broker is 0.00,
Condition1 is false, so no order is generated.
======================
The date is 10/9/2013,
time is 4:00:00 PM,
bar # is 996.00,
current bar open is 856.28,
current bar high is 862.65,
current bar low is 842.98,
current bar close is 855.86,
market position on chart is 1.00,
market position at broker is 0.00,
Condition1 is true, so at close of this bar the limit order to buy at 855.9 is generated by the script
to be executed at bar # 997.00