Simple Coding Help - No Promise.

Instead, is it possible to just fill the area between hourly High Low with desired color?

The code I had posted some how did not show up in the message . . .

But there is also simpler (light weight) way of doing the same with using any graphics functions

Check the code . . if this is what you want can post the simpler version


Code:
_SECTION_BEGIN("2 Timeframes Candlestick Bar Chart");
// Specially designed for use in day trading and to save chart space. This chart will displays 2 sets
// of candlestick bars. One for the time interval set for your chart- for example 1 Minute. 
// The higher timeframe candlestick bars are created by using gfx low-level graphics AND will display  
// according to the parameters you set- for example 5 minutes. 

// I got the idea from David's (dbwyatt_1999) 2 Timeframe chart code which was shared by him on the AmiBroker List. 
// It uses TimeFrame functions with the PlotOHLC function using styleCloud. So I was thinking it would look 
// very nice using low-level graphics instead. Little bit more complicated, but I got a few great pointers from Herman!

// If your chart background turns pink- please read the error message in the upper left corner of the chart.
// Then please observe this AFL code uses ColorBlend(ColorFrom, ColorTo, Factor) which was introduced in Version 5.21 beta.
// The rules are simple- time frames from 1 up to 60 minutes AND Lower time frame must be smaller than the Higher time frame.

Version(5.21); 
SetChartOptions(2, chartShowDates);
Title = Name();
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PARAMETERS AND SETTINGS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ChartLum 		= Param("Chart Background Color Intensity", 0.40, 0, 1, 0.01);
TFMinShort		= Param("Short Timeframe (Minutes)", 1, 1, 60, 1);
TFMinLong 		= Param("Long Timeframe (Minutes)", 5, 1, 60, 1);
OnSTFBars		= ParamToggle("Short TF Bars", "Off, On", 1);
OnLTFBars		= ParamToggle("Long TF Bars", "Off, On", 1);
BarLum1 		= Param("Short TF Bar Color Intensity", 0, 0, 1, 0.01);
BarLum2 		= Param("Long TF Bar Color Intensity", 0.70, 0, 1, 0.01);

//SetChartBkColor(ColorBlend(colorLightBlue, colorWhite, ChartLum));
// Bar Colors for the Short Timeframe candlestick bars:
LineColor 		= ColorBlend(colorBlack, colorWhite, BarLum1);
UpBarColor		= ColorBlend(colorBrightGreen, colorWhite, BarLum1);
DnBarColor		= ColorBlend(colorRed, colorWhite, BarLum1);
// Bar Colors For The Long Timeframe candlestick bars:
TFLineColor 	= ColorBlend(colorBlack, colorWhite, BarLum2 - 0.1);
TFUpBarColor	= ColorBlend(colorBrightGreen, colorWhite, BarLum2);
TFDnBarColor	= ColorBlend(colorRed, colorWhite, BarLum2);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FUNCTIONS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function GetVisibleBarCount() 
{ 
 lvb = Status("lastvisiblebar"); 
 fvb = Status("firstvisiblebar"); 
 return Min( Lvb - fvb, BarCount - fvb ); 
} 

function GfxConvertBarToPixelX( bar ) 
{ 
 lvb = Status("lastvisiblebar"); 
 fvb = Status("firstvisiblebar"); 
 pxchartleft = Status("pxchartleft"); 
 pxchartwidth = Status("pxchartwidth"); 
 return pxchartleft + bar  * pxchartwidth / ( Lvb - fvb + 1 ); 
} 

function GfxConvertValueToPixelY( Value ) 
{ 
 local Miny, Maxy, pxchartbottom, pxchartheight; 
 Miny = Status("axisminy"); 
 Maxy = Status("axismaxy"); 
 pxchartbottom = Status("pxchartbottom"); 
 pxchartheight = Status("pxchartheight"); 
 return pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) ); 
} 

StaticVarKey = Name();
procedure xStaticVarSet(SName, SValue)
{
 global StaticVarKey;
 if (StaticVarKey != "")
 	StaticVarSet(Sname + StaticVarKey, Svalue);
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// MAIN PROGRAM:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if(Interval() != TFMinShort * 60)
{
 Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "Set the chart time Interval to: " + NumToStr(TFMinShort, 1.0, 1) + 
					" Minute(s) or change the Short Timeframe Parameter setting.";
 OnSTFBars		= 0;
 OnLTFBars		= 0;
// SetChartBkColor(colorRose);
} 

if(TFMinShort >= TFMinLong)
{
 Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "The Long
Timeframe setting must be longer than the Short Timeframe!";
 OnSTFBars		= 0;
 OnLTFBars		= 0;
 //SetChartBkColor(colorRose);
}

if(OnSTFBars)
{
 BarColor		= IIf(Close > Open, UpBarColor, DnBarColor);
 SetBarFillColor(BarColor);
 Plot(Close, "", LineColor, styleCandle);
}
else
 Plot(Close, "", colorBlack, styleCandle  | styleNoDraw);

TFSec = in1Minute * TFMinLong; 
TimeFrameSet(TFSec); 

//Happy Changes Start
//TFOpen 			= Open; 
TFOpen 			= IIf(C>O,L,H);
TFClose			= IIf(C>O,H,L);
//TFClose			= Close; 
//Happy Changes End

TFHigh 			= High; 
TFLow 				= Low; 
TFBarIndex			= BarIndex();
TFLastBarIndex	= LastValue(BarIndex());
TimeFrameRestore(); 

TFOpen 			= TimeFrameExpand(TFOpen, TFSec, expandFirst); 
TFHigh 			= TimeFrameExpand(TFHigh, TFSec, expandFirst); 
TFLow 				= TimeFrameExpand(TFLow, TFSec, expandFirst); 
TFClose			= TimeFrameExpand(TFClose, TFSec, expandFirst);
TFBarIndex			= TimeFrameExpand(TFBarIndex, TFSec, expandLast + 1);
TFLastBarIndex	= TimeFrameExpand(TFLastBarIndex, TFSec, expandLast + 1);

CandleTop 			= Max(TFOpen, TFClose); 
CandleBottom		= Min(TFOpen, TFClose); 
//============================================================================
// GFX LOW-LEVEL GRAPHICS SECTION.
// DRAWING THE LONG TIMEFRAME CANDLESTICK BARS:
//============================================================================
if(OnLTFBars)
{ 
 GfxSetOverlayMode(1); 
 AllVisibleBars 	= GetVisibleBarCount(); 
 fvb				= Status("firstvisiblebar"); 
 ChartWidth		= GfxConvertBarToPixelX(AllVisibleBars );
 PixBar 			= ChartWidth / AllVisibleBars;
 Adjust			= Pixbar * 0.35;
 TFMinutes 		= TFMinLong / TFMinShort;
 NewTFBar 			= IIf(TFBarIndex != Ref(TFBarIndex, -1), 1, 0);
 BarInd			= BarIndex();
 TFLastBarIndex	= LastValue(TFLastBarIndex);

 // DRAW BAR HISTORY AND THE CURRENT BAR:
 for(i = 0; i < AllVisibleBars; i++) 
 {
  x1 = GfxConvertBarToPixelX(i) * NewTFBar[i + fvb] - Adjust;
  if(BarInd[i + fvb] < TFLastBarIndex AND NewTFBar[i + fvb] == 1)
	 {
		Counter = 0;
		for(n = i + 1; NewTFBar[n + fvb] == 0 AND n + fvb < BarCount-1; n++)
			Counter++;
		x2 = GfxConvertBarToPixelX(i + Counter) * NewTFBar[i + fvb] + 1 + Adjust;
	 }

  if(TFBarIndex[i + fvb] == TFLastBarIndex)
 	x2 = GfxConvertBarToPixelX(i + TFMinutes - 1) * NewTFBar[i + fvb] + 1 + Adjust;

   y1 = GfxConvertValueToPixelY(CandleTop[i + fvb]); 
   y2 = GfxConvertValueToPixelY(CandleBottom[i + fvb]); 
   yH = GfxConvertValueToPixelY(TFHigh[i + fvb]);
   yL = GfxConvertValueToPixelY(TFLow[i + fvb]);

   // Candle Body:
   GfxSelectPen(TFLineColor, 0);
   FillColor = IIf(TFOpen[i + fvb] < TFClose[i + fvb], TFUpBarColor,TFDnBarColor);
   GfxSelectSolidBrush(FillColor); 
   if(y1 == y2){y1 = y1 - Adjust; y2 = y2 + Adjust;
	GfxSelectSolidBrush(TFLineColor);}
   if(x1 > 0){
   		GfxRectangle( x1, y1, x2, y2); 
   		// Candle High and Low:
   		GfxSelectPen(TFLineColor, 2);
   		GfxMoveTo(x2+(x1-x2)/2, y1);
   		GfxLineTo(x2+(x1-x2)/2, yH);
   		GfxMoveTo(x2+(x1-x2)/2, y2);
   		GfxLineTo(x2+(x1-x2)/2, yL);
   		RequestTimedRefresh(0); 
	}
 } 
}
_SECTION_END();
Happy :)


Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);
PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,ColorRGB(40,40,120),ColorRGB(80,20,20)),styleNoLabel|styleCloud);
_SECTION_END();
 
Last edited:

amitrandive

Well-Known Member


guys i tried to find this kind of formula pivot AFL , didnt find anywhere , can you guys help please? :)
@Happy bro i tried to modify the code put by you here in this thread with my zero knowledge but it didnt work at all .............can you please help me with the code in above image? :)
http://www.traderji.com/amibroker/90153-afl-pivot-point-static.html#post874980

Try this


Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

// Calculate the daily Pivot and S/R //
 
TimeFrameSet(inDaily);
BC=(H+L)/2;
Pivot = (H + L + C)/3;
TC=(Pivot-BC)+Pivot;
R1 = (Pivot * 2) - L;
R2 = Pivot +(H - L);
R3= R1+(H-L);
R4=R3+(R2-R1);
S1 = (2 * Pivot) - H;
S2= Pivot - (H - L);
S3= S1 - (H - L);
S4=S3-(S1-S2);
 
TimeFrameRestore();
 
// Plot the Pivot Point //
 
Plot(TimeFrameExpand(Pivot,inDaily,expandLast), "Pivot Point", colorLightBlue, styleThick);
Plot(TimeFrameExpand(TC,inDaily,expandLast), "TC", colorYellow, styleThick);
Plot(TimeFrameExpand(BC,inDaily,expandLast), "BC", colorYellow, styleThick);
 
// Plot the Resistance Level Clouds and Line //
 
Plot(TimeFrameExpand(R1,inDaily,expandLast), "R1", colorGreen, styleThick);
Plot(TimeFrameExpand(R2,inDaily,expandLast), "R2", colorGreen, styleThick);
Plot(TimeFrameExpand(R3,inDaily,expandLast), "R3", colorGreen, styleThick);
Plot(TimeFrameExpand(R4,inDaily,expandLast), "R4", colorGreen, styleThick);
 
// Plot the Support Levels Clouds and Lines //
 
Plot(TimeFrameExpand(S1,inDaily,expandLast), "S1", colorRed, styleThick);
Plot(TimeFrameExpand(S2,inDaily,expandLast), "S2", colorRed, styleThick);
Plot(TimeFrameExpand(S3,inDaily,expandLast), "S3", colorRed, styleThick);
Plot(TimeFrameExpand(S4,inDaily,expandLast), "S4", colorRed, styleThick);
 
Last edited:

toocool

Well-Known Member
awesome amit bro , thanks a lot .

can you please add monthly , weekly , daily and other options generally found in pivot afl's , that would be great :)

also this afl indicator is not getting deleted from chart
 

josh1

Well-Known Member
Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);
PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,ColorRGB(40,40,120),ColorRGB(80,20,20)),styleNoLabel|styleCloud);
_SECTION_END();
Yeah.... Thanks. This one is working and much lighter. Is it possible to get borders to these?
 
Yeah.... Thanks. This one is working and much lighter. Is it possible to get borders to these?
Yes . . .

Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);

Plot(Lo,"Lo",colorBrightGreen,styleStaircase);
Plot(Hi,"Hi",colorBrightGreen,styleStaircase);

PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,ColorRGB(40,40,120),ColorRGB(80,20,20)),styleNoLabel|styleCloud);
_SECTION_END();
Its v crude, will try better one later . . .

To restrict the for loop, plotting the v line on hourly for only last 200 bars on LTF

Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);

Plot(Lo,"Lo",ColorRGB(120,120,0),styleStaircase);
Plot(Hi,"Hi",ColorRGB(120,120,0),styleStaircase);

TimeFrameSet(inHourly);
x = IIf(BarCount > 200, BarCount-200, 1);
u[x] = H[x];	y[x] = L[x];
for( i = x+1; i < BarCount; i++ ) 
{ 
	u[i] = IIf(u[i-1]==H[i-1],L[i],H[i]);
	y[i] = IIf(y[i-1]==L[i-1],H[i],L[i]);
}
TimeFrameRestore();
H1 = TimeFrameExpand(u,inHourly,expandFirst);
L1 = TimeFrameExpand(y,inHourly,expandFirst);
Plot(L1,"Lo",ColorRGB(120,120,0),styleStaircase|styleNoLabel);
Plot(H1,"Hi",ColorRGB(120,120,0),styleStaircase|styleNoLabel);

PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,ColorRGB(10,10,30),ColorRGB(30,10,10)),styleNoLabel|styleCloud,0,0,0,-1);
_SECTION_END();
Happy :)
 
Last edited:

amitrandive

Well-Known Member
Ok here is the thing I wanted an ATR trailing stop loss afl which could be properly modified for number of bars and basic style of ATR trailing method which could be plotted right below candles for stop loss visibility easily and amibroker ATR thingy didn't work as it didn't have any settings .

Now I have got such an afl from some one and it looks fantastic but I don't know it's proper settings however it feels that the afl is very good and properly made





hi guys there is an issue in this afl the stop loss calculated but this afl is not getting violated at all even after downswing after a bull run , its like a moving average which never gets touched , can you guys correct this ?:)

thanks
Try this

Code:
_SECTION_BEGIN("ERO ATR BUY SELL");
 
ero = Param("ATR multiple", 2.8, 0.5, 10, 0.1 )*Param("ATR period", 10, 3, 50 );  
ero_col=ParamColor( "Color", colorCycle );
 
r=HHV(H,ero);
s=LLV(L,ero);
ab=IIf(H>Ref(r,-1),1,IIf(L<Ref(s,-1),-1,0));
ac=ValueWhen(ab!=0,ab,1);
sl=IIf(ac==1,s,r);
 
Plot(sl, _DEFAULT_NAME(), ero_col, styleStaircase); // or styleaArea
 
Buy=Cross(H,sl);
Sell=Cross(sl,L);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();
 
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
Or Try this
Code:
_SECTION_BEGIN( "fcVS" );
period  = Param( "Period", 13, 1, 240, 1 );
mult    = Param( "Multiplier", 1.7, 1, 240, 0.1 );
 
f = ATR( period );
 
VS[0] = Close[0];
trend[0] = 0;
HighC[0] = 0;
Lowc[0] = 0;
 
for ( i = period + 1; i < BarCount; i++ )
{
 
    vs[i]       = vs[i-1];
    trend[i]    = trend[i-1];
    highC[i]    = HighC[i-1];
    lowc[i] = lowc[i-1];
 
    if ( ( trend[i] >= 0 ) && ( C[i] < VS[i] ) )
    {
        trend[i] = -1;
        HighC[i] = C[i];
        lowc[i] = C[i];
    }
 
    if ( ( trend[i] <= 0 ) && ( C[i] > VS[i] ) )
    {
        trend[i] = 1;
        HighC[i] = C[i];
        lowc[i] = C[i];
    }
 
    if ( trend[i] == -1 )
    {
        if ( C[i] < lowc[i] )
            lowc[i] = C[i];
 
        VS[i] = lowc[i] + ( mult * f[i] );
    }
 
 
    if ( trend[i] == 1 )
    {
        if ( C[i] > HighC[i] )
            HighC[i] = C[i];
 
        VS[i] = HighC[i] - ( mult * f[i] );
    }
 
}
 
 
Buy = Cross( Trend, 0 );
Sell = Cross( 0, Trend );
 
Plot( Close, "Close", colorBlack, styleCandle );
Plot( VS, "Vol Stop", IIf( trend == 1, 10, 11 ), styleThick );
 
mkol    = IIf( Trend == 1, 10,  11 );
Plot( 5, "ribbon", mkol, styleOwnScale | styleArea | styleNoLabel, 0, -5 ); // Weekly trend
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low - f, High + f ) );
_SECTION_END();
 

Similar threads