Profile Picture

Single variable updated from each NewBar

Posted By johan 3 Years Ago
Message
Posted Friday July 25 2014
In a CFD portfolio, I have developed code to calculate a running daily actual equity, i.e. Equity per Open Position+=Profit/Loss of daily movement ((Today Close-YesterdayClose)*Size), as only the profit/loss is actual equity (and not the full open value). I calculate this daily profit/loss in NewBar. What I struggle with is to get a system wide equity position - typically I want to run something like this:

equity+=Equity per Open Position for 1st Open Position + Equity per Open Position for 2nd Open Position +...+Equity per Open Position for xth Open Position

Is there a way where I can run a method after all NewBars for the day have been executed, and add all the individual Equity per Open Position together?

Thanks for the help.
Posted Friday July 25 2014
Is your above calculation in your symbol script class or your system class? Placing the calculation in your system class should get you what you need.
Posted Saturday July 26 2014
Thanks Duane. I think I have got it. I calculate my Total Equity in MySystem. I now want to pass this value back to MySymbolScript for calculating a position size. I am very new to C#, and am struggling to get this variable in the MySymbolScript class. hereby some code:

MySystem calculation:

public override void NewBar()
{
base.NewBar();
foreach (MySymbolScript position in SymbolScripts)
totalEquity += position.equity;
Console.WriteLine("Total Equity {0}", totalEquity);
}

I now want to use this totalEquity in NewBar() in MySymbolScript, but can't get it passed into MySymbolScript.

Thanks for your help.
Posted Saturday July 26 2014
I got it right - forgot to make variable static.
Posted Saturday July 26 2014
PositionManager.GetOpenPositions method is accessible via the system class so you don’t need to iterate your SymbolScripts to obtain the equity.

public override void NewBar()
{

foreach (var position in PositionManager.GetOpenPositions())
totalEquity += position.equity;
Console.WriteLine("Total Equity {0}", totalEquity);

}
Posted Friday August 01 2014
You don't have to make the variable static. You can make it an instance property on the trading system class, and get to the instance of the trading system class from your symbol scripts using the TradingSystem property. IE, from your symbol scripts you would do something like:

TradingSystem.TotalEquity += position.Equity;

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems