Simple Coding Help - No Promise.

I think vijkris is saying right. In your AFL signal repaints (looks into future) that why you are getting signal late and if wrong signal generated it vanished after some bars.

PS: I am not an expert of AFL.:D

HAHA:clap::clap::clap::clap:

Thanks Ankur Bhai..I wont mind if some expert comment on this.

Pls guys dont mind. This is an awesome afl as per me. If it works as the way I want it.
 
No not ribbon.

I need diff background colours between 10 to 15, 15 to 20, 20 to 25, 25 to 40
those will be horizontal stripes of above specified width filled with diff colours.
let ADX condition can be anything. colours are fixed.
Nitin

Code for ribbon is practically same to code for coloring entire background. Last few parameters are present in ribbon to control the height. If you provide full range, ribbon will go over the entire screen.
 
HAHA:clap::clap::clap::clap:

Thanks Ankur Bhai..I wont mind if some expert comment on this.

Pls guys dont mind. This is an awesome afl as per me. If it works as the way I want it.
Had a look at the AFL posted by you. The limitation and problems you faced are part of the AFL and will continue to exist. To remove all that will need lots of modification.
 
Guys,

Can some one please help me with this:

The oscillator (code included below-Section-1) must use the ATP value from the second code (Section-2)

Section-1

HTML:
_SECTION_BEGIN("CYBER STOCH");
//==================================
//==================================
// 	From John Ehler's book     ===
// 	Rocket Science for Traders ===
//                     	     		===
// 	AFL By Robert Dunbar  	   ===
//==================================
//==================================

Arrows = ParamToggle( "Buy/Sell Arrows", "No|Yes", 1 );
alpha = Param( "Alpha", 0.07, 0.01, 0.4, 0.01, 0.01 );
Len = Param( "Length", 8, 1, 25, 1, 1 );
BullSig = BearSig = Trigger = Cycle = MaxCycle = MinCycle = Value1 = Value2 =
0;
PriceIn = ( ( H + L ) / 2 );

SmoothX = ( PriceIn + 2 * Ref( PriceIn, -1 ) + 2 * Ref( PriceIn, -2 ) + Ref(
PriceIn, -3 ) ) / 6;


for ( i = 6; i < BarCount; i++ )
{
    Cycle[i] = ( ( 1 - 0.5 * alpha ) ^ 2 ) * ( SmoothX[ i ] - 2 * SmoothX[ i - 1
] + SmoothX[ i - 2] ) + 2 * ( 1 - alpha ) * Cycle[ i - 1 ] - ( ( 1 - alpha ) ^ 2
) * Cycle[ i - 2 ];

    if ( i < 7 )
        Cycle[i] = ( PriceIn[i] - 2 * PriceIn[i-1] + PriceIn[i-2] ) / 4;
}

MaxCycle = HHV( Cycle, Len );

MinCycle = LLV( Cycle, Len );

Value1 = IIf( MaxCycle != MinCycle, ( Cycle - MinCycle ) / ( MaxCycle - MinCycle
), Value1 );

Value2 = ( 4 * Value1 + 3 * Ref( Value1, -1 ) + 2 * Ref( Value1, -2 ) + Ref(
Value1, -3 ) ) / 10;

Value2 = 2 * ( Value2 - 0.5 );

Trigger = ( 0.96 * ( Ref( Value2, -1 ) + 0.02 ) );

BullSig = IIf( Cross( Value2, Trigger ), True, False );
BearSig = IIf( Cross( Trigger, Value2 ), True, False );


Plot( Value2, "CyberCycle", colorLightBlue );
Plot( Trigger , "Trigger", colorRed );
Plot( 0 , "", colorWhite, styleDashed );

if ( Arrows )
{
    PlotShapes( shapeUpArrow*BullSig, colorBrightGreen );
    PlotShapes( shapeDownArrow*BearSig, colorRed );
}
_SECTION_END();
Section-2

HTML:
function ATP(a)
{
nd=Day() != Ref(Day(), -1);

Bars = 1 + BarsSince( nd );
TodayVolume = Sum(V,Bars);
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

at=IIf (BarIndex() >= StartBar,(Sum (a * V, Bars ) /TodayVolume),0);
return at;
}
ATPo = ATP(o);
ATPh = ATP(h);
ATPl = ATP(l);
ATPc = ATP(c);
col = IIf(ATPo<ATPc,colorDarkGreen,colorTan);

PlotOHLC(ATPo,ATPh,ATPl,ATPc,"ATP candles",col,styleCandle);
seniors,Could you kindly look into the above.
 
Had a look at the AFL posted by you. The limitation and problems you faced are part of the AFL and will continue to exist. To remove all that will need lots of modification.
Hi Mastermind,

Will you be able to help in this case. Believe me, if this works out it might be helpful for other day traders.

We have idea in front of us, it just need to be coded properly.

Regards
 
Last edited:

josh1

Well-Known Member
Hi Guys,
Need some help from you.
I want to identify inside close candles.
Conditions are like this---
1. When Ref(C, -1) > Ref(L,-2) and Ref(C, -1) < Ref(H, -2), Previous candle is inside candle. In simple english, If close of a candle is between High and Low of candle previous to it, it is inside candle,.

2. High and Low of the earlier candle become basis. So Ref(L, -2) and Ref(H, -2) remain base values, say BaseHi and BaseLo. All subsequent candles whose close is between these two base values to be treated as inside candles. ( I guess, we have to use static variables ). I would like to have different colour for these inside candles.

Edit- We do not change BaseHi and BaseLo until there is a breakout close outside these points. That is even if there is another candle whose close is between H and L of earlier candle, we ignore it until there is a breakout of first such base.

3. When a candle closes outside of these values, that is above BaseHi or below BaseLo is breakout candle. It can be coloured seperately. (I prefer to find this candle for Ref(C, -1) since in intraday, price can go above or below these values and in last few seconds, it goes inside so that close is inside)

4. Once a break out happens, all candles are normal until there is a close inside earlier H L.


Hi Josh

See if this is what you want.

Happy :)
Thank a lot Happy Ji,

Here is a revised code. I just gave parameters to colour scheme.

Code:
_SECTION_BEGIN("Price");
SetChartBkColor(colorBlack);
GraphXSpace=5;
_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BaseHi[1]    = H[0];		
BaseLo[1]    = L[0];
IamInside[1] = C[1] < BaseHi[1] AND C[1] > BaseLo[1];

for (i = 2; i < BarCount; i++) 
{
	if (IamInside[i-1]) 
	{
		IamInside[i] = C[i] < BaseHi[i-1] AND C[i] > BaseLo[i-1];
		if (IamInside[i])
	 	{
			BaseHi[i] = BaseHi[i-1];
			BaseLo[i] = BaseLo[i-1];	
		}
		else
		{
			BaseHi[i] = H[i-1];
			BaseLo[i] = L[i-1];		
		}		
	}
	else
	{
		IamInside[i] = C[i] > L[i-1] AND C[i] < H[i-1];
		BaseHi[i] = H[i-1];
		BaseLo[i] = L[i-1];		
	}
}
Upclr = ParamColor("UpColour",colorBlack);
Dnclr = ParamColor("DnColour",colorRed);
SetBarFillColor(IIf(C > O, Upclr,Dnclr)); 
//BarColor = IIf(NOT IamInside,ParamColor("BreakColour",colorYellow),ParamColor("Barcolour",colorWhite)); //IIf(C > O, colorSeaGreen, colorPink)
BarColor = IIf(NOT IamInside,IIf(C>BaseHi,ParamColor("BreakOutColour",colorBrightGreen),ParamColor("BreakDownColor",colorRose)),ParamColor("Barcolour",colorBlueGrey)); //IIf(C > O, colorSeaGreen, colorPink)

Plot(C, "Close", Barcolor, styleCandle | styleNoTitle);  	

// Can comment out or delete the following 
//PlotShapes(IamInside*21,colorWhite,0,L,-10);
Plot(BaseHi, "BH",colorBlueGrey, styleDashed|styleStaircase);  	
Plot(BaseLo, "BL",colorLime, styleDashed|styleStaircase);  	
_SECTION_END();
 
how to write correctly this one in afl
if ( DayC<DayO )
dayc is yesterday close and dayo is today open
it should be something like this
for( i = 1; i < BarCount; i++ )
{
if ( Close[ i ] < open[ i - 1 ] )
i dont know how to write it can anyone help
https://www.amibroker.com/guide/keyword/if.html
Code:
<RESULTPART> = IIf(Ref(Close, -1) < Open, <IFPART>, <ELSEPART>);
Your requirements are incomplete so I cannot give you full statement. You need to correctly replace RESULTPART, IFPART and ELSEPART with other appropriate code.
 

Similar threads