Counting Buy signals to calculate a average Buy price

The initial idea was because I didn't want to eliminate the buy signal by ExRem, but when stochastic returned golden cross, buy signal came out, then I wanted to calculate the average buy price.
The following is the one I have made, but I want to prepare for more than 3 times the average price. I really need help from the experts here..

Title = "";
SetChartBkColor(ParamColor("Color", colorCustom1)); 
SetChartOptions(0, chartShowDates);

CandleColor = IIf(C >= Ref(C,-1), colorBlue, colorRed);
PlotOHLC(O, H, L, C, "Candle",CandleColor,styleCandle,10);

VolColor = IIf(V >= Ref(V,-1), colorBlue, colorRed);
PlotOHLC(0, V, 0, V, "V", VolColor,styleOwnScale|styleHistogram,5,0,0,0,2);

//= Stochastic 
STochL = LLV(L,6);
STochH = HHV(H,5);

LnStochK = ((C-STochL)/(STochH-STochL)) * 100;
LnStochK1 = Ref(LnStochK,-1);
LnStochK2 = Ref(LnStochK,-2);
AvgStochK3 = (LnStochK+LnStochK1+LnStochK2)/3;
LnStochD = LnStochK*(2/(3+1))+AvgStochK3*(1-(2/(3+1)));


STochGC = Cross(LnStochK,LnStochD) AND LnStochK <= LOSSTOCH;
STochDC = Cross(LnStochD,LnStochK) AND OBStoch;
PlotShapes(IIf(STochGC, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-45);
PlotShapes(IIf(STochDC, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);

ExBSign = ExRem(STochGC,STochDC);
ExSSign = ExRem(STochDC,STochGC);
ExSSign1 = Ref(ExSSign,-1);

FlipBSign = Flip(STochGC,STochDC);
FlipSSign = Flip(STochDC,STochGC);
FlipSSign1 = Ref(FlipSSign,-1);


BP1x = ValueWhen(STochGC AND ExBSign AND FlipSSign1,C);
BP2x = ValueWhen(STochGC AND FlipBSign,C);

BP1T = "Buy 1 = " + WriteVal(BP1x,1.0);
BP2T = "Buy 2 = " + WriteVal(BP2x,1.0);

AVGP1 = IIf(FlipSSign,0,(BP1x+BP2x)/2);
AVGP1T = "Average Buy Price = " + WriteVal(AVGP1,1.0);

//= Layout 
GfxSelectFont("Arial",10, 700);
GfxTextOut("" + BP1T, 5, 50);
GfxTextOut("" + BP2T, 5, 65);
GfxTextOut("" + AVGP1T, 5, 90);


Thank you in advance..

@Viery, what do you mean by:

Please see the following post for an example of how to describe what you want to achieve:

@phase21 , I'm so sorry I can't respond to your advice, because my laptop is broken, so I replace my laptop but I didn't know how to log in here until yesterday I was create a new user account and @Tomasz gave me a clue.

For my previous problem was solved by only giving 1 signal without having to make multiple buy signal.

But I have a new problem and maybe I should create a new topic because the problem is different.

@Tomasz, I am grateful if you close this topic.

Many Thanks for all of your kindness