Hello,
Are there any ways to get or calculate a total market exposure for current broker account (like Portfolio InvestedCapital but I can’t use Portfolio Trader)? I mean the amount of cash invested in securities in my broker account on the moment of strategy calculation regardless whether Orders generated by the strategies on different charts in the workspace or created manually.
Tried to find out how to do it by using TradeManager but have the following challenges:
- AvailableToTrade property of Account struct seems not supported by my broker but can get account balance and use it as a baseline
- Position struct has AvgPrice property but there is no Quantity property. And also it's not clear how to distinguish whether it’s open position or not
- Order struct has both ExecPrice and FilledContracts properties but struggling to understand what exactly ETM_OrderState statuses are related to currently Open orders
Any help is very much appreciated,
Thanks
Calculating Account Market Exposure
- Tammy MultiCharts
- Posts: 200
- Joined: 06 Aug 2020
- Has thanked: 6 times
- Been thanked: 65 times
Re: Calculating Account Market Exposure
Hello Vik,
Please have a look at the script sample below that might help you achieve your goal:
For example, if there are 2 positions open via manual trading, this code will print the following output:
P: OptPaperTrader, A: SIM 001, S: @AD#C, Pos: 2, AvgP: 0.7203, OPL: 28.1096275474319
P: OptPaperTrader, A: SIM 001, S: @BP#C, Pos: 1, AvgP: 1.2688, OPL: -35.1370344343029
Please have a look at the script sample below that might help you achieve your goal:
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
namespace PowerLanguage.Strategy
{
public class Trademanager2 : SignalObject
{
public Trademanager2(object _ctx) : base(_ctx) { }
public TradeManager.IPositions _openPosition;
protected override void Create(){}
protected override void StartCalc()
{
TradeManager.ProcessEvents();
_openPosition = TradeManager.TradingData.Positions;
}
protected override void CalcBar()
{
TradeManager.ProcessEvents();
for (int i = 0; i < _openPosition.Items.Count(); i++)
{
Output.WriteLine(_openPosition.Items[i].ToString());
}
Output.WriteLine(" ");
}
}
}
P: OptPaperTrader, A: SIM 001, S: @AD#C, Pos: 2, AvgP: 0.7203, OPL: 28.1096275474319
P: OptPaperTrader, A: SIM 001, S: @BP#C, Pos: 1, AvgP: 1.2688, OPL: -35.1370344343029