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
Auto Trader
MarketPosition Variable
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);
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);
- Stanley Miller
- Posts: 556
- Joined: 26 Jul 2005
- Has thanked: 3 times
Re: MarketPosition Variable
MarketPosition returns the correct values on my side, please see the attached screenshot. Which version of MultiCharts do you have?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);
Auto Trader
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.
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.
IB Order Status
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
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
- Stanley Miller
- Posts: 556
- Joined: 26 Jul 2005
- Has thanked: 3 times
Re: Auto Trader
Sell is exit long signal, it can't generate marketposition = -1Hi 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.
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
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
- Stanley Miller
- Posts: 556
- Joined: 26 Jul 2005
- Has thanked: 3 times
There are 4 types of signals: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.
buy
sell
sell short
buy to cover
MultiCharts always checks your current market position before order is sent. MC follows TS logic when sending orders.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
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).