Issue to define additional entries dependant on the first entry

Hello everyone.

I've been facing an issue to implement scaling to my system. The system consists of buying a certain TICKER conditioned to a Bollinger Breakout entry signal and scale in up to two additional entries, which depend on the value of the first entry. The first entry is the breakout of a BBandBot(C,20,2) and two remaining entries would be nothing more than the breakout of BBandBot(?,20,3) and BBandBot(?,20,4), but considering the value of the first entry and not de CLOSE value of the bar. I don't know how to store the first entry value to make these two additional entries dependant on it.

Find my code below:

SetOption( "InitialEquity", 20000 );
MaxPos = 5;
SetOption( "MaxOpenPositions", MaxPos );


SellPrice =MA(C,20);

//Buy = ExRem( Buy, Sell );  //  clear out excesive signals, if we are already bought
//Sell = ExRem( Sell, Buy ); //  clear out excesive signals, if we are already sold



Any help or comments are appreciated.

Not a complete answer:
Normally things like scale in are handled by the backtest engine but if you want to do it on the chart you could try...
FirstBuyPrice = ValueWhen( Buy, BuyPrice ); hold that entry price for the scale in calculations.

@rdcamaral are you trying to backtest or trying to achieve it in a live system ?

Thanks for the suggestion. I've found a topic here at the forum describing the scale in with mutliple criteria. Using the command you suggested I achieved what I wanted.

Many thanks!

I'm trying to backtest for instance. Wih @JohnHT answer and some otther piece of code I was able to solve the issue.

oh well good. Do share your findings and the link(s) here so that it may help someone in the future if he/she ever came across it.

Oh yeah, for sure. The scale in procedure I've adopted something very similar to this discussion:

[Scale-In / Scale-Out : How to implement in AmiBroker Auto-Trading like IB or the other auto-trading platform]

For future reference, find below my code mixing the solution John has suggested with the one presented at the topic above:

FirstEntry = BuySignal1;
InFirstPos = Flip(FirstEntry, Sell);
FirstTrigger = ExRem(InFirstPos, Sell);
BarsSinceFirstTrigger = BarsSince(FirstTrigger);
FirstTriggerPrice = IIf(BarsSinceFirstTrigger < BarsSinceSell, Ref(BI,-1), 0 );

Buy = ExRem( Buy, Sell );  //  clear out excesive signals, if we are already bought
Sell = ExRem( Sell, Buy ); //  clear out excesive signals, if we are already sold

PE = ValueWhen( Buy, Ref(BI,-1)); //entry price



SecondEntry = BuySignal2 AND InFirstPos AND Ref(InFirstPos,-1);
InSecondPos = Flip(SecondEntry, Sell);
SecondTrigger = ExRem(InSecondPos, Sell);
BarsSinceSecondTrigger = BarsSince(SecondTrigger);
SecondTriggerPrice =IIf(BarsSinceSecondTrigger < BarsSinceSell, Ref(SegundaEntrada,-BarsSinceSecondTrigger), 0 );


ThirdEntry = BuySignal3 AND InSecondPos AND Ref(InSecondPos,-1);
InThirdPos = Flip(ThirdEntry, Sell);
ThirdTrigger = ExRem(InThirdPos, Sell);
BarsSinceThirdTrigger = BarsSince(ThirdTrigger);
ThirdTriggerPrice = IIf(BarsSinceThirdTrigger < BarsSinceSell, Ref(TerceiraEntrada,-BarsSinceThirdTrigger), 0);

Buy = IIf( FirstTrigger, 1, IIf( SecondTrigger OR ThirdTrigger, sigScaleIn, 0  ) );

BuyPrice = IIf( FirstTrigger, Ref(PE,0),IIf( SecondTrigger , Ref(SE,0),Ref(TE,0)));

Sell = ExRem(Sell,Buy);

Filter=FirstTrigger or SecondTrigger or ThirdTrigger or Sell;