Submitting orders with mouse clicks in PowerLanguage  [SOLVED]

Questions about MultiCharts and user contributed studies.
wullenweber helmut
Posts: 60
Joined: 21 Dec 2007
Has thanked: 3 times
Been thanked: 9 times

Submitting orders with mouse clicks in PowerLanguage

Postby wullenweber helmut » 08 Dec 2016

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!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby TJ » 08 Dec 2016

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?

wullenweber helmut
Posts: 60
Joined: 21 Dec 2007
Has thanked: 3 times
Been thanked: 9 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby wullenweber helmut » 09 Dec 2016

@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.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Submitting orders with mouse clicks in PowerLanguage

Postby ABC » 09 Dec 2016

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

wullenweber helmut
Posts: 60
Joined: 21 Dec 2007
Has thanked: 3 times
Been thanked: 9 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby wullenweber helmut » 09 Dec 2016

@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;

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Submitting orders with mouse clicks in PowerLanguage

Postby ABC » 09 Dec 2016

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

wullenweber helmut
Posts: 60
Joined: 21 Dec 2007
Has thanked: 3 times
Been thanked: 9 times

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

Postby wullenweber helmut » 09 Dec 2016

@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;

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby janus » 10 Dec 2016

Yes limit (and stop) orders have to be sent repeatedly until filled. Market orders (entry or exit) however only need to be sent once.

wullenweber helmut
Posts: 60
Joined: 21 Dec 2007
Has thanked: 3 times
Been thanked: 9 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby wullenweber helmut » 12 Dec 2016

@Janus
The order is sended only once. But without setting the flag-variable with IntraBarPersist the condition = true via mouseclick will not persist.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Submitting orders with mouse clicks in PowerLanguage

Postby janus » 12 Dec 2016

@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.


Return to “MultiCharts”