NexusFi: Find Your Edge


Home Menu

 





Powerlanguage Multicharts.NEt coding questions


Discussion in MultiCharts

Updated
    1. trending_up 1,751 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Powerlanguage Multicharts.NEt coding questions

  #1 (permalink)
 fjgaspar 
Sevilla + Spain
 
Experience: Beginner
Platform: Multicharts
Trading: SP
Posts: 21 since May 2016
Thanks Given: 3
Thanks Received: 3

Hi,

I'm trying to code an strategy for automatic trading in multicharts.net platform, which uses powerlanguage coding language.

I have been able to code the conditions for strategy, but I need help with some questions that I am not able to figure out.

When certain conditions are met, my strategy needs to send 3 orders when current bar is closed: entry (long or short), stoploss, and profit target. I have code this and works ok.

The problem begins after that. When a new bar begins, the orders are sent. I need to achieve the following:

- If the entry order is executed, and when this bar ends and a new bar begins, neither the profit target nor the stoploss have been fullfilled, I need to move the stop loss to another level, and profit target has to keep. From them on, both orders have to keep unchanged until one of them executes.

- After the entry order is executed, if profit target or stop loss is executed at any time, in that same moment the remain order has to be cancelled in this moment: I can't wait until the bar closes.

- If the entry order is not executed during the bar in which has been sent, all 3 orders has to be cancelled upon bar close.

I need some help to code all those things.

Thank you.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


fjgaspar View Post
- If the entry order is executed, and when this bar ends and a new bar begins, neither the profit target nor the stoploss have been fullfilled, I need to move the stop loss to another level, and profit target has to keep. From them on, both orders have to keep unchanged until one of them executes.

How to code this depends on how you've already coded the profit target and stop-loss levels. Because it sounds to me what you're saying here is 'update the stop-loss level' with every bar. That can be done, of course, but how that depends on your strategy's logic.


fjgaspar View Post
- After the entry order is executed, if profit target or stop loss is executed at any time, in that same moment the remain order has to be cancelled in this moment: I can't wait until the bar closes.

Managed orders in MultiCharts .NET remain active until they are cancelled.

If you, for example, only submit the profit target and stop-loss order as long as there's an open position, then when the position is closed, the orders aren't submitted anymore (and thus cancelled).

If they have to be cancelled immediately in this moment, and not till the price bar closes, you need to use intra-bar order generation.



fjgaspar View Post
- If the entry order is not executed during the bar in which has been sent, all 3 orders has to be cancelled upon bar close.

You can do this by adding this logic to your entry conditions, for example by storing the bar number in a variable the first time the entry signal is generated. Then on each calculation you can compare how many bars have passed since that original entry signal, and if that's more than one bar (so the order hasn't been filled on the initial entry bar), then stop resubmitting the entry order.

Reply With Quote
Thanked by:
  #3 (permalink)
 fjgaspar 
Sevilla + Spain
 
Experience: Beginner
Platform: Multicharts
Trading: SP
Posts: 21 since May 2016
Thanks Given: 3
Thanks Received: 3


Thank you for your answer.

Finally, I have solved all the problems.

I define 6 kinds of orders: One stop buy. One stop shellshort. These two are for entries (long or short). One limit sell (Profit for longs). One limit buytocover (profit for shorts), one stop sell (stop protection for longs) and one stop buytocover (stop protection for shorts.
After stablishing conditions for entry, stop loss and profit, I send an entry order to the market. Lets say a long position:

orderdefinedasstopbuy.send(price,price)
orderstoplong.Send(price)
orderprofitlong.Send(price)

When the conditions meet, at the start of the bar, ecery order is sent. The entry order becomes active, and the others don't reach the market because those kinds of orders can't exist without an open position.
If the bar finishes and the entry has not been executed, the order is automatically canceled (default behaviour of Multicharts).

If it has been executed, the two others orders reach the market, because the position is open and the orders were sent. If one of them is executed, the position is closed, and so, the other cannot exists anymore, so it is automatically canceled.

If tha bar ends without none of the orders executed, the code continue. I have added a block of code that ask for the position in market, so if the position is opened, the two 'protection' orders are sent again.

I have only another question that I haven't been able to solve. How can I know the execution price or an order? I mean that the script knows that price and store it into a variable. I know I can llok for execution price in the account page.

Started this thread Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

fjgaspar,

depending on the automation mode you are using (Sync or Async) you can use the Strategy Performance related reserved words.
When operating in Sync mode the strategy positions on the chart will be updated when the broker reports them as filled and they have matching fill prices.

When operating in Async mode they are independent of the broker prices and can therefore be different. While the strategy performance related reserved words will still return the values as you see them on the chart, accessing the broker fill prices will likely require your code to subscribe to the TradeManager to monitor and track the position changes. You can find a few example in the official Multicharts forum on how to do that, but it's a bit slim and much more complex than using the performance related reserved words directly.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #5 (permalink)
 fjgaspar 
Sevilla + Spain
 
Experience: Beginner
Platform: Multicharts
Trading: SP
Posts: 21 since May 2016
Thanks Given: 3
Thanks Received: 3

Thanks again.

I use Sync mode. I have tried with StrategyInfo.AvgEntryPrice but it returns 0. Maybe if I wait till next bar, it will give me the real value, but when I send an order type market, it gets executed in that moment and I have to know what is the execution price when is executed.

Started this thread Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

Are you using intrabar order generation? If not, the values might only be updated at the end of the bar.

Regards,

ABCTG

Follow me on Twitter Reply With Quote




Last Updated on August 5, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts