While looking at the recently added Accounts & Positions reserved words, I was wondering whether it was possible to get the initial margin and the maintenance margin from the broker?
I think it would be handy to be able to access these values, since certain brokers (like IB) don't have a fixed intraday margin value of x dollar, so it would be helpful if the strategy can check the required margin for the instrument before placing an automated trade.
[AutoTrading] How to get initial margin & maintenance margin
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: [AutoTrading] How to get initial margin & maintenance ma
Hello Josh,
Unfortunately that is not possible to get the initial margin and the maintenance margin from the broker with the help of PowerLanguage Editor at the moment.
Unfortunately that is not possible to get the initial margin and the maintenance margin from the broker with the help of PowerLanguage Editor at the moment.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: [AutoTrading] How to get initial margin & maintenance ma
Thanks Henry.
I saw that Martin already made a similar feature request for this (thanks Martin ).
Please vote!
I saw that Martin already made a similar feature request for this (thanks Martin ).
Please vote!
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: [AutoTrading] How to get initial margin & maintenance margin
Margin? That thing traders use which most determines their risk of ruin?
If you're going to dream then dream big. Since you are unlikely to get those PowerLanguage keywords ever; why not submit a new request to have the current margin of your choice automatically filled in to the QuoteManager field when you connect to the symbol? Make it update automatically. That's how trading execution platforms should work. Then you would just use the already available Margin keyword.
But I'll vote for your small dream too.
If you're going to dream then dream big. Since you are unlikely to get those PowerLanguage keywords ever; why not submit a new request to have the current margin of your choice automatically filled in to the QuoteManager field when you connect to the symbol? Make it update automatically. That's how trading execution platforms should work. Then you would just use the already available Margin keyword.
But I'll vote for your small dream too.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: [AutoTrading] How to get initial margin & maintenance margin
I'm not sure. The feature request says it's released, but I don't see what the PowerLanguage keyword/function would be.Bump. Was this ability ever added?
Perhaps with `GetRTAccountNetWorth()`? The help page isn't that descriptive and can't test so don't know for sure.
Re: [AutoTrading] How to get initial margin & maintenance margin
I've thought of a solution available to some people, requiring the ability to simultaneously trade real and paper.
Have a paper strategy enter a position however often the margin changes. Use the existing commands to find out the initial and maintenance margin. Then pass that info to the real-money strategy.
Have a paper strategy enter a position however often the margin changes. Use the existing commands to find out the initial and maintenance margin. Then pass that info to the real-money strategy.
Re: [AutoTrading] How to get initial margin & maintenance margin
Here's what I've been doing to successfully auto-update the margin. In the same PT portfolio as my trading strategy, I run the following strategy in parallel on the same instrument:
That strategy is trading on the paper profile. I created a custom session in QM just for it, starting at the instrument's session open (which is when the margin changes) and ending very shortly thereafter. All it needs to do is enter one position a day, find out the margin and then exit. The rest of the day it can be asleep. The next day, since the date has changed, the flags are reset and the condition for entry is again be satisfied.
My trading strategy then uses pmm_get_global_named_num("init") to grab the initial margin from the paper strategy. My broker is IB, whose maintenance margin is always 80% of the initial margin, so my code above only pulls the initial margin.
If you want to use that signal, you have to find out the number to enter into the "acctCode" input, corresponding to whichever paper account you want to trade with. You can find it out with a paper test:
Code: Select all
[AllowSendOrdersAlways = False]
input: acctCode(2);
vars:
intrabarpersist LBOC(false),
intrabarpersist sentEntry(false),
intrabarpersist sentExit(false),
intrabarpersist prevdate(0);
LBOC = LBOC or (LastBarOnChart_s and date=currentdate);
if LBOC then begin
if date>prevdate then begin
sentEntry = false;
sentExit = false;
prevdate = date;
end;
if (sentExit=false) and MarketPosition_at_Broker=0 and (barstatus=2 or sentEntry)
and strtonum(tm_account_str_value2(acctCode,"Net Liquidation")) = tm_account_num_value(acctCode, 1001)
then begin
sentEntry = true;
buy 1 contract this bar close;
end else if MarketPosition_at_Broker_for_The_Strategy>0 then begin
pmm_set_global_named_num("init",strtonum(tm_account_str_value2(acctCode,"Margin")));
if (barstatus=2 or sentExit) then begin
sentExit = true;
sell all contracts this bar close;
end;
end;
end;
My trading strategy then uses pmm_get_global_named_num("init") to grab the initial margin from the paper strategy. My broker is IB, whose maintenance margin is always 80% of the initial margin, so my code above only pulls the initial margin.
If you want to use that signal, you have to find out the number to enter into the "acctCode" input, corresponding to whichever paper account you want to trade with. You can find it out with a paper test:
Code: Select all
for value1=1 to tm_accounts_count begin
if "DUxxxxx" = tm_account_str_value(value1, 2000) then print(file("..."), value1);
end;