Run code when order is closed  [SOLVED]

Questions about MultiCharts and user contributed studies.
Eduardo
Posts: 21
Joined: 22 May 2020

Run code when order is closed

Postby Eduardo » 07 Dec 2020

Hello,
I'm trying to run some code as soon as an order is closed. I'm using TotalTrades and it works well unless the order is entered and closed in the same bar, like in the picture attached.
Would there be another way of doing it?
Thank you

Code: Select all

//Run as soon as an order is closed Variables: oldTotalTrades(0); if totaltrades > oldTotalTrades then begin //An order just got closed. //Execute code here value1 = value1 + 1; //just a counter of how many times this code was ran print("Total executions = ", value1, " Totaltrades= ", totaltrades); oldTotalTrades = totaltrades; End
Print Output:
Total executions = 1204.00 Totaltrades= 1227.00
Total executions = 1205.00 Totaltrades= 1228.00
Total executions = 1206.00 Totaltrades= 1229.00

As you can see, the number of times the code was run is less than the number of total trades.
pic1.jpg
(11.88 KiB) Not downloaded yet

User avatar
Kate MultiCharts
Posts: 589
Joined: 21 Oct 2020
Has thanked: 9 times
Been thanked: 148 times

Re: Run code when order is closed

Postby Kate MultiCharts » 21 Dec 2020

Hello Eduardo,

Total executions are counted once per bar, and a position can be closed several times. That’s why the Total executions number does not correspond to Totaltrades number.

Please try to enable Intra-Bar Order Generation. You can do it by doubleclicking an empty area on the chart. Then in the menu select Format Signals -> Format - Properties tab -> check the Enable Intra-Bar Order Generation box.

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Run code when order is closed  [SOLVED]

Postby Eduardo » 22 Dec 2020

Thank you, I'll try that.


Return to “MultiCharts”