Difference between revisions of "Why an Order Was or Was Not Executed"

From MultiCharts
Jump to navigation Jump to search
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
+
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==
 
==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 [[Order and Position Tracker|Orders Tab]]).
+
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 [[Order and Position Tracker|Orders Tab]]).
 
<br>
 
<br>
There are 2 possible reasons why an order is not placed at broker:
+
There are 2 possible reasons why an order is not placed at the broker:
# 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 [[Order and Position Tracker|Logs Tab]])  
+
# 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 [[Order and Position Tracker|Logs Tab]])  
# 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.
+
# 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.
  
 
<br>
 
<br>
  
 
==Monitoring from Script==
 
==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.
+
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, 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:
+
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:
 
<br>
 
<br>
 
<br>
 
<br>
Line 24: Line 24:
 
'''If MinMove < 10 then''' <br>
 
'''If MinMove < 10 then''' <br>
 
'''Scale = 1;'''<br>
 
'''Scale = 1;'''<br>
'''If MinMove > 99 and MinMove > 1000 then''' <br>
+
'''If MinMove > 99 and MinMove < 1000 then''' <br>
 
'''Scale = 2;'''<br>
 
'''Scale = 2;'''<br>
'''If MinMove > 999 and MinMove > 10000 then'''<br>
+
'''If MinMove > 999 and MinMove < 10000 then'''<br>
 
'''Scale = 3;'''<br>
 
'''Scale = 3;'''<br>
'''If MinMove > 9999 and MinMove > 100000 then'''<br>
+
'''If MinMove > 9999 and MinMove < 100000 then'''<br>
 
'''Scale = 4;'''<br>
 
'''Scale = 4;'''<br>
'''If MinMove > 99999 and MinMove > 1000000 then'''<br>
+
'''If MinMove > 99999 and MinMove < 1000000 then'''<br>
 
'''Scale = 5;'''
 
'''Scale = 5;'''
 
<br>
 
<br>
Line 53: Line 53:
 
'''"The date is ", DateToString(DateToJulian(Date)), ",", NewLine,<br>
 
'''"The date is ", DateToString(DateToJulian(Date)), ",", NewLine,<br>
 
'''"time is ", TimeToString(ELTimeToDateTime(Time)), ",", NewLine,<br>
 
'''"time is ", TimeToString(ELTimeToDateTime(Time)), ",", NewLine,<br>
'''"bar # is ", maxbarsback+currentbar, ",", NewLine,<br>
+
'''"bar # is ", symbol_currentbar, ",", NewLine,<br>
 
'''"current bar open is ", open, ",", NewLine,<br>
 
'''"current bar open is ", open, ",", NewLine,<br>
 
'''"current bar high is ", high, ",", NewLine,<br>
 
'''"current bar high is ", high, ",", NewLine,<br>
Line 64: Line 64:
 
<br>
 
<br>
 
<br>
 
<br>
If the script is applied to your chart and it is opened in PowerLanguage Editor, you will be able to see the following lines in the Output tab:
+
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:
 
<br>
 
<br>
 
<br>
 
<br>

Revision as of 12:42, 15 June 2017

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