How to modify "Exit Strategy" buttons

Questions about MultiCharts and user contributed studies.
czaussie1029
Posts: 7
Joined: 20 Nov 2023

How to modify "Exit Strategy" buttons

Postby czaussie1029 » 28 Nov 2023

Hello all,

I am having hard time finding a place in Power Language Editor or elsewhere to modify scripts that control those Exit Strategy buttons like "Stop Loss Strategy" or "Profit Target Strategy".

I see I can create new button (template) and modify its parameters - but I would like to go into the code and modify deeper. Is that possible?

Basically, I am trying to create custom Stop Loss and Take Profit buttons with their own code.

What's the best way to achieve this? Thank you in advance for your tips.

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: How to modify "Exit Strategy" buttons

Postby Polly MultiCharts » 29 Nov 2023

Hello czaussie1029,

PowerLanguage Editor can be used for creating and modifying strategies for auto trading.
The Chart Trading panel is used for manual trading and this is a different mode. There is no option to modify the Exit strategies in PowerLanguage Editor.
You can change the settings using the Edit button or create templates. You might also try using Master Strategy.
Please note that we always recommend testing your setup with a pre-built Paper Trader or with a demo broker account before going live.

As a workaround there is a possibility to write a script in PowerLanguage that would respond to mouse clicks on the chart.
In MultiCharts .NET there are more possibilities to do that, for example using pre-built signal _ChartToolBar_Trading_.

czaussie1029
Posts: 7
Joined: 20 Nov 2023

Re: How to modify "Exit Strategy" buttons

Postby czaussie1029 » 05 Dec 2023

Thank you for your answer.

I am trying with a script that uses MouseClickCtrlPressed. That seems to work well, I can read prices, etc. but can you point me in the direction of how to set stop loss or any order for that matter from the script? It looks like those functions can be only called from strategies, not indicators?

Basically, what is the best mechanism to read the open position price and apply stop loss order according to some calculations?

Thank you in advance.

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: How to modify "Exit Strategy" buttons

Postby Polly MultiCharts » 06 Dec 2023

czaussie1029,

In MultiCharts indicators cannot send orders, it is a visual technical analysis too, used to analyze market conditions and identify and forecast trends and market patterns.
Orders can be sent by signals according to a set of trading rules implemented in the signal's algorithm.
For more info please see this page.

If you need to read the open position price you can use the OpenEntryPrice keyword and then send Stop orders according to the specified conditions.
There is also a SetStopLoss order that can close out the entire position or the entry if the loss reaches the specified currency value. When using SetStopLoss there is no need to specify OpenEntryPrice, as if an entry appears, this exit order is generated at once without waiting for the next calculation on the bar close or next tick.

czaussie1029
Posts: 7
Joined: 20 Nov 2023

Re: How to modify "Exit Strategy" buttons

Postby czaussie1029 » 14 Dec 2023

Ok, I was able to catch mouse clicks through strategy and I can read various account (IB) parameters and I can read open trade symbol, etc.

But is it possible to create stop loss order for an open position this way? I open the trades manually, but would like to set stop loss (at ad-hoc calculated price) once I Ctrl+click. Basically:

1. Trade is opened in MC manually
2. Strategy is running in the window and is reading account information (=it can see the trade)
3. Ctrl+click is pressed
4. Stop Loss order is generated, say 30 pips away from the current price (I would pass the price into the code that creates the SL order, presumably).

Is that possible?

I experimented with SetStopLoss and SetStopLoss_pt but I don't believe that is the right approach here.

Thank you in advance!

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: How to modify "Exit Strategy" buttons

Postby Polly MultiCharts » 20 Dec 2023

czaussie1029,

In MultiCharts there are two modes of trading: manual and automatic. And usually we do not recommend combining these two methods. For more info about it please see this page.

The most efficient solution will be to create a strategy that will generate the entries and exist according to the specified conditions, i.e. using only automatic trading.

But as a workaround you can use Sync Mode of auto trading and use !From Broker To Strategy MP Synchronizer! so that your strategy is aware of the manual orders.
Please note that we always recommend testing your signal with a demo broker account or with a pre-built Paper Trader broker profile before going live.

You could also post your suggestion at our Project Management. If it is popular among our users, our developers will review the possibility of adding it.

czaussie1029
Posts: 7
Joined: 20 Nov 2023

Re: How to modify "Exit Strategy" buttons

Postby czaussie1029 » 21 Dec 2023

Thank you for the reply.

Point taken on not recommending automated and manual trading. That said, I have lived off manual FX trading for over 20 years and I do not see my discretionary manual trades to be converted to automated, probably ever.

But I see a lot of value of automated generation of signals and also SL/PT orders on the fly - but off my manual entries.

OK, so I have experimented with !From Broker To Strategy MP Synchronizer! script, I even get "MP is Synchronized" text on the chart. SA is enabled. I experimented with various timeouts.

But I still get "0" currentcontracts, "0" marketposition. I also tried all other variations of Market_at_Broker...

Only information that refers to the manually opened position is through GetPositionSymbol (I can get the EURUSD symbol properly), but this worked without !From Broker To Strategy MP Synchronizer! script as well.

Obviously I am missing something, can you continue pushing me in the right direction? I actually think that my approach is not unique to me, other users can benefit from understanding this better too.

Thank you in advance.

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: How to modify "Exit Strategy" buttons

Postby Polly MultiCharts » 27 Dec 2023

czaussie1029,

Please make sure you have Recalculate in Broker Events: Market Position Change and Order Filled boxes enabled in Format → Strategy Properties → Auto Trading tab. After that please try reproducing the issue again. Will currentcontracts and marketposition still display 0?

czaussie1029
Posts: 7
Joined: 20 Nov 2023

Re: How to modify "Exit Strategy" buttons

Postby czaussie1029 » 12 Jan 2024

Thank you for the reply. I triple checked the setting, it is as indicated by you above. Still, I get zero position, zero contracts.

I am posting my code, it is as simple as it gets I would hope.

I can confirm I can read symbol name when the position is indeed opened.

Automate Order Execution is enabled, !From Broker to Strategy is enabled and I get the message "MP is synchronized"

Something small is missing :)

Code: Select all

[IntrabarOrderGeneration = false] [RecoverDrawings = false] [ProcessMouseEvents = True] if(getappinfo(aiCalcReason) = CalcReason_mouseLClick) then begin print(MouseClickCtrlPressed," ","Mouse click + Ctrl key pressed event"); print(GetPositionSymbol("U6XYZ123",1),"","Here I can get symbol properly when position is opened"); print(CurrentContracts," "," Currentcontracts"); print(MarketPosition_at_Broker," "," MarketPosition"); end;

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: How to modify "Exit Strategy" buttons

Postby Polly MultiCharts » 16 Jan 2024

czaussie1029,

Thank you for the info. We have checked the script on our end and it works as expected.

After the synchronization, please check File → New → Order and Position Tracker → Strategy Position tab. Position Match should be true for the auto trading chart.
Also please make sure you have the Symbol Mapping set correctly. For more info about it please see this page.
If it doesn’t help, we would need to investigate the issue in detail, so please send us a description of the issue and the screenshots demonstrating it to our support email.


Return to “MultiCharts”