Capital does not change with trades being closed?

Posted By: Hredot

Capital does not change with trades being closed? - 09/27/17 16:01

I put

Code:
if(is(INITRUN)) {
    Capital = 5000;    // starting capital
}



at the top of my run() routine.
The strategy then performs trades and closes trades with profits and losses. But for some reason the Capital and CapitalClosed variables do not get updated properly:



While CapitalClosed registers some loss at the beginning it then just stops registering the other trade results. And Capital just never gets updated.

Am I doing something wrong? Should I include more commands to make these quantities properly track the current state of affairs?

Thanks for any suggestion!
Posted By: AndrewAMD

Re: Capital does not change with trades being closed? - 09/27/17 17:54

You are reading input values and expecting an output. laugh You don't even need to say if(is(INITRUN)) - it makes no difference.

Here's how to get it done:
Code:
plot("Sim Balance",(Capital + WinTotal - LossTotal),NEW,RED);

Bon appétit.
Posted By: Hredot

Re: Capital does not change with trades being closed? - 09/27/17 20:28

Oh... Thanks for the answer, but now I am a bit confused.
In the portfolio management section of the tutorial the variables Capital and ProfitClosed are used to determine how much to reinvest at any given time. If these variables are actually supposed to be input only and therefore always constant, how to reconcile this with the tutorial?
Posted By: AndrewAMD

Re: Capital does not change with trades being closed? - 09/27/17 20:40

In the opening post, you said "CapitalClosed". I don't think this is a real variable.

Capital is an input.

And here's a really good code snippet:
Code:
// reinvest the square root of your portfolio component profits, separately for long and short trades
if(GoLong) 
  Margin = OptimalFLong * Capital * sqrt(1 + (WinLong-LossLong)/Capital);else
  Margin = OptimalFShort * Capital * sqrt(1 + (WinShort-LossShort)/Capital); 
// reinvest the square root of your portfolio component profits
Margin = OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital); 
// reinvest the square root of your total profits
Margin = OptimalFLong * Capital * sqrt(1 + (WinTotal-LossTotal)/Capital);



Source: http://www.zorro-trader.com/manual/en/optimalf.htm
Posted By: Hredot

Re: Capital does not change with trades being closed? - 09/27/17 21:12

Oh, I typed it wrong in the forum, but I meant profitClosed, sorry about that.
Indeed, that code snippet is what I was looking for, thanks for pointing it out!
© 2024 lite-C Forums