Simple Coding Help - No Promise.

Hi,
I want to ask question with a
lets say,
today is tuesday ..we seeing crude oil chart on 5 minute timeframe .. i only trade when there's shooting star.and there's no shooting star on 5 minute timeframe,( current timeframe that is on my chart) As per his rule he only trade when there's shooting star,but there's shooting star on 23 minute timeframe. but he don't know there's shooting star.

I need an afl , which can output timeframe of candle pattern.

I simplied question, i guess it's clear.

shootingstar = (((H-L)>4*(O-C)) AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75));

Thank you
 

ethan hunt

Well-Known Member
Need an AFL with following conditions for Backtesting:

Rule 1 = if(X ROC > D% and X ROC > Y ROC) = BUY X

Rule 2 = if(X ROC < D% and Y ROC < D%) = CLOSE/EXIT POSITION = NO POSITION

Rule 3 = if(Y ROC > D% and Y ROC > X ROC) = BUY Y

ROC & D% can be changed from Parameter.

To be used for backtesting of 2 stocks X & Y from watchlist containing only these 2 stocks.
 
You need 3 loops; code will be something like this

function LkBk( array,n )
{
// initialize
for( i = 0; i < n; i++ )
{
result[ i ] = array[ i ];
}

for( i = n; i < BarCount; i++ )
{
result[ i ] = 1;
for (j = n; j > 0; j--)
{
result[ i ] = result[ i ] AND Ref(array, j - i)>Ref(array,j-i-1)
}

}
return result;
}

You will have to do your own testing.... However, chances that all elements of result will be zero is very high because all that is needed is one element in which previous element is not less than current element.
 
Last edited:
HTML:
ND = Day() != Ref(Day(), -1);

///// VWAP and SDs /////

P = (H + L) / 2;
VWP = P * V;
BI = BarIndex();
BeginBI = ValueWhen(ND, BI);
BeginBI = BeginBI[BarCount -1];
if(BeginBI < BarCount - 1)
	{
	InRange = BI >= BeginBI;
	CumV = Cum(V * InRange);
	CumVWP = Cum(VWP * InRange);
	VWAP = CumVWP / CumV;
	S = Cum(Ref(CumV, -1) * V * (P - Ref(VWAP, -1))^2 / CumV);
	Variance = S / CumV;
	SD = sqrt(Variance);
	VWAP = IIf(InRange, VWAP, Null);
	Plot(VWAP, "VWAP", colorYellow, styleNoTitle + styleNoRescale);
	Plot(VWAP + SD, "+1SD", colorGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - SD, "-1SD", colorRed, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP + 2*SD, "+2SD", colorSeaGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - 2*SD, "-2SD", colorOrange, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP + 3*SD, "+3SD", colorPaleGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - 3*SD, "-3SD", colorLightOrange, styleDashed + styleNoTitle + styleNoRescale);
	}

///// PVP /////

BarSinceND = BarsSince(ND);
iStart = Max(BarCount - 1 - BarSinceND[BarCount - 1], 0);
Top = HighestSince(ND, High);
Bot = LowestSince(ND, Low);
Range = Top - Bot;
BoxesInRange = Range / TickSize + 1;
VolUnit = Volume / ((High - Low) / TickSize + 1);
VUcount = 0;
MaxVUcount = 0;
PVP = Null;

if(iStart > 0)
{
for(i = iStart; i < BarCount; i++)
	{
	jShift = round((Bot[i - 1] - Low[i]) / TickSize);
	if((BoxesInRange[i] < BarCount))
		{
		if(jShift > 0)
			{
			LastVUcount = VUcount;
			VUcount = 0;
			for(j = jShift; j < BoxesInRange[i]; j++)
				{
				VUCount[j] = LastVUCount[j - jShift];
				}
			}
		jStart = round((Low[i] - Bot[i]) / TickSize);
		jEnd = round((High[i] - Bot[i]) / TickSize);
		for(j = jStart; j <= jEnd; j++)
			{
			VUcount[j] = VUcount[j] + VolUnit[i];
			MaxVUcount = Max(MaxVUcount, VUcount[j]);
			}
		}
	}
for(j = 0; j < BoxesInRange[BarCount - 1]; j++)
	{
	if(MaxVUcount == VUcount[j])
		PVP = Bot[BarCount - 1] + j * TickSize;
	}
Plot(PVP, "PVP", colorTurquoise, styleDots + styleNoTitle + styleNoRescale);
}
can someone please see this code. found in traderslaboratory. not plotting anything.
Sent code to amibroker support. Their reply:

Hello,

Thank you very much for your e-mail.

When calling array[ bar ] - you must always check whether ‘bar’ ís between 0 and Barcount-1 range.

See this preliminary version of KB article for additional details.

----------------------

Avoid hard-coding fixed bar numbers when using subscript operator.


AFL allows to refer to individual array elements with subscript operator, i.e. array[ bar ]. The bar numbers we can use are between 0 and Barcount-1, therefore in order to get the first bar we use array[ 0 ], to get the last bar of array you can use array[ BarCount - 1 ];

BarCount variable returns number of bars currently loaded by AFL engine and when using subscript operator we should always check if we are using values between 0 and Barcount-1. That’s because QuickAFL engine will dynamically adjust number of loaded bars and AmiBroker does not load full history of quotes.

Actually afl shows error Subscript out of range.


So, please help me out not able to correct it.
 
You need 3 loops; code will be something like this

function LkBk( array,n )
{
// initialize
for( i = 0; i < n; i++ )
{
result[ i ] = array[ i ];
}

for( i = n; i < BarCount; i++ )
{
result[ i ] = 1;
for (j = n; j > 0; j--)
{
result[ i ] = result[ i ] AND Ref(array, j - i)>Ref(array,j-i-1)
}

}
return result;
}

You will have to do your own testing.... However, chances that all elements of result will be zero is very high because all that is needed is one element in which previous element is not less than current element.
Spot on!!!, tnx a zillion mstrmnd007
lovvy
 
Hi,
I want to ask question with a
lets say,
today is tuesday ..we seeing crude oil chart on 5 minute timeframe .. i only trade when there's shooting star.and there's no shooting star on 5 minute timeframe,( current timeframe that is on my chart) As per his rule he only trade when there's shooting star,but there's shooting star on 23 minute timeframe. but he don't know there's shooting star.

I need an afl , which can output timeframe of candle pattern.

I simplied question, i guess it's clear.

shootingstar = (((H-L)>4*(O-C)) AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75));

Thank you
Hi,
Can somebody guide me ?
Thank you
 
I need urgent help and I will be very grateful if some expert generously gives some time to better this afl. I had made this request earlier too. But unfortunately i cudn't get a reply.
This is a simple Tom DeMark Trendline afl. It draws trendline connecting two recent fractals starting from right. I have used it on intraday chart. It draws the best trendline. But it is bad afl because it is too memory intensive and many a times Amibroker gets stucks when it is loaded. Perhaps it is due to "For" loop. Is there a way to avoid For Loop in the following code and make it better?

// TomDemark Fractal Trendline
percent = Param("Perbent", 0.05, 0.01, 10 );
firstpointL = 2;
firstpointH = 2;
y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));
for( i = 1; i < BarCount AND y0 >= y1; i++ )
{
firstpointL++;
y0=LastValue(Trough(L,percent,firstpointL));
}

x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );


yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));

for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{
firstpointH++;
yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );
Plot( LineL, " Support", colorBrown,1 +8 + 4096);
Plot( LineH, "Resistance", colorGreen,1 + 8 + 4096);
 

jagankris

Well-Known Member
I need urgent help and I will be very grateful if some expert generously gives some time to better this afl. I had made this request earlier too. But unfortunately i cudn't get a reply.
This is a simple Tom DeMark Trendline afl. It draws trendline connecting two recent fractals starting from right. I have used it on intraday chart. It draws the best trendline. But it is bad afl because it is too memory intensive and many a times Amibroker gets stucks when it is loaded. Perhaps it is due to "For" loop. Is there a way to avoid For Loop in the following code and make it better?
Nope it is not possible.
 

Similar threads