Page 1 of 1

Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 08 2016
by wullenweber helmut
With this sample code MC sends a LMT order to TWS but it is cancelled immediately. Do you have any idea why this happens and what have to be done so that the order would not be cancelled?

Code: Select all

[ProcessMouseEvents = true];
[IntrabarOrderGeneration = true];

var: LEntryLevel(3170),SEntryLevel(3220);

// LMT Buy order with a mouse click with Shift
if MouseClickShiftPressed then Buy ("LevelK1") 1 contract next bar LEntryLevel limit;

// LMT Sell order with a mouse click with Ctrl
if MouseClickCtrlPressed then Sell short ("LevelS1") 1 contract next bar SEntryLevel limit;
Thank you in advance!

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 08 2016
by TJ
With this sample code MC sends a LMT order to TWS but it is cancelled immediately. Do you have any idea why this happens and what have to be done so that the order would not be cancelled?

Code: Select all

[ProcessMouseEvents = true];
[IntrabarOrderGeneration = true];

var: LEntryLevel(3170),SEntryLevel(3220);

// LMT Buy order with a mouse click with Shift
if MouseClickShiftPressed then Buy ("LevelK1") 1 contract next bar LEntryLevel limit;

// LMT Sell order with a mouse click with Ctrl
if MouseClickCtrlPressed then Sell short ("LevelS1") 1 contract next bar SEntryLevel limit;
Thank you in advance!

Did you lift up the shift key or the mouse click?

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 09 2016
by wullenweber helmut
@TJ
Both. While holding down Shift or Ctrl with a left mouse click an order is placed. After the order is acknowledged the orders is canceled as the audit trail shows.
I am wondering about the reason why the order is canceled.

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 09 2016
by ABC
Helmut,

in general MC will keep orders alive as long as the conditions that triggered the order are true. If your order triggering condition is a mouse click, then this condition is not true anymore once you release the mouse key.
One approach to solve this would be to set a flag to true with your mouse click and send the order while the flag is true. You just have to add a reset condition for the flag once your are filled or in case you want the order to get cancelled.

Regards,

ABC

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 09 2016
by wullenweber helmut
@ABC
Thank you! I tried this, but it did not solve the problem. How do I set the flag correctly?

Code: Select all

[ProcessMouseEvents = true];
[IntrabarOrderGeneration = true];

var: LEntryLevel(3180),SEntryLevel(3200);
var: Buyflag(false),Sellflag(false);

if marketposition = 1 then buyflag = false;
if marketposition = -1 then Sellflag = false;


// LMT Buy order with a mouse click with Shift
if MouseClickShiftPressed then buyflag = true;
if buyflag = true then Buy ("LevelK1") 1 contract next bar LEntryLevel limit;

// LMT Sell order with a mouse click with Ctrl
if MouseClickCtrlPressed then sellflag = true;
if sellflag = true then Sell short ("LevelS1") 1 contract next bar SEntryLevel limit;

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 09 2016
by ABC
Helmut,

what is the result of your code?

You have IntrabarOrderGeneration enabled, but your variables are not intrabarpersist. This might be an explanation, but not knowing what actually happens with your code this is just a guess.

Regards,

ABC

Re: Submitting orders with mouse clicks in PowerLanguage  [SOLVED]

Posted: Dec 09 2016
by wullenweber helmut
@ABC

You ar right, intrabarpersist was missing. Without intrabarpersist the orders were cancelled. Thank you very much, ABC!

This code works fine:

Code: Select all

[ProcessMouseEvents = true];
[IntrabarOrderGeneration = true];

var: LEntryLevel(3190),SEntryLevel(3210);
var: IntraBarPersist Buyflag(false), IntraBarPersist Sellflag(false);

if marketposition = 1 then buyflag = false;
if marketposition = -1 then Sellflag = false;


// LMT Buy order with a mouse click with Shift
if MouseClickShiftPressed then buyflag = true;
if buyflag = true then Buy ("LevelK1") 1 contract next bar LEntryLevel limit;

// LMT Sell order with a mouse click with Ctrl
if MouseClickCtrlPressed then sellflag = true;
if sellflag = true then Sell short ("LevelS1") 1 contract next bar SEntryLevel limit;

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 10 2016
by janus
Yes limit (and stop) orders have to be sent repeatedly until filled. Market orders (entry or exit) however only need to be sent once.

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 12 2016
by wullenweber helmut
@Janus
The order is sended only once. But without setting the flag-variable with IntraBarPersist the condition = true via mouseclick will not persist.

Re: Submitting orders with mouse clicks in PowerLanguage

Posted: Dec 12 2016
by janus
@Janus
The order is sended only once. But without setting the flag-variable with IntraBarPersist the condition = true via mouseclick will not persist.
I was just warming you that using the same code for market orders may risk duplicate orders being sent and filled in real-time depending on the properties settings of the Signal study.