MultiCharts | PowerLanguage Tutorials | CH6: Buy and Sell

Buy and Sell

PowerLanguage provides Buy, Sell, SellShort and BuyToCover instructions for placing orders.

The syntax of these instructions is composed of Action + NameAndNumberOfTrades + Order.

Instruction Syntax
Action NameAndNumberOfTrades Order
Buy [("EntryLabel")][TradeSize] Order
Sell [("ExitLabel")][From Entry("EntryLabel")][TradeSize[Total]]
SellShort [("EntryLabel")][TradeSize]
BuyToCover [("ExitLabel")][From Entry("EntryLabel")][TradeSize[Total]]

Order

Order determines the price and time of placing an order. There are 4 types of Order.

Note: It is not recommended to use This Bar On Close in practice, because it may cause inconsistencies between the real time trade signals and the backtest trade signals.

Order Semantic
This Bar On CloseA market order is sent on the last tick of this bar.
On – skip word, just to increase readability and will be skipped during execution.
Next Bar At Open
Next Bar At Market
Send a market order on the first tick of the next bar.
Market and Open are interchangeable.
At – skip word, just to increase readability and will be skipped during execution.
Next Bar At <Price> LimitA limit order is sent at the first tick of the next bar. If the order is not filled at the end of the bar, the order will be cancelled.
<Price> – Number specifying the price of the limit order.
At skip word, just to increase readability and will be skipped during execution.
Next Bar At <Price> StopA stop order is sent at the first tick of the next bar. If the order is not filled at the end of the bar, the order will be cancelled.
<Price> – Number specifying the price of the stop order.
At skip word, just to increase readability and will be skipped during execution.
4種 OrderCommandType

Buy

Buy syntax is composed of Action + NameAndNumberOfTrades + Order.
If there exists short position when the buy order is filled, the short position will be closed.

Instruction Syntax
Action NameAndNumberOfTrades Order
Buy [("EntryLabel")][TradeSize] Order

Buy syntax

Buy[("EntryLabel")] [TradeSize] Order;

Where:

EntryLabel – Name this buy entry as EntryLabel. The buy name will be displayed on the chart.
[] represents this parameter can be omitted.
If EntryLabel is not specified, the default name will be “Buy” for the first entry, “Buy#2” for the second, “Buy#3” for the third, and so on.
As Sell, you can use the EntryLabel to specify which entry to sell.

TradeSize – Specify the number of shares(contracts) to buy.
Need to be followed by one of the following words: Share, Shares, Contract or Contracts.
[] represents this parameter can be omitted.
If TradeSize is not specified, the value of Settings->Strategy Properties->Properties->Fixed Order Shares is used.

Order  – Specifies the order type. See Order.

Examples

Place a market order which buys 1 contract at next bar and name this entry as “Entry”.

Buy("Entry")1 Contract Next Bar Market;

Place a limit order which buys 2 shares at price is smaller than or equal to 100 at next bar.

Buy 2 Shares Next Bar At 100 Limit;

Place a stop order which buys 10 contracts at price is greater than or equal to 50 at next bar.

Buy 10 Contracts Next Bar 50 Stop;

Sell

Sell syntax is composed of Action + NameAndNumberOfTrades + Order.

Instruction Syntax
Action NameAndNumberOfTrades Order
Sell [("ExitLabel")][From Entry("EntryLabel")][TradeSize[Total]] Order

Sell syntax

Sell[("ExitLabel")] [From Entry("EntryLabel")] [TradeSize[Total]] Order

Where:

ExitLabel – Name this sell exit as ExitLabel. The sell name will be displayed on the chart.
[] represents this parameter can be omitted.
If ExitLabel is not specified, the default name will be “Sell” for the first exit, “Sell#2” for the second, “Sell#3” for the third, and so on.

EntryLabel – Specifies the name of the buy entry to sell.
From is skip word, just to increase readability and will be skipped during execution.
[] represents this parameter can be omitted.
If EntryLabel is not specified, default is sell all entry positions.

TradeSize – Specify the number of shares(contracts) to sell from each entry.
Need to be followed by one of the following words: Share, Shares, Contract or Contracts.
If TradeSize is followed by Total, the total number of TradeSize shares(contracts) will be sold according to the First In, First Out order of entry.
[] represents this parameter can be omitted.
If TradeSize is not specified, default is sell all shares(contracts).

Order – Specifies the order type. See Order.

Examples

Place a market order which sells 10 shares from entry named Original Entry at next bar.

Sell Entry("Original Entry")10 Shares Next Bar At Market;

Place a market order which sells 5 contracts from each entry at next bar.

Sell 5 Contracts Next Bar Market;

Place a limit order which sells total 1 shares at price is greater than or equal to 100 at next bar.

Sell 1 Share Total Next Bar At 100 Limit;

Place a stop order which sells all contracts at price is smaller than or equal to 50 at next bar.

Sell Next Bar 50 Stop;

SellShort

SellShort syntax is composed of Action + NameAndNumberOfTrades + Order.
If there exists long position when the short order is filled, the long position will be closed.

Instruction Syntax
Action NameAndNumberOfTrades Order
SellShort [("EntryLabel")][TradeSize] Order

SellShort syntax

SellShort[("EntryLabel")] [TradeSize] Order

or

Sell Short[("EntryLabel")] [TradeSize] Order

Where:

EntryLabel – Name this short entry as EntryLabel. The short name will be displayed on the chart.
[] represents this parameter can be omitted.
If EntryLabel is not specified, the default name will be “Short” for the first entry, “Short#2” for the second, “Short#3” for the third, and so on.
As BuyToCover, you can use the EntryLabel to specify which entry to cover.

TradeSize – Specify the number of shares(contracts) to short.
Need to be followed by one of the following words: Share, Shares, Contract or Contracts.
[] represents this parameter can be omitted.
If TradeSize is not specified, the value of Settings->Strategy Properties->Properties->Fixed Order Shares is used.

Order – Specifies the order type. See Order.

Examples

Place a market order which shorts 1 contract at next bar and name this entry as “Entry”.

SellShort("Entry")1 Contract Next Bar Market;

Place a limit order which shorts 2 shares at price is greater than or equal to 100 at next bar.

SellShort 2 Shares Next Bar At 100 Limit;

Place a stop order which shorts 10 contracts at price is smaller than or equal to 50 at next bar.

SellShort 10 Contracts Next Bar 50 Stop;

BuyToCover

BuyToCover syntax is composed of Action + NameAndNumberOfTrades + Order.

Instruction Syntax
Action NameAndNumberOfTrades Order
BuyToCover [("ExitLabel")][From Entry("EntryLabel")][TradeSize[Total]] Order

BuyToCover syntax

BuyToCover [("ExitLabel")] [From Entry("EntryLabel")] [TradeSize[Total]] OrderCommandType

or

Buy To Cover [("ExitLabel")] [From Entry("EntryLabel")] [TradeSize[Total]] OrderCommandType

Where:

ExitLabel – Name this cover exit as ExitLabel. The cover name will be displayed on the chart.
[] represents this parameter can be omitted.
If ExitLabel is not specified, the default name will be “Cover” for the first exit, “Cover#2” for the second, “Cover#3” for the third, and so on.

EntryLabel – Specifies the name of the short entry to cover.
From is skip word, just to increase readability and will be skipped during execution.
[] represents this parameter can be omitted.
If EntryLabel is not specified, default is cover all entry positions.

TradeSize – Specify the number of shares(contracts) to cover from each entry.
Need to be followed by one of the following words: Share, Shares, Contract or Contracts.
If TradeSize is followed by Total, the total number of TradeSize shares(contracts) will be covered according to the First In, First Out order of entry.
[] represents this parameter can be omitted.
If TradeSize is not specified, default is cover all shares(contracts).

Order – Specifies the order type. See Order.

Examples

Place a market order which covers 10 shares from entry named Original Entry at next bar.

BuyToCover Entry("Original Entry")10 Shares Next Bar At Market;

Place a market order which covers 5 contracts from each entry at next bar.

BuyToCover 5 Contracts Next Bar Market;

Place a limit order which covers total 1 shares at price is smaller than or equal to 100 at next bar.

BuyToCover 1 Share Total Next Bar At 100 Limit;

Place a stop order which covers all contracts at price is greater than or equal to 50 at next bar.

BuyToCover Next Bar 50 Stop;

Reference

https://www.multicharts.com/trading-software/index.php?title=Category:Strategy_Orders

https://www.multicharts.com/trading-software/index.php?title=Buy

https://www.multicharts.com/trading-software/index.php?title=Sell

https://www.multicharts.com/trading-software/index.php?title=SellShort

https://www.multicharts.com/trading-software/index.php?title=BuyToCover

Leave a Reply