# Amibroker - Position Pyramiding/Scaling In



## CTA (10 June 2015)

Hi,

Does anyone have code for pyramiding / scaling into positions based on ATR? I would like to e.g., add to an existing position if the price moves up 2ATRs from the initial entry price using the ATR at the time of trade entry.

I have check the SigScaleIn function from the Amibroker help website, but can't seem to be able to adapt this to the above.

Many thanks for your help!


----------



## 2Finn5 (20 June 2015)

CTA said:


> Hi,
> 
> Does anyone have code for pyramiding / scaling into positions based on ATR? I would like to e.g., add to an existing position if the price moves up 2ATRs from the initial entry price using the ATR at the time of trade entry.




I used this example code to do something similar:
http://www.amibroker.com/kb/2006/03/06/re-balancing-open-positions/

You'll need to store the ATR change since trade entry array as a static variable to access the data in the backtester.


----------



## Indiara (8 May 2018)

CTA said:


> Hi,
> 
> Does anyone have code for pyramiding / scaling into positions based on ATR? I would like to e.g., add to an existing position if the price moves up 2ATRs from the initial entry price using the ATR at the time of trade entry.
> 
> ...





Were you able to do this implementation? I need it.

Thanks.


----------



## Indiara (8 May 2018)

2Finn5 said:


> I used this example code to do something similar:
> http://www.amibroker.com/kb/2006/03/06/re-balancing-open-positions/
> 
> You'll need to store the ATR change since trade entry array as a static variable to access the data in the backtester.




I started to implement could you give me some hint? to complete?

for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
   {

    price = pos.GetPrice( bar, "C" );
    symbolATR = StaticVarGet( sig.Symbol + "ATR" );
    price1 = pos.EntryPrice;

    if( price1 > (price + 0.5*symbolATR));
    {
     bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, 10000, MarginDeposit);
    }
   }


----------



## Indiara (8 May 2018)

Here is a part of the code ..


  for(bar=0; bar < BarCount; bar++)
  {
   bo.ProcessTradeSignals( bar );

   //CurEquity = bo.Equity;

   for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
   {

    price = pos.GetPrice( bar, "C" );
    symbolATR = StaticVarGet( pos.Symbol + "ATR" );
    price1 = pos.EntryPrice;
    investi = -10;

    if( price > (price1 + 0.5*symbolATR[0]));
    {
     bo.ScaleTrade( bar, pos.Symbol, investi < 0, price, investi, MarginDeposit);
    }
   }
  }


----------

