Why an Order Was or Was Not Executed  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Why an Order Was or Was Not Executed

Postby orad » 29 Dec 2014

Can someone please translate the PowerLanguage code in this wiki page Why an Order Was or Was Not Executed to C#?

I don't understand why...

Code: Select all

Condition1 = close > close[1];
when 'true' means 'order to buy is generated'.

Thanks!

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

Re: Why an Order Was or Was Not Executed  [SOLVED]

Postby JoshM » 29 Dec 2014

I don't understand why...

Code: Select all

Condition1 = close > close[1];
when 'true' means 'order to buy is generated'.
Because that sloppy PowerLanguage code is like this (redundant lines removed for brevity):

Code: Select all

Condition1 = close > close[1];

If Condition1 = true then begin
Buy next bar at close limit;
end;
So the entry condition for the `buy next bar at close limit` order happens when `Condition1` is true. And that variable is true when the current close is greater than the previous close (`close > close[1]`). So, one can say:

Code: Select all

Condition1 = close > close[1];
when 'true' means 'order to buy is generated'
..because when `Condition1` would be false, the limit order would not be submitted.

In my opinion, that Wiki page is not helpful because the reasons why or why not a trade was executed are highly dependent on your strategy.

That being said, if you want a similar example for C#:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
using PowerLanguage.TradeManager;

namespace PowerLanguage.Strategy
{
public class Snippet_Strategy : SignalObject
{
public Snippet_Strategy(object _ctx) : base(_ctx) { }

private IOrderMarket enterLong, exitLong;

protected override void StartCalc()
{
Output.Clear();
}

protected override void Create()
{
enterLong = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy));
exitLong = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Sell));
}

protected override void CalcBar()
{
bool longCondition = Bars.Close[0] > Bars.Close[1];
bool shortCondition = Bars.Close[0] < Bars.Close[1];

if (longCondition == true)
{
enterLong.Send(1);
}
else if (shortCondition == true)
{
exitLong.Send(1);
}

// Debug to the PowerLanguage .NET Editor Output Window
Output.WriteLine("{0} - #{1} | MP: {2}, MP at broker: {3}, longCondition = {4}, shortCondition = {5}",
Bars.Time[0].ToString("d-M-yy HH:mm:ss"),
Bars.CurrentBar,
StrategyInfo.MarketPosition,
StrategyInfo.MarketPositionAtBroker,
longCondition,
shortCondition
);
}
}
}
Which gives as output:

Code: Select all

29-12-14 10:11:00 - #369 | MP: 1, MP at broker: 0, longCondition = True, shortCondition = False
29-12-14 10:16:00 - #370 | MP: 2, MP at broker: 0, longCondition = False, shortCondition = True
29-12-14 10:21:00 - #371 | MP: 0, MP at broker: 0, longCondition = True, shortCondition = False
29-12-14 10:26:00 - #372 | MP: 1, MP at broker: 0, longCondition = True, shortCondition = False
29-12-14 10:31:00 - #373 | MP: 2, MP at broker: 0, longCondition = False, shortCondition = True
29-12-14 10:36:00 - #374 | MP: 0, MP at broker: 0, longCondition = True, shortCondition = False
29-12-14 10:41:00 - #375 | MP: 1, MP at broker: 0, longCondition = True, shortCondition = False
29-12-14 10:46:00 - #376 | MP: 2, MP at broker: 0, longCondition = False, shortCondition = True
(Can a moderator move this topic to the general MC .NET forum? Thanks.)

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Why an Order Was or Was Not Executed

Postby orad » 15 Jan 2015

Thanks JoshM, I was confused because the confirmation of 'order to buy is generated' was printed before the Buy order was sent. I think your equivalent C# code should be included in the wiki. Thanks again for your great answer.


Return to “MultiCharts .NET”