How does the auto trading work ?

Questions about MultiCharts and user contributed studies.
youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

How does the auto trading work ?

Postby youn56 » 05 Apr 2012

Exemple:

I'm running an automated strategy (autotrading) and a buy order is filled.
The evening, i turn off my PC.
The next day, i start the PC and MC. I turn on the strategy (SA button green) and as the "Show the assign the initial market position at the broker dialogue -->Show always" option is enabled, i fill the dialog box to input the initial position and average price.

My question :

Is my exit order (limit or stop order) from my automated strategy going to be send to the TWS normally ?

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

Re: How does the auto trading work ?

Postby Henry MultiСharts » 05 Apr 2012

Yes, there should be no problem. The strategy should behave like it was not turned off.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: How does the auto trading work ?

Postby janus » 05 Apr 2012

Yes, there should be no problem. The strategy should behave like it was not turned off.
Yes that's so for simple strategies but for more complex ones like mine that incorporate pyramid style trading techniques, I have to store certain parameters into a file and then reload them into the strategy when I restart MC to keep track of the various entry and exit levels. I further complicate the issue by having two types of trades at the same time, one is for a quick profit and the other is a runner that tries to extract as much profit as possible using a trailing stop. It would be nicer if pyramid trading was built-into MC. I understand others have requested this and similar features at PM.

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: How does the auto trading work ?

Postby youn56 » 06 Apr 2012

Thank you,
Then another question :
I use the BarsSinceEntry function in the strategy. Which initial position for the BarsSinceEntry does the strategy "understand" ? the input filled one (day d --> BarsSinceEntry = 0) or the strategy one (day d-1 --> BarsSinceEntry = 1) ?

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: How does the auto trading work ?

Postby youn56 » 09 Apr 2012

I don't understand.
Today, i filled the dialog box to input the initial position and average price to my strategy before the opening market.
The strategy stop calculated was 98.12.
The open was 97.74. Then, normally, my trade should be closed to market at 97.74.
Any order was sent by MC.
I join a part of the code. I used an EntryLabel for the entry but not for the exit. Perhaps it's my error ?
Let me know where i'm wrong please.
img1.png
(3.91 KiB) Downloaded 657 times

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: How does the auto trading work ?

Postby Andrew MultiCharts » 12 Apr 2012

Dear Youn56,

We have investigated the situation. Let me explain how it works:
1. You turn on automation in SA mode.
2. All historically generated (backtested) orders are wiped out from the chart.
3. The script is calculated on the last historical bar (in this case “historical” means “the one that is before the current ticking in real-time bar), since no Intra-Bar order Generation tool is enabled and the current moving bar is not closed, so the script is not calculated yet on the current bar.
4. After this the Initial Market Position dialogue appears.
5. In your script you have the condition “if marketposition = 1”. According to the point 3 the script was firstly calculated on the last historical bar, so the market position was 0.

Here is what you need to do to avoid the issue:
• Get your “sell” lines out of “market position” condition. “Sell”, meaning exit order will be sent only if you have a open long position. So your “ if marketposition = 1” is an excessive condition that prevents the script to send the order on next bar in your case.

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: How does the auto trading work ?

Postby youn56 » 12 Apr 2012

Thank you Andrew,
I have modified my code and everything seems to work for now. I will keep you informed.

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: How does the auto trading work ?

Postby youn56 » 16 Apr 2012

Hi Andrew,

It doesn't work as i would like.
I filled the dialog box to input the initial position and average price.

The code to exit is like this :

Code: Select all

sell ("SL") next bar at c * 0.98 stop ;
sell ("TP") Next Bar at entryprice*1.02 limit;
The "entryprice" price remains at 0 until the next bar. The "entryprice" should be the averageprice filled in the input dialog box. Isn't it ?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: How does the auto trading work ?

Postby Andrew MultiCharts » 17 Apr 2012

Hi Andrew,

It doesn't work as i would like.
I filled the dialog box to input the initial position and average price.

The code to exit is like this :

Code: Select all

sell ("SL") next bar at c * 0.98 stop ;
sell ("TP") Next Bar at entryprice*1.02 limit;
The "entryprice" price remains at 0 until the next bar. The "entryprice" should be the averageprice filled in the input dialog box. Isn't it ?
Hello,

As i have mentioned in my previous post, the first calculation takes place on previous bar (the bar before currently ticking). Since no orders and posotions are active on that bar, the entry price is 0. Once the strategy is calculated on the current bar (on close without IOG) the initial position for the strategy are applied.


Return to “MultiCharts”