Output / Write / Alerts and OnBrokerStategyOrderFilled

Questions about MultiCharts .NET and user contributed studies.
beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 11 Apr 2014

I would like to make more clear the information I get in an email, sent by my strategy.


The code is..

protected override void OnBrokerStategyOrderFilled(bool is_buy, int quantity, double avg_fill_price)
{
Alerts.Alert("{0} - order has been filled: buy? {1}, quantity: {2}, avg fill: {3}",
DateTime.Now.ToString("d-M-yy HH:mm:ss"),
is_buy,
quantity,
avg_fill_price);


I can't find much information for OnBrokerStategyOrderFilled What information is available when a trade fills? How many columns can I use?

I tried looking at Alerts and Outputs, but still don't know what reserved words I can use.

Thanks in advance.
DB

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby JoshM » 13 Apr 2014

I can't find much information for OnBrokerStategyOrderFilled What information is available when a trade fills?
In the context of this method, that would be the parameters from the method itself (i.e. `OnBrokerStategyOrderFilled(bool is_buy, int quantity, double avg_fill_price)`).

Btw, this method is discussed in the wiki.
How many columns can I use?
What do you mean with a column? Do you want to output to an Excel file or something?
I tried looking at Alerts and Outputs, but still don't know what reserved words I can use.
`Alerts.Alert("alert message")` for alerts, and `Output.WriteLine("output message")` for outputting to the PL Editor window.

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 13 Apr 2014

It is discussed but not with any detail that I find to be clear.

Through discussions with others at another website where direct answers were provided...

I now understand that output write is required to send an email when a trade takes place. Not real intuitive for someone learning this language when the ALERT TAB has a section to send emails. Given I was able to send out audible and visual alerts in understandable form, why not emails? So I got highly focuses on trying to make Alert alert work and clearly heading down the wrong path.

I have already figured out, I can have as many columns of information I want, just do not know the keywords / reserved words that will send through a clear communication. I had been hoping for the email to say something Like...

Sell 1 EPM14 at 1821.75 Limit
Buy 7 EPM14 at 1820.25 Limit

Best in 1 email, but I can live with 2

The information and the form it takes is crude and fine for me. If I need an assistant to deal with it for me, I do not think they could manage it most of the time.

I have concluded this can not be done with Output and it was suggested I need to use the Trade Manager. Which for me, does not have enough info to do anything with it. Even then, it may not work as I would hope because there may not be enough time to act on the information.

In my perfect world, I would turn on the automation and forget it. With the issues that surface and could surface, no can do, at least not yet.

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 13 Apr 2014

I made some errors.. which I have discovered. Further points to me that the information is not clear. I do not need output write to send the email, I need to see what would be in the email sent.

OnBrokerStrategyOrderFilled()

protected override void OnBrokerStategyOrderFilled(bool is_buy, int quantity, double avg_fill_price)

will send the unclear email I have been trying to straighten out.

hairyMug
Posts: 57
Joined: 03 Feb 2014
Has thanked: 5 times
Been thanked: 6 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby hairyMug » 13 Apr 2014

Try This:

protected override void OnBrokerStategyOrderFilled(bool is_buy, int quantity, double avg_fill_price)
{
int lastOrderIndex= this.TradeManager.TradingData.Orders.Items.Count() -1;
PowerLanguage.TradeManager.Order lastOrder= this.TradeManager.TradingData.Orders.Items[lastOrderIndex];
string ls_out = lastOrder.Action.ToString();
ls_out= ls_out +"\t" + lastOrder.Contracts.ToString();
ls_out = ls_out + "\t" + lastOrder.Symbol.ToString();
ls_out = ls_out + "\t" + lastOrder.ExecPrice.ToString();
ls_out= ls_out +"\t" + lastOrder.Category.ToString();
Alerts.Alert(ls_out);
}

There are many other parts of the trade available in the "lastOrder" and this is predicated on new positions being added to the end of the list

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 13 Apr 2014

hairy,

I appreciate the help! Was there a source that provided the information on last order
or was it a result of digging around?


When I added to my code that which you provided and compiled, an error in the log...

'System.Array' does not contain a definition for 'count' and no extension method 'count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) "Don_Long_Email_Test" [Strategy] Ln 74

Tried to research what might be the cause, attempted some changes, none of which helped. Went back to the original.

I must have missed a step.

Thank
Don

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 13 Apr 2014

Typo on my part


typed count and needed Count


but now get error with signal

:System.IndexOutOfRangeException:Index was outside the bounds of the array.

now digging for a solution :)

hairyMug
Posts: 57
Joined: 03 Feb 2014
Has thanked: 5 times
Been thanked: 6 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby hairyMug » 14 Apr 2014

"out of bounds" will happen if the index < 0 OR if the "items" collection starts at 1.
Try using:

int lastOrderIndex= this.TradeManager.TradingData.Orders.Items.Count() ;

If that works, then the collection is "1 based".
If that does not work the look to see if the lastIndex >=0 before using it...


(Lots of digging and many years with .Net)

BTW; as you have discovered, C# is case-sensitive... ;-)

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 14 Apr 2014

Done all I can to find it.. still getting the error.

Going to hold my head under water for 30 mins and see if that helps.

It would be so much easier if MC would make it a select-able option check box.

hairyMug
Posts: 57
Joined: 03 Feb 2014
Has thanked: 5 times
Been thanked: 6 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby hairyMug » 14 Apr 2014

I would suggest getting c# express (free) and using the debugger...
(if express supports attaching to process)

beck donald
Posts: 199
Joined: 25 Jan 2008
Has thanked: 2 times
Been thanked: 7 times

Re: Output / Write / Alerts and OnBrokerStategyOrderFilled

Postby beck donald » 14 Apr 2014

I have it and after about 30 mins waiting to get into in debug mode I sprayed it with RAID and shut it down.

I will try again later.

hairy, I appreciate your trying to help!
Don


Return to “MultiCharts .NET”