Exit controlled by strategy

Questions about MultiCharts .NET and user contributed studies.
Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Exit controlled by strategy

Postby Fabrice » 14 Feb 2013

When doing manual trading, I want a strategy to manage the exit. Can you provide an example of code showing

1/ how to access the open P/L (like the one displayed in the chart when doing manual trading)
2/ send an exit order

I have found how to access to the position with StrategyInfo.MarketPositionAtBroker. I am no sure that SignalObject can only be used (CurrentPosition.OpenLots and CurrentPosition.OpenProfit are always at 0), may be TradeManager need to be used.

Thanks.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Exit controlled by strategy

Postby Henry MultiСharts » 14 Feb 2013

Hello Fabrice,

You need to use From_Broker_To_Strategy_MP_Synchronizer signal to assign your broker position (that was opened manually) to your exit strategy. Once your strategy has this information (StrategyInfo.MarketPosition) - IStrategy.CurrentPosition property should start returning actual position information. CurrentPosition.OpenProfit will return Open PL.

You can find the code examples for sending orders commands in the source code of the prebuilt MultiCharts studies.
Please go to PowerLanguage .Net editor->Open to view the full list of studies.
Market order entry and exit command examples can be found in Custom_Strategy signals;
For exit strategies examples please refer to Profit_Target, Stop_loss, Breakeven_Stop, Dollar_Trailing and Percent_Trailing prebuilt signals.

You can add From_Broker_To_Strategy_MP_Synchronizer signal and one of the mentioned above exit signals to see how it works. Multiple signals applied to one chart form a single strategy with its market position, i.e. there is no additional code required to "link" the signals together.

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: Exit controlled by strategy

Postby Fabrice » 15 Feb 2013

Hello Henry,

Thank you for the help. I have done several tries but failed to get a real time P/L like the one displayed in the arrow of manual trading.

In the signal From_Broker_To_Strategy_MP_Synchronizer :
- is it useful to tweak TimeOutMS and LatencyMS ?
- is it necessary to enable intra-bar order generation ?

In the strategy properties, in the "Assign the Initial Market Position at the Broker Settings", what should be chosen :
- Show the Assign the Initial MarketPosition at the Broker dialogue (the default) ?
- Assume the initial market position at the broker FLAT
- Assume the initial market position at the broker the SAME AS on the chart

It seems also that the results are differents when the SA is off and the SA is on (i.e. when SA is off, CurrentPosition.OpenProfit remains at 0 even if a position is opened).

Thanks.
Last edited by Fabrice on 15 Feb 2013, edited 2 times in total.

Zoli
Posts: 90
Joined: 12 Sep 2012
Has thanked: 24 times
Been thanked: 38 times

Re: Exit controlled by strategy

Postby Zoli » 15 Feb 2013

Hi Fabrice,

I cannot say for sure but it might be because of the preferred currency setting.
Do you have the preferred currency set as USD? (File->Preferences->Trading tab)
If yes, try setting it to none and see if they match.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Exit controlled by strategy

Postby Henry MultiСharts » 15 Feb 2013

- is it useful to tweak TimeOutMS and LatencyMS ?
It is important to know the average time of receiving information from the broker about the market position and filled order from the moment the request was sent. Timeouts should be increased in case of need.
This topic has been already discussed multiple times in the other threads: Automated exit strategy with manual trading
- is it necessary to enable intra-bar order generation ?
It is already enabled by default for this script.

Code: Select all

[IOGMode(IOGMode.Enabled)]
In the strategy properties, in the "Assign the Initial Market Position at the Broker Settings", what should be chosen :
- Show the Assign the Initial MarketPosition at the Broker dialogue (the default) ?
- Assume the initial market position at the broker FLAT
- Assume the initial market position at the broker the SAME AS on the chart
if you are using a synchronizer script you do not need to input any values in "Assign the Initial Market Position at the Broker Settings" window. You can leave it by default.
It seems also that the results are differents when the SA is off and the SA is on (i.e. when SA is off, CurrentPosition.OpenProfit remains at 0 even if a position is opened).
CurrentPosition works only when you have auto trading = ON and your strategy has an open position. Synchronizer script will assign the position only when auto trading = ON.

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: Exit controlled by strategy

Postby Fabrice » 15 Feb 2013

@zoli,
Thank you for your help but there is not this setting in MC.Net 8.0 (I do not use beta version for trading).
Regards.

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: Exit controlled by strategy

Postby Fabrice » 19 Feb 2013

Hello Henry,
Thanks for these details. I have done some other tries, but nothing run as smooth as I have expected. There have been probably a lot of changes in 8.5 beta from 8.0 release. I will wait 8.5 release before trying again. I must say that "attaching" a "coded" strategy on a manual entry should be more straightforward and documented.
Regards.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Exit controlled by strategy

Postby Henry MultiСharts » 20 Feb 2013

Hello Fabrice,

Please describe what exactly is not clear or lacks documentation. I will forward your suggestions to our developers for further improvements.


Return to “MultiCharts .NET”