Multicharts.net powerlanguage signals

Hi,

I’m new to powerlanguage programming. I’m trying to make a simple test to approach to the automatic order launch.

I have this code:

private IOrderStopLimit orderbuy;
protected override void Create(){
orderbuy = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Buy));
}
protected override void CalcBar()

orderbuy(Bars.High(0) + 2 ,Bars.High(0) + 2);
            }

What I pretend with this code is to send a buy stop limit order 2 points over the max of the last bar when a bar closes.

If I run this signal, when a bar finishes, the wanted buy order is sent. But if it is not filled during next bar, when it finishes the order is moved to the new high + 2, and that is not what I want.

Later, I have tried to code another example: when a bar finishes, send a buy stop order 2 points over the max, and a sell stop order 2 points under the low. I have tried this code:

private IOrderStopLimit orderbuy;
private IOrderStopLimit ordersell;
protected override void Create(){
orderbuy = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Buy));
ordersell = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Sell));
}
protected override void CalcBar()

orderbuy(Bars.High(0) + 2 ,Bars.High(0) + 2);
ordersell(Bars.Low(0) - 2 ,Bars.Low(0) - 2);
            }

}

When I run it, it launch the buy order, but not the sell order. It only launch the sell order if the buy order is filled.

The final goal I want to achieve is to launch a sort of OCO group at the end of a bar, compossed by:

An entry buy stop limit 2 points over the max of the last bar.
An exit sell limit a number of points over the buy.
An exit sell stop, a number of points below the buy.
If the bar finishes and the buy has not been filled, all orders must be cancelled.
If the buy is filled, then if one of the other orders is filled, the other has to be cancelled.
If the buy is filled and the bar in which it has been filled finished with the other two orders unfilled, move the stop sell some points up, and just wait until one of them is filled. When this occurs, the other order has to be cancelled.
And of course, whenever a position is opened, no new orders can be sent to the market.
I appreciate some help. Not need the whole code. I have enough with some clues in the right direction.

fjgaspar,

with the line “orderbuy(Bars.High(0) + 2 ,Bars.High(0) + 2);” you will constantly send the order on every bar (until filled, unless you allow more than one entry in the same direction). You will also update the order prices at the end of the bar when Bars.High[0] changed compared to the previous bar.

You will likely have to add an variable (boolean for example) that allows sending the order. When all your conditions are met, you set the variable to true and at the end of the bar or when you are filled, you set the variable back to false, so the order is not re-issued on the next bar.

In case that “sendLongOrder” is a variable of type bool, you can do something like this for the order (this doesn’t cover the part where you handle and evaluate what value sendLongOrder should have at the moment):

if (sendLongOrder)
orderbuy.Send(Bars.High[0] + 2 ,Bars.High[0] + 2);

Regarding your problem of not getting an actual sell order, this is because you are sending an exit order (which therefore only appears after you are long), but not an order to go short.
In Multicharts EOrderAction.Sell specifies an order to exit a long trade, while EOrderAction.SellShort will give you what you are looking for.

Regards,

ABCTradingGroup

@ABCTradingGroup thank you for your help.

Optimus Futures

Hi,

I was sure I had replied to this messahe yet. Anyway, I write it again.

Thank you for the answer. That has clarified the question.

But as I continue developing my system, I arrive with more doubts.

Now I need some help for 3 questions. Tell me if is better to open a new thread. The questions are:

  • Is there any chance of send OCO groups (entry, stoploss and take profit) from Powerlanguage, or is neccessary to control that with code and three different and individual orders?

  • I need to send an order to the market when some conditions occurs in actual bar and last n bars. When that conditions meet, I need to send an order when a new bar begins. That is not a problem. A new bar begins and the order is sent to the market. But I need to cancel that order if that bar finishes and the order has not been filled. How can I identify that the bar in which the order was put has not been fllled and has to be cancelled?

  • Related with the above, If I have sent 3 different orders (to simulate the OCO) and one of them is filled. The bar finishes and I want to modify one of the two remaining orders (mainly, move the stoploss). How I identify the bar has ended and how can I modify a sent order?

Thank you very much.

Since you started a topic of Multicharts executions. We have moved your thread here: http://www.optimusfutures.com/forum/platform-related-threads/873-multicharts-order-execution-oco.html
We just want to keep programming and platform functions separately.
Thank you.

Optimus Futures

Ok, thanks for the notice.

But this is not a question of the platform. Is a question of programming. At least, that is what I have tried to mean.

Is about execution from programming, not about sending and executing orders from the platform.