Plz provide me TimeBox afl !!

Status
Not open for further replies.

casoni

Well-Known Member
#31
Hello,
here's code :)

_SECTION_BEGIN("3");

Version(5.21);
RequestTimedRefresh(0.1,True);
SetBarsRequired(sbrAll,sbrAll);
SetChartOptions(2, chartShowDates);
Title = Name();

ChartLum = Param("Chart Background Color Intensity", 0, 0, 1, 0.01);
if(Interval()<inDaily)
{
TFMinShort = Interval();
TFMinMedium = inDaily;
TFMinLong = inWeekly;
}
else
if(Interval()==inDaily)
{
TFMinShort = inDaily;
TFMinMedium = inWeekly;
TFMinLong = inMonthly;
}

OnSTFBars = ParamToggle("Short TF Bars", "Off, On", 1);
OnMTFBars = ParamToggle("Medium 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("Medium TF Bar Color Intensity", 0.70, 0, 1, 0.01);
LTFLine = Param("Long TF Bar Line Thickness", 3, 0, 10, 1);
BarLum3 = Param("Long TF Bar Color Intensity", 0.50, 0, 1, 0.01);

// Bar Colors for the Short Timeframe candlestick bars:
LineColor = ColorBlend(colorBlack, colorWhite, BarLum1);
UpBarColor = ColorBlend(colorBrightGreen, colorWhite, BarLum1);
DnBarColor = ColorBlend(colorRed, colorWhite, BarLum1);

SetChartBkColor(ColorBlend(colorLightBlue, colorWhite, ChartLum));

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 ) );
}



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

function PlotBars(TFMinLong, BarLum, Style)
{

TFLineColor = ColorBlend(colorBlack, colorWhite, BarLum - 0.1);
TFUpBarColor = ColorBlend(colorBrightGreen, colorWhite, BarLum);
TFDnBarColor = ColorBlend(colorRed, colorWhite, BarLum);

TFSec = TFMinLong;
TimeFrameSet(TFSec);
TFOpen = Open;
TFHigh = High;
TFLow = Low;
TFClose = Close;
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 = TFHigh ;
CandleBottom = TFLow;

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);


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:
FillColor = IIf(TFOpen[i + fvb] < TFClose[i + fvb], TFUpBarColor, TFDnBarColor);
if(Style == "Fill")
{
GfxSelectPen(TFLineColor, 1);
GfxSelectSolidBrush(FillColor);
}
else
{
GfxSelectPen(FillColor, LTFLine);
GfxSelectSolidBrush(ColorBlend(colorLightBlue, colorWhite, ChartLum));
}

if(y1 == y2){y1 = y1 - Adjust; y2 = y2 + Adjust; GfxSelectSolidBrush(TFLineColor);}
if(x1 > 0){
GfxRectangle( x1, y1, x2, y2);

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);
}
}
}

if(OnLTFBars)
PlotBars(TFMinLong, BarLum3, "Line");
if(OnMTFBars)
PlotBars(TFMinMedium, BarLum2, "Fill");
_SECTION_END();
 
Status
Not open for further replies.

Similar threads