Hello, Plot only draws a line of the last value in the pane and not previous values. What have I done wrong? Thank you.
_SECTION_BEGIN("My Kelly ");
longonly = True;
kap = 1000;
//lookback
lookback = 54;
// Die Kelly-Zahl wird nur auf Basis der Lookback-Bars berechnet
if (lookback > 0)
{
numwin = 0;
numlose = 0;
win = 0;
lose = 0;
sumwin = 0;
sumlose = 0;
avwin = 0;
avlose = 0;
riskpercent = 0;
percentwin = 0;
riskpercent = 0;
sharestohold = 0;
// Berechnung der Gewinn- und Verlustwahrscheinlichkeit sowie des durchschn. Gewinns und Verlusts
for (i = 0; i < lookback - 1; i++)
{
if ((C[i] - C[i + 1]) > 0) // Gewinn
{
numwin = numwin + 1;
win = C[i] - C[i + 1];
sumwin = sumwin + win;
printf("A: %g, %g, %g\n", numwin, win, sumwin);
}
if (numwin != 0)
avwin = sumwin / numwin;
else avwin = 0;
if ((C[i] - C[i + 1]) <= 0) // Verlust
{
numlose = numlose + 1;
lose = -1 * (C[i] - C[i + 1]);
sumlose = sumlose + lose;
printf("B: %g, %g, %g\n", numlose, lose, sumlose);
}
if (numlose != 0)
avlose = sumlose / numlose;
else
avlose = 0;
printf("C: %g\n", avlose);
}
percentwin = numwin / lookback; // Prozentsatz steigender Bars
printf("D: %g\n", percentwin);
printf("avwin: %g\n", avwin);
if ((avlose AND avwin) != 0)
riskpercent = (percentwin - ((1 - percentwin) / (avwin / avlose)));
else
riskpercent = 0; // Kelly Formel
printf("E: %g\n", riskpercent);
// Berechnung der Aktienanzahl für das definierte Risikokapital
if (avlose > 0)
{
sharestohold = ceil(kap * riskpercent / avlose);
printf("K: %g\n", sharestohold);
}
ind1 = sharestohold;
ind2 = 100*riskpercent;
ind3 = avlose*numlose;
ind4 = avwin*numwin;
ChartType = ParamList("Chart Type", "SharesToHold|KellyPercent|Lose/Win"); //
if (ChartType == "SharesToHold") //
{
Plot(ind1, "SharesToHold", colorWhite, styleLine );
}
if (ChartType == "KellyPercent") //
{
Plot(ind2, "KellyPercent", colorAqua, styleLine );
}
if (ChartType == "Lose/Win") //
{
Plot(ind3, "%lose*avglose", colorRed, styleLine );
Plot(ind4, "%win*avgwin", colorGreen, styleLine );
}
}