Hi,
I am looking for a afl code which can give a buy signal on cross of a signal candle.
if candle has closed above "super trend 10,3"
and prices have crossed the high of signal candle.
Thank you.
Hi,
I am looking for a afl code which can give a buy signal on cross of a signal candle.
if candle has closed above "super trend 10,3"
and prices have crossed the high of signal candle.
Thank you.
Would you like to have a cup of tea and a piece of cake while waiting for copy&paste ready code? Please take a seat... our front desk lady will be right back to you taking very special care of you.
Most importantly the requested code will arrive in app. 30 minutes via hyper optimized carrier pigeons service.
Sincerely yours
THE AB SPECIAL FORCES
@yogi, you have not told us how you define the "signal bar", so there's really no way for anyone here to give you a complete solution. And the point @fxshrat is humorously making is that members of this forum tend to look favorably upon those who have at least attempted to solve their own problems, and when they get stuck, ask very well-defined questions. In other words, this is not the place to come to if you're just expecting someone else to do all the work for you. That's what paid contractors are for.
With all that in mind, the code below should at least get you closer to your desired solution. It does not take into account the signal bar, so you will need to work that out on your own, or ask better questions so that others can help you.
function SuperTrend(lenATR, width)
{
nATR = ATR(lenATR);
pAvg = (H+L) / 2;
upperBand = pAvg + width * nATR;
lowerBand = pAvg - width * nATR;
isUpTrend = True;
dn = DateNum();
for (i=lenATR; i<BarCount; ++i)
{
if (C[i] > upperBand[i-1])
isUpTrend[i] = True;
else if (C[i] < lowerBand[i-1])
isUpTrend[i] = False;
else
isUpTrend[i] = isUpTrend[i-1];
if (isUpTrend[i])
lowerBand[i] = Max(lowerBand[i], lowerBand[i-1]);
else
upperBand[i] = Min(upperBand[i], upperBand[i-1]);
}
super = IIf(isUpTrend, lowerBand, upperBand);
return super;
}
Buy = C > SuperTrend(10,3);
Thanks for your help...
I tried plotting it on the chart by adding below code
Plot(SuperTrend,"STOP",IIf(C>SuperTrend,colorBrightGreen,colorRed),styleDots|styleStaircase|styleThick );
however, i am getting "Error 31."
if you can please help on the above.
Thank you.
AmiBroker is telling you what the problem is, and where to find it. Here is the error text:
Plot(SuperTrend
-------------^
File: [your file name with line and column number]
Error 31
Syntax error, unexpected ",", expecting "("
SuperTrend is a function. To reference it, you have to add parentheses and parameters, just like with every other function in AmiBroker. For convenience and efficiency, you could assign the array returned by the SuperTrend() function to a variable so that the function is called only one time, rather than once for every time you reference the SuperTrend array. For example:
st = SuperTrend(10,3);
Buy = C > st;
Plot(st, "STOP", IIf(C>st,colorBrightGreen,colorRed),styleDots|styleStaircase|styleThick);
And really, please spend some time with the extensive AmiBroker documentation and tutorials and/or invest in some training.
Sir,
I have been trying code to buy above High of the signal candle, but valuewhen function allows buyprice to be within the range of H AND L of singnal candle, I will be glad if I get correction function for this action, I tried following code
`// Desired Buy Stop Price
P_HIGH = Ref(H,-1);
P_HIGHPRICE = P_HIGH +0.10;
C_HIPRICE = Ref(H,0) + 0.10;
D_PRICE = IIf(P_HIGHPRICE>C_HIPRICE,P_HIGHPRICE,C_HIPRICE);
BuyPrice = ValueWhen(Buy,D_PRICE);`
For posting questions on the forum, you are required to get "Verified". Please search for "Verified" or "Verified Badge" and follow the steps.
Additionally, when you are posting code, please use the CODE BLOCKS ("</>").
See how-to-use-this-site.