Auto Trader

Questions about MultiCharts and user contributed studies.
widgetman
Posts: 81
Joined: 11 Oct 2005

Auto Trader

Postby widgetman » 03 Apr 2007

Hi,
Could someone please show me a code example using the auto trader to IB and explain how to tag stops as well when a order goes in. So far all I have been able to get it to do is send orders at the Market price. I would like to be able to send stops as well and also determine if I am in a position and a cycle reverses then cover current order and flip the other way. Any input would be appreciated.
-Thanks

widgetman
Posts: 81
Joined: 11 Oct 2005

Postby widgetman » 03 Apr 2007

Hi,
I also noticed playing with a custom strategy that using the Marketposition command after I enter a order short does not return -1 as expected. What are the three variables I should see with using MP ?

-Thanks
0 no position
1 long position
short position ???

widgetman
Posts: 81
Joined: 11 Oct 2005

MarketPosition Variable

Postby widgetman » 03 Apr 2007

Hi,
Listed below is a simple If loop that tries to determine if we are in a current position. If we are then it covers the position and flips the other way. For some reason the marketposition variable never comes back -1 for a short position. I noticed in the search forums that was acknowledged and supposed to be fixed in the next release. The posting was 11/22/06 so I am assuming it was fixed. Any idea why I never see a -1 for a short signal ? Any thoughts and help would be appreciated.
-Thanks

MP = marketposition;
if MP = 0 then Buy ( "Long" ) next bar at open ;
if MP = -1 then
begin
Buy ( "Cover Short" ) next bar at open ;
print("Covered Short");
Buy ( "Long" ) next bar at open ;

end;
Alert("Long Fired");
print("Market Position is ",MP);

widgetman
Posts: 81
Joined: 11 Oct 2005

Postby widgetman » 05 Apr 2007

Does it normally take days to get some simple questions answered ?

User avatar
Stanley Miller
Posts: 556
Joined: 26 Jul 2005
Has thanked: 3 times

Re: MarketPosition Variable

Postby Stanley Miller » 09 Apr 2007

Hi,
Listed below is a simple If loop that tries to determine if we are in a current position. If we are then it covers the position and flips the other way. For some reason the marketposition variable never comes back -1 for a short position. I noticed in the search forums that was acknowledged and supposed to be fixed in the next release. The posting was 11/22/06 so I am assuming it was fixed. Any idea why I never see a -1 for a short signal ? Any thoughts and help would be appreciated.
-Thanks

MP = marketposition;
if MP = 0 then Buy ( "Long" ) next bar at open ;
if MP = -1 then
begin
Buy ( "Cover Short" ) next bar at open ;
print("Covered Short");
Buy ( "Long" ) next bar at open ;

end;
Alert("Long Fired");
print("Market Position is ",MP);


MarketPosition returns the correct values on my side, please see the attached screenshot. Which version of MultiCharts do you have?

User avatar
Kate
Posts: 758
Joined: 08 Dec 2006

Postby Kate » 09 Apr 2007

snapshot
Attachments
mp.GIF
mp.GIF (87.78 KiB) Viewed 452 times

widgetman
Posts: 81
Joined: 11 Oct 2005

Auto Trader

Postby widgetman » 09 Apr 2007

Hi Kate,
Thanks for gettin back to me. I am using 2.0.777.777 and in your screen shot I noticed you are using Buy Long and Sell Short commands.
I simply used Buy and Sell so that may be why I could not get marketposition to work correctly. I will try it and see.

widgetman
Posts: 81
Joined: 11 Oct 2005

IB Order Status

Postby widgetman » 09 Apr 2007

Hi Kate,
I am now able to get a marketposition status to read 0,1,-1
I am not however able to get a correct status position back from IB after orders start firing. Does marketposition read the order status of IB back ?

Thanks

User avatar
Stanley Miller
Posts: 556
Joined: 26 Jul 2005
Has thanked: 3 times

Re: Auto Trader

Postby Stanley Miller » 10 Apr 2007

Hi Kate,
shot I noticed you are using Buy Long and Sell Short commands.
I simply used Buy and Sell so that may be why I could not get marketposition to work correctly. I will try it and see.


Sell is exit long signal, it can't generate marketposition = -1

widgetman
Posts: 81
Joined: 11 Oct 2005

Postby widgetman » 10 Apr 2007

Hi Stanley,
I think I understand what you mean now. I still have a couple confusing issues maybe you can help with. If Sell Short is a short position entry, and Sell is a long cover, then why won't the script language accept a Buy Long for a new order. It seems I can only issue a Buy command for a cover or a new position.

This also presents a issue when I first turn on the script strategy. It assumes a marketposition of the last signal regardless of what position you have in your IB account. It this Auto trader is to be used as a order entry system in IB would it not make sense to actually look at what position is in IB first then set marketposition to that value initially ?
Your thoughts and comments would be greatly appreciated.
-Thanks

User avatar
Stanley Miller
Posts: 556
Joined: 26 Jul 2005
Has thanked: 3 times

Postby Stanley Miller » 10 Apr 2007

Hi Stanley,
I think I understand what you mean now. I still have a couple confusing issues maybe you can help with. If Sell Short is a short position entry, and Sell is a long cover, then why won't the script language accept a Buy Long for a new order. It seems I can only issue a Buy command for a cover or a new position.


There are 4 types of signals:

buy
sell
sell short
buy to cover

This also presents a issue when I first turn on the script strategy. It assumes a marketposition of the last signal regardless of what position you have in your IB account. It this Auto trader is to be used as a order entry system in IB would it not make sense to actually look at what position is in IB first then set marketposition to that value initially ?
Your thoughts and comments would be greatly appreciated.
-Thanks


MultiCharts always checks your current market position before order is sent. MC follows TS logic when sending orders.
So if you are ALREADY "1 Long" (before turning the system on) and:
Your strategy generates "1 Short" - then a Sell order for 2 (two) contracts will be generated;
Your strategy generates "1 Long" - then no orders will be generated (that is in case the pyramiding is not enabled).


Return to “MultiCharts”