Good evening.
I'm trying to implement the scale in my strategy, I buy with PS and the scale in it will be triggered if the contract price is higher than 0.5 * ATR on the day it entered the BUY.
For example: Buy = U $ 11.00 and ATR of 0.50. If the price of the asset rises to 11.25, I call the scale in, recalculate the same method of PS, and pass the information to buy more contracts. I should now consider the entry price as 11.25 if it goes up 0.5 * ATR, that is, go to $ 11.50 the scale in is triggered again and so on.
I started thinking about low level implementation as follows, but there is something wrong with the code, you can give me a way to go, tips. Thank you !
SetOption("UseCustomBacktestProc", True );
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.PreProcess(); // Initialize backtester
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;
positionrisk = 0.01;
investi = ((100*positionrisk*CurEquity)/symbolATR[bar]*pos.PointValue);
investi1 = investi*pos.MarginDeposit;
if( price > (price1 + 0.1*symbolATR[0]));
{
bo.ScaleTrade( bar, pos.Symbol, investi > 0, price, investi1, MarginDeposit);
}
}
}
bo.PostProcess(); // Finalize backtester
}