Today, I experienced the first "fatal error" of MC in autotrading which executed TWO sell orders within a minute. This is supposed to be "selling X contracts" to close a position of X contracts before market closing, but MC executed it twice resulting a short position. Fortunately, I sit in front of the computer and close the short position manually.
DOES ANYONE EXPERIENCE SIMILAR THING LIKE WHAT I DO?
I am thinking to code a "precautionary strategy" to check the position every bar, version the position that it should be as hown in the MC chart. Close "over" positions when it detects that; and buy / sell short additional contracts to match the position as it should be.
But I don't know how to start the code..... any input and perhaps someone may have coded it already!!??
Over / Under Trading When Autotrading with MC
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Dear Spaceant,
You can write such "precautionary strategy" by means of EasyLanguage. Basically, you need to compare the marketposition and MarketPosition_at_Broker values to compare the actual position at the broker with the position shown on the chart. To do what you want you need to make sure that marketposition and MarketPosition_at_Broker values are the same.
You can write such "precautionary strategy" by means of EasyLanguage. Basically, you need to compare the marketposition and MarketPosition_at_Broker values to compare the actual position at the broker with the position shown on the chart. To do what you want you need to make sure that marketposition and MarketPosition_at_Broker values are the same.
Re: Over / Under Trading When Autotrading with MC
Spaceant, what type of sell order are you using? If you just want to cover your longs say "sell all contracts". better still, if you don't know or don't care whether you are short, long or flat, and you want to cover everything regardless then say:
sell all contracts;
buytocover all contracts;
Either one or the other or neither will be executed depending on your market position. It does no harm to have both commands.
sell all contracts;
buytocover all contracts;
Either one or the other or neither will be executed depending on your market position. It does no harm to have both commands.
The one that I experienced was something strange:
marketposition = 0 ;
MarketPosition_at_Broker = -3 ;
MarketPosition_at_Broker_for_The_Strategy = 0;
I have tested it today using "buy to cover", but it didn't work as marketposition is zero!! Perhaps, I should use "Buy" to forcefully close the position....... will test
marketposition = 0 ;
MarketPosition_at_Broker = -3 ;
MarketPosition_at_Broker_for_The_Strategy = 0;
I have tested it today using "buy to cover", but it didn't work as marketposition is zero!! Perhaps, I should use "Buy" to forcefully close the position....... will test
It works!The one that I experienced was something strange:
marketposition = 0 ;
MarketPosition_at_Broker = -3 ;
MarketPosition_at_Broker_for_The_Strategy = 0;
I have tested it today using "buy to cover", but it didn't work as marketposition is zero!! Perhaps, I should use "Buy" to forcefully close the position....... will test
For another case:
marketposition = 1 ;
MarketPosition_at_Broker = 0 ;
MarketPosition_at_Broker_for_The_Strategy = 3;
The MarketPosition_at_broker should be 3. Due to whatever reason, no position has been entered, I have tried to code this situation and others in a precautionary strategy:
I have tested MP=0 while there is a +ve / -ve position, in which the code works. BUT, it doesn't seem working for MP=1 or -1Inputs:Opt(1);
Vars: MP(0),MP_At_Bk(0),MP_For_S(0),MP_Chk(0),Diff(0),AbsQty(0);
MP=marketposition;
MP_At_Bk=MarketPosition_at_Broker;
MP_For_S=MarketPosition_at_Broker_for_The_Strategy;
MP_Chk=marketposition_checked;
Diff=MP_At_Bk - MP_For_S;
AbsQty=absvalue(Diff);
If Diff<>0 then begin
If MP=1 then begin
If Diff>0 then Sell ("LX-Chk") Diff contracts next bar at market;
If Diff<0 then Buy ("LE-Chk") AbsQty contracts next bar at market;
End; {MP=1}
If MP=-1 then begin
If Diff>0 then Sell Short ("SE-Chk") Diff contracts next bar at market;
If Diff<0 then Buy to Cover ("SX-Chk") AbsQty contracts next bar at market;
End; {MP=-1}
If MP=0 then begin
If Diff>0 then Sell Short ("LX(0)-Chk") Diff contracts next bar at market;
If Diff<0 then Buy ("SX(0)-Chk") AbsQty contracts next bar at market;
End; {MP=0}
End; {Diff}
Can anyone tell me what has been wrong?
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Dear Spaceant,
This code should make the position at broker the same as it is on the chart:
This code should make the position at broker the same as it is on the chart:
Code: Select all
Inputs:Opt(1);
Vars: MP(0),MP_At_Bk(0),Diff(0),AbsQty(0);
MP = MarketPosition * CurrentContracts;
MP_At_Bk = MarketPosition_at_Broker;
Diff = MP_At_Bk - MP;
AbsQty = Absvalue(Diff);
If (GetAppInfo(aistrategyauto) = 1) and (GetAppInfo(airealtimecalc) = 1) and (Diff<>0) then begin
If Diff>0 then PlaceMarketOrder(False, True, AbsQty);
If Diff<0 then PlaceMarketOrder(True, True, AbsQty);
End; {Diff}
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Dave, some questions on this supposedly new feature.
1. Why was PlaceMarketOrder introduced?
2. I presume none of the standard orders will know about any open orders generated by PlaceMarketOrder, including the "sell all contracts" and "buytocover all contracts" to cover all open positions regardless of whether the situation is long, short or flat. Correct?
3. If the answer to 2 is yes, are there equivalents to "sell all contracts" and "buytocover all contracts"?
1. Why was PlaceMarketOrder introduced?
2. I presume none of the standard orders will know about any open orders generated by PlaceMarketOrder, including the "sell all contracts" and "buytocover all contracts" to cover all open positions regardless of whether the situation is long, short or flat. Correct?
3. If the answer to 2 is yes, are there equivalents to "sell all contracts" and "buytocover all contracts"?
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times