Powerlanguage Multicharts.NEt coding questions - MultiCharts | futures.io
futures.io futures trading


Powerlanguage Multicharts.NEt coding questions
Started: by fjgaspar Views / Replies:229 / 5
Last Reply: Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Powerlanguage Multicharts.NEt coding questions

  #1 (permalink)
Trading Apprentice
Sevilla + Spain
 
Futures Experience: Beginner
Platform: Multicharts
Favorite Futures: SP
 
Posts: 14 since May 2016
Thanks: 2 given, 2 received

Powerlanguage Multicharts.NEt coding questions

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.

Reply With Quote
 
  #2 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: -
 
Jura's Avatar
 
Posts: 766 since Apr 2010
Thanks: 2,347 given, 646 received


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
The following user says Thank You to Jura for this post:
 
  #3 (permalink)
Trading Apprentice
Sevilla + Spain
 
Futures Experience: Beginner
Platform: Multicharts
Favorite Futures: SP
 
Posts: 14 since May 2016
Thanks: 2 given, 2 received


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.

Reply With Quote
 
  #4 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,191 since Apr 2013
Thanks: 198 given, 681 received

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

Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Sevilla + Spain
 
Futures Experience: Beginner
Platform: Multicharts
Favorite Futures: SP
 
Posts: 14 since May 2016
Thanks: 2 given, 2 received

Futures Edge on FIO
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.

Reply With Quote
 
  #6 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,191 since Apr 2013
Thanks: 198 given, 681 received

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

Regards,

ABCTG

Reply With Quote

Reply



futures.io > > > > Powerlanguage Multicharts.NEt coding questions

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Anthony Drager: Pulling the trigger with confidence

Elite only
 

Leo Murphy: The Art and Science of Technical Analysis

Elite only
 

FuturesTrader71: Ask Me Anything

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to start if you want to learn .NET powerlanguage uspilotzzz MultiCharts 3 April 20th, 2016 09:10 AM
The Booker Method (Powerlanguage .NET) Aufidius MultiCharts 0 March 2nd, 2016 02:48 PM
Convert AmiBroker Formula Language into MultiCharts PowerLanguage p2tr AmiBroker 0 March 24th, 2014 07:28 AM
Money management code in Multicharts PowerLanguage moses MultiCharts 1 March 18th, 2013 07:34 AM
Powerlanguage / Multicharts Strategy Stoploss code Wouter Elite EasyLanguage Automated Trading 10 September 17th, 2012 03:58 PM


All times are GMT -4. The time now is 01:14 AM.

no new posts
Page generated 2017-01-24 in 0.12 seconds with 20 queries on phoenix via your IP 54.161.200.170