I'm trying to implement a calulation which is useful in backtest an replay mode too.
Using the primary bars as daily and a secondary as 5min, I'm like to calculate the major logic on daily bars and the final desicion on how to react (alerting or something like this), has to be in the last minutes before the sessions ends...
Here is my implementation for OnBarUpdate:
protected override void OnBarUpdate()
{
if(CurrentBars[0] < PeriodSlow || CurrentBars[1] < PeriodSlow)
return;
EMA200[0] = SMA(BarsArray[0], PeriodSlow)[0];
var percentB2 = PercentB(BarsArray[0][2], Bollinger(Deviation, PeriodBollinger).Lower[2], Bollinger(Deviation, PeriodBollinger).Upper[2]);
var percentB1 = PercentB(BarsArray[0][1], Bollinger(Deviation, PeriodBollinger).Lower[1], Bollinger(Deviation, PeriodBollinger).Upper[1]);
var percentB0 = PercentB(BarsArray[0][0], Bollinger(Deviation, PeriodBollinger).Lower[0], Bollinger(Deviation, PeriodBollinger).Upper[0]);
// Update from the 5min Bars
if(BarsInProgress == 1)
{
if(ToTime(Times[1][0]) >= ToTime(21,50,00))
{
// long
if(Closes[0][0] > EMA200[0] && !_enteredLong)
{
if(percentB0 < 0.2 && percentB1 < 0.2 && percentB2 < 0.2)
{
EntryBuy[0] = Close[0];
_enteredLong = true;
}
}
// long agressive
if(_enteredLong && !_aggressiveLong && percentB0 < 0.2)
{
EntryBuy[0] = Close[0];
_aggressiveLong = true;
}
// close all long positions
if(_enteredLong && percentB0 > 0.8)
{
_aggressiveLong = false;
_enteredLong = false;
Print("Exit agressive longs");
}
}
}
The hint is, that a minimum of 200 days is needed to calulate the SMA, so the indicators need to wait until these 200 days AND 200 * 480 5 minute bars are loaded...
Is there any way to speed up this? Or is something wrong with my implementation?
The preferred usage of this indicator is for market analysing, not necessarely on charts.
Hope someone can help me :-)
Thx for your ideas and have a nice weekend.
Cheers Markus
Comment