Simple Coding Help - No Promise.

mastermind007

Well-Known Member
It is actually doing forward reference of MA which does not make sense to me

maybe -ve sign missed....so try this

T2 = Ref(MA(Close ,CY2 ), -CY2/2)+ M2*ATR(CY2 );
B2 = Ref(MA( Close ,CY2 ), -CY2/2)- M2*ATR(CY2 )

I put -ve sign in ref 2nd argument

but this will change the way it will draw but will not repaint what is completed
Hello Nehal, Pratap

Simply placing a -ve sign before understanding the formula or calculations is risky. This particular TA technique happens to be shrouded by lots of confusion. Google it.
I've read about it in past but when I saw the first post of Nehal, I was not 100% sure if it was the same thing that I had encountered before.

Sure enough, it has been on T.J too. Take a look at what has happened here

Problem with this freely available AFL version is not in its being evidently wrong to anyone with basic AFL understanding but it actually misses the entire point. If you read his book, it talks of polynomials and what not. I am not convinced that all that the fix needed are two minus signs.

Yes, adding a minus this would make the problem disappear, but I honestly doubt overall authenticity of the code even with that fix.
 
Last edited:

pratapvb

Well-Known Member
Hello Nehal, Pratap

Simplly placing a ve sign before understanding the formula or calculations is risky. This particular TA technique happens to be shrouded by lots of confusion. Google it.
I've read about it in past but was not 100% sure if it was the same thing that I had encountered before.

Sure enough, it has been on T.J too. Take a look at what has happened here

Problem with this freely available AFL version is not in its being evidently wrong to anyone with basic AFL understanding but it actually misses the entire point. If you read his book, it talks of polynomials and what not. I am not convinced that all that the fix needed are two minus signs.

Yes, adding a minus this would make the problem disappear, but I honestly doubt overall authenticity of the code even with that fix.
I said it will change the way it is drawn and so whether that is what is required needs to be checked....I don't know this theory.....but I watched it on my chart for 2 days before suggesting

atleast what this was attempting to do was to reference 1/2 period MA back (this is standard in cycle theory) and then add/subtract multiple of ATR to it to create a band....so suggested it
 
Hello

Was planning to write a short note on different types of MAs . . . but . . .time constrains . . . will do it some other time :)

In Brief for now . . . .

For any MA we need to look for three characteristics . . .

1) The Lag (fast or slow to catch up, for e.g, slower to faster ones MA, EMA, DEMA, TEMA . . . etc)
2) The Smoothness
3) The Overshoot (for e.g. Linear Regression or Hull MA will overtake the price, when the price keeps trending )

Many new types of MA // Filters keep getting designed to the best fit . . .

Amibroker offers around 8 types standard Moving averages . . .

now if we know what exactly we are looking for we can combine just these 8 and get the curve we are looking for . . .

Even a simple moving average on HTF will suffice for getting just the direction for the trade/trend . . .


The main question is how does one use a MA,
for trade direction, or for trigger or in combination with other indicators,
the choice of MA will differ based in the purpose for which it is being used.

:) Happy
 
Hello

There are many requests on this thread that go unanswered. I apologize to everyone for that.


If the request are for something that can be done off hand, for e.g. some changes or queries about a code then I try to solve it,

But requests like ones for building an entire system are not possible to be completed due to huge time required for implementation / testing etc.



Lastly a big Thanks to all our friends at Traderji who continue to answer the queries on this thread




:) Happy
 
Hi

I am just learning AFL coding little bit, may be this will be helpful

_SECTION_BEGIN("Pivot High Pivot Low Orignal");

SetBarsRequired(350, -0);
// ------------- EazyTradePlus V1.1
SetChartOptions(0,chartShowDates|chartWrapTitle);
AboveUBB =0;
SellSignal=0;
BuySignal=0;
//--------------------------------EazyTradePlus V1.1 Main AFL
SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half", colorBlack),
ParamColor("Inner panel color lower half", colorDarkOliveGreen)); // color of inner panel
//user parameters
parmPlotScoreCard = ParamToggle("Plot KPScoreCard", "No|Yes", 1);
parmPlotA900AutoStop = ParamToggle("Plot A900/AutoStop", "No|Yes", 0);
parmA900Color = ParamColor("A900 Color", colorWhite);
parmA900Style = ParamStyle("A900 Style", styleLine, maskAll);
parmAutoStopColor = ParamColor("AutoStop Color", colorYellow);
parmAutoStopStyle = ParamStyle("AutoStop Style", styleLine, maskAll);
parmPPTextColor = ParamColor("PP Text color", colorBlack);
parmPPTrndColorUp = ParamColor("PP Trend Up color", ColorRGB(167,224,243) );
parmPPTrndColorDn = ParamColor("PP Trend Dwn color", ColorRGB(255,192,203) );
parmPPTextOffSet = Param("PP OffSet", 0.60, 0.40, 1.5, 0.1);
parmTickMultipler = Param("M/W tick allowance", 1, 0, 10, 1);
parmA900AutoStopX = ParamToggle("Plot A900/AutoStop Cross", "No|Yes");
parmA900AutoStopColorX = ParamColor("A900/AutoStop Cross Color", colorBlack);
ParmSCThreshold = Param("ScoreCard Threshold", 3, 1, 9, 1);
parmVoice = ParamToggle("Voice 123 Setups", "No|Yes", 0);
parmAlert = ParamToggle("Alert 123 Setups", "No|Yes", 0);
parmPivotPop = ParamToggle("PivotPop", "No|Yes", 1);
parmBarCancel = Param("Bar Cancel", 7, 1, 20, 1);
parmWaterLevelColor = ParamColor("WalterLevel Color", ColorRGB(127,255,212));
parmWaterLevelStyle = ParamStyle("WaterLevel Style", styleLine, maskAll);
parmBBPeriod = Param("Bollinger Band Period", 10, 2, 30, 1);
parmBBSD = Param("bollinger Band SD", 0.8, 0.2, 3.0);
ParmPlotPPIndicators = ParamToggle("Plot Pivot Pop indicators", "No|Yes", 0);
parmBBColor = ParamColor("BBands Color", colorBlack);
parmBBStyle = ParamStyle("BBands Style", styleLine, maskAll);

ParmDebug = ParamToggle("Debug", "No|Yes", 0);

// constants
_N(PaneName = Name() + Interval(2)+ _SECTION_NAME());
_N(NewBarName = "NewBar" + PaneName);

//functions
function NewBarP()
{
PrevDT = StaticVarGet( NewBarName);
DT = LastValue(DateTime());
StaticVarSet( NewBarName,DT);
return DT != PrevDT;
}
function MRoundP(Number, Multiple )
{
if(Multiple == 0 )
{

xMultiple = 0.01; }
else
{
xMultiple = Multiple;
}
Divided = Number / xMultiple;
intDivided = int(Divided);
intDivided = intDivided + round(Divided - intDivided);
return intDivided * xMultiple;
}

//miscellaneous setups
ObjAB = CreateObject("Broker.Application");
ticker = objAB.Stocks(Name() );
if(ticker.TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = ticker.TickSize; // use Tick Size for this symbol
}
NewBarSignal = NewBarP();
// KP Indicators
KPA900 = E_TSKPA900(Close);
KPAutoStop = E_TSKPAUTOSTOP(High,Low,Close);
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); //ScoreCard
KPScoreCard = 0;
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd0 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd1 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd2 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd3 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd4 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd5 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd6 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd7 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd8 > 0, 1, -1);

if(parmDebug == 1)
{
printf("a900: %0.6f% \nAutoStop: %0.6f%\nScoreCard: %0.0f%\n", KPA900, KPAutoStop, KPScoreCard);
}
if(parmPlotScoreCard == 1)
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g% (%0.4f%) {{VALUES}}", O, H, L, C, SelectedValue( C - Ref(C, -1)) ));
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.2f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
Color = IIf(KPScoreCard >= parmSCThreshold, colorBlue, IIf(KPScoreCard <= -parmSCThreshold, colorRed, colorYellow) );
Plot( C, "Close", Color , styleNoTitle | ParamStyle("OHLC Style",styleBar | styleThick) | GetPriceStyle() );
}
//user want A900/AutoStop plotted
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
// find A900/AutoStop cross over/under with ScoreCard confirmation.
XOUp = (KPA900 > KPAutoStop) AND (KPScoreCard >= parmSCThreshold); // New Pivot Low
XODn = (KPA900 < KPAutoStop) AND (KPScoreCard <= -parmSCThreshold); // New Pivot High
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "before= XOUp: True", "before= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//remove duplicate signals
XOUp = ExRem(XOUp, XODn);
XODn = ExRem(XODn, XOUp);

if(parmDebug == 1)
{
printf(WriteIf(XOUp, "after= XOUp: True", "after= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//find the current Pivot Points - PL and PH
//remember XOUp = 1 means a PL and XODn =1 means a PH
PLBars = IIf(XOUp, LowestSinceBars(XODn, L ,1), 0); //find the bar that produced the Lowest Low
PHBars = IIf(XODn, HighestSinceBars(XOUp, H, 1),0); //find the bar that produced the Highest High
//PLPrice = IIf(XOUp, Ref(L, -PLBars), 0);
//PHPrice = IIf(XODn, Ref(H, -PHBars),0);
PLPrice = Ref(L, -PLBars);
PHPrice = Ref(H, -PHBars);

//keep track of the previous Pivot Points
PrevPLBars = Ref(BarsSince(XOUp), -1) +1;
PrevPHBars = Ref(BarsSince(XODn), -1) +1;
PrevPLPrice = Ref(PLPrice, -prevPLBars);
PrevPHPrice = Ref(PHPrice, -PrevPHBars );
PivotsCloseEnough = TickValue * parmTickMultipler;
PLDifference = MroundP(PLPrice - PRevPLPrice, ticker.TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, ticker.TickSize);
PPTrend = IIf(XOUp AND (PLDifference > PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND (PLDifference < - PivotsCloseEnough) AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND (PHDifference > PivotsCloseEnough) AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND (PHDifference < -PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1,
IIf(XOUp AND (abs(PLDifference) <= PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 2,
IIf(XODn AND (abs(PHDifference) <= PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -2, 0)))) ));
if(ParmDebug)
{
printf("Current PH Bar: %g% /Price: %g%\n", PHBars, PHPrice);
printf("Current PL Bar: %g% /Price: %g%\n", PLBars, PLPrice);
printf("Previous PH Bar: %g% /Price: %g%\n", PrevPHBars, PrevPHPrice);
printf("Previous PL Bar: %g% /Price: %g%\n", PrevPLBars, PrevPLPrice) ;
printf("PP Trend: %g%\n", PPTrend);
printf("PHPrice - PrevPHPrice: %g%\nPLPrice - PrevPLPrice: %g%\nPivotsCloseEnough: %g%", PHDifference, PLDifference, PivotsCloseEnough);
}
//PLot pivots as text
dist = parmPPTextOffSet * ATR(10);
//for( i = 0; i < BarCount -1; i++)
for( i = 0; i < BarCount ; i++)
{
if(XOUp[i ] == 1 AND abs(PPTrend) != 2) //cross up -plot the Pivot Low
{
PlotText("PL", i - PLBars, PLPrice - dist , parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XODn[i ] == 1 AND abs(PPTrend) != 2) //cross down - plot the pivot high
{
PlotText("PH", i - PHBars, PHPrice + dist, parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XOUp[i ] == 1 AND (PPTrend) == 2) // the Pivot Low is a W Bottom
{
PlotText("PW", i - PLBars, PLPrice - dist , parmPPTextColor, colorYellow) ;
}
if(XODn[i ] == 1 AND PPTrend == -2) //cross down - pivot high is a M Top
{
PlotText("PM", i - PHBars, PHPrice + dist, parmPPTextColor, colorYellow) ;
}
PPL = (XOUp[i ] == 1 AND abs(PPTrend) != 2);
PPH = (XODn[i ] == 1 AND abs(PPTrend) != 2);

} //end For

_SECTION_END();

PMA = MA(C,15);

Plot(PMA, "", colorLime);

Buy=PPH>PMA AND C>PPH;
Sell=PPL<PMA AND C<PPL;
Short = PPL;
Cover=PPH;

Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-35);
PlotShapes(Short*shapeDownArrow,colorRed,0,H,-35);


I dont know why arrows are not coming, where did I went wrong, may be seniors may help to correct the mistake



Hi Guyz,

I tried copying this code..

But getting more than 10 to 20 errores.. and few errors like

Error 32. Syntax error, probably missing semicolon at the end of the previous line
Error 29. Variable <kpautostop> used without having been initialized
Error 29. Variable <kp900> used without having been initialized


plz can u rectify these.. thank you...
 
Below is the Market Profile AFL which can plot hourly/daily/weekly and monthly profile. I want to add Quarterly option in it so it can plot quarterly profile. Is there any way we can add quarterly option to this ? Is there any Quarterly () function available in amibroker like Month() or Day().
Thanks



_SECTION_BEGIN( "MPLite" );
// - there was a plot limit call introduced after 5.41.0 beta
// i.e. "•Warning 502: Calling Plot()/PlotOHLC over 500 times is displayed in indicator in runtime to prevent abuse"
// - uses GFX for major calls of plot only if AB version newer than 5.40 - this only delays reaching the plot limit
// - see also the toggle parameter "use_original_version"

PlotOHLC( O, H, L, C, "Price", IIf( C > O, colorGreen, colorRed ), styleCandle );
function Lastthursday()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 4, 1, IIf( Daysinmonthfinal - Day() < 8 AND DayOfWeek() == 3 AND Ref( DayOfWeek(), 1 ) != 4 AND Day() != Daysinmonthfinal , 1, 0 ) );
return returnvalue;
}

procedure PlotlinewithGFXinit()
{
global AB_Miny, AB_Maxy, AB_lvb, AB_fvb;
global AB_pxchartleft, AB_pxchartwidth, AB_pxchartbottom, AB_pxchartheight;
global AB_TotalBars, AB_penwidth;

RequestTimedRefresh(1);
GfxSetOverlayMode( 0 );
AB_penwidth = 2;

AB_Miny = Status( "axisminy" );
AB_Maxy = Status( "axismaxy" );
AB_lvb = Status( "lastvisiblebar" );
AB_fvb = Status( "firstvisiblebar" );

AB_pxchartleft = Status( "pxchartleft" );
AB_pxchartwidth = Status( "pxchartwidth" );
AB_pxchartbottom = Status( "pxchartbottom" );
AB_pxchartheight = Status( "pxchartheight" );

AB_TotalBars = AB_Lvb - AB_fvb;
}

procedure Plot_horizon_line_with_GFX( ix0, ix1, iy, icolor )
{
global AB_Miny, AB_Maxy, AB_lvb, AB_fvb;
global AB_pxchartleft, AB_pxchartwidth, AB_pxchartbottom, AB_pxchartheight;
global AB_TotalBars, AB_penwidth;

local ix0, ix1, iy, icolor;
local x_px, y_px, y_scale;

GfxSelectPen( icolor, AB_penwidth, 0 );
x_px = AB_pxchartleft + ( ix0 - AB_fvb ) * AB_pxchartwidth / ( AB_TotalBars + 1 );

y_scale = AB_pxchartheight / ( AB_maxy - AB_miny );
y_px = AB_pxchartbottom - floor( 0.5 + ( iy - AB_Miny ) * y_scale );
GfxMoveTo( x_px, y_px );

x_px = AB_pxchartleft + ( ix1 - AB_fvb ) * AB_pxchartwidth / ( AB_TotalBars + 1 );
GfxLineTo( x_px, y_px );
}


FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );

totalVisible = Lastvisiblebar - FirstVisibleBar;
//if(totalVisible<1500){
use_original_version = ParamToggle("MP version", "GFX code(only if AB > 5.40)|original code", 0);
//Den = Param("Density", 1, 0.1, 10, 0.1);
percent = Param( "Value Area", 70, 1, 100, 1 );
Type = ParamList( "Type", "Price Profile|Volume Profile" );
Period = ParamList( "Base", "Hourly|Daily|Weekly|Monthly|Lastthursday|Yearly", 1 );
x_scale = Param( "Horizontal_scale", 2, 0, 10, 0.1 );

EnMP2= ParamStyle("Style",styleLine|styleHidden|styleNoLabel,maskAll);
styleLines = styleDots;

EnIB = ParamToggle( "Show Initial Balance", "No|Yes", 1 );
IBBars = Param( "Initial Balance Bars", 2, 1, 10, 1 );

ViewYvalues = ParamToggle( "Show Yesterdays Values", "No|Yes", 1 );
ViewVlines = ParamToggle( "Show Vertical Base Lines", "No|Yes", 0 );
Viewvalues = ParamToggle( "Show Values", "No|Yes", 0 );
ViewVpoc = ParamToggle( "Show Virgin POC", "No|Yes", 1 );
ViewTPO = ParamToggle( "Show TPO Count", "No|Yes", 0 );

ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);

Color_Above_VA = ParamColor( "Color_Above_VA", colorGrey40 );
Color_VA = ParamColor( "Color_VA", colorBlueGrey );
Color_Below_VA = ParamColor( "Color_Below_VA", colorGrey40 );
Color_POC_line = ParamColor( "Color_POC_Line", colorYellow );

color_YVAH = ParamColor( "YVAH", colorWhite );
color_YVAL = ParamColor( "YVAL", colorWhite );
color_YPOC = ParamColor( "YPOC", colorYellow );

IBColor = ParamColor( "IB Color", colorWhite );
IBstyle = ParamStyle( "IB style", styleLine, maskAll );
Color_Virgin_POC = ParamColor( "Virgin Poc Color", colorYellow );
Color_Base_Line = ParamColor( "Base Line Color", colorDarkGrey );

if ( Period == "Hourly" )
{
BarsInDay = BarsSince( Hour() != Ref( Hour(), -1 ) );
Bot = TimeFrameGetPrice( "L", inHourly, 0 );
Top = TimeFrameGetPrice( "H", inHourly, 0 );
Vol = TimeFrameGetPrice( "V", inHourly, 0 );
}

if ( Period == "Daily" )
{
//OR Interval()==3600
BarsInDay = BarsSince( Day() != Ref( Day(), -1 ) ) ;
Bot = TimeFrameGetPrice( "L", inDaily, 0 );
Top = TimeFrameGetPrice( "H", inDaily, 0 );
Vol = TimeFrameGetPrice( "V", inDaily, 0 );
}

if ( Period == "Weekly" OR Interval() == 24 * 3600 )
{
BarsInDay = BarsSince( DayOfWeek() < Ref( DayOfWeek(), -1 ) );
bot1 = ValueWhen( BarsInDay == 0, L, 1 );
Bot2 = ValueWhen( Ref( BarsInDay, 1 ) == 1 OR BarIndex() > BarCount - 2 , LLV( L, BarsInDay ), 0 );
bot = Min( bot1, bot2 );
top1 = ValueWhen( BarsInDay == 0, H, 1 );
Top2 = ValueWhen( Ref( BarsInDay, 1 ) == 1 OR BarIndex() > BarCount - 2, HHV( H, BarsInDay ), 0 );
top = Max( top1, top2 );
Vol = TimeFrameGetPrice( "V", inWeekly, 0 );
}

if ( Period == "Monthly" )
{
BarsInDay = BarsSince( Month() != Ref( Month(), -1 ) );
Bot = TimeFrameGetPrice( "L", inMonthly, 0 );
Top = TimeFrameGetPrice( "H", inMonthly, 0 );
Vol = TimeFrameGetPrice( "V", inMonthly, 0 );
}

if ( Period == "Lastthursday" )
{
BarsInDay = BarsSince( Lastthursday() == 0 AND Ref( Lastthursday(), -1 ) == 1 );
bot1 = ValueWhen( BarsInDay == 0, L, 1 );
Bot2 = ValueWhen( Ref( BarsInDay, 1 ) == 1 OR BarIndex() > BarCount - 2 , LLV( L, BarsInDay ), 0 );
bot = Min( bot1, bot2 );
top1 = ValueWhen( BarsInDay == 0, H, 1 );
Top2 = ValueWhen( Ref( BarsInDay, 1 ) == 1 OR BarIndex() > BarCount - 2, HHV( H, BarsInDay ), 0 );
top = Max( top1, top2 );
Vol = ValueWhen( Ref( BarsInDay, 1 ) == 1 OR BarIndex() > BarCount - 2 , Sum( V, BarsInDay ), 0 );

}

if ( Period == "Yearly" )
{
BarsInDay = BarsSince( Year() != Ref( Year(), -1 ) );
Bot = TimeFrameGetPrice( "L", inYearly, 0 );
Top = TimeFrameGetPrice( "H", inYearly, 0 );
Vol = TimeFrameGetPrice( "V", inYearly, 0 );
}

CurTop = HHV( H, BarsInDay + 1 );

Curbot = LLV( L, BarsInDay + 1 );

Range = Top - Bot;
coverage = LastValue( Ref( ATR( 10 ), -1 ) );

den = ( coverage / 10 );
//den=1;

multiplier = IIf( round( totalVisible ) / 300 < 1, 1, round( totalVisible ) / 300 );

if ( ViewVlines == 1 )
{

Plot( BarsInDay == 0, "", Color_Base_Line, styleHistogram | styleOwnScale | styleLine | styleNoLabel );
}

relTodayRange = 0;

x = 0;
basey = 0;
basex = 0;
newday = 0;
total = 0;
shiftup = 0;
shiftdn = 0;
Line = Null;
Voloumeunit = 0;

PlotlinewithGFXinit();
for ( i = IIf( FirstVisibleBar - 100 > 1, FirstVisibleBar - 100, FirstVisibleBar ); i < Lastvisiblebar AND i < BarCount - 1 ; i++ )
{
if ( BarsInDay == 0 )
{
t = BarsInDay[i-1];


if ( EnIB == 1 )
{
IBH = HHV( H, IBBars );
IBL = LLV( L, IBBars );
Line1 = LineArray( basex, IBH[basex+IBBars-1], i, IBH[basex+IBBars-1] );
Plot( Line1, "", IBColor, IBstyle );
Line2 = LineArray( basex, IBL[basex+IBBars-1], i, IBL[basex+IBBars-1] );
Plot( Line2, "", IBcolor, IBstyle );
}

//////////////////////////////////
poc = 0;
pocj = 0;
midrange = int( relTodayRange / 2 ) + 1;

for ( j = 1; j <= relTodayRange + 1 ; j++ )
{
if ( poc < x[j] )
{
poc = x[j];
pocj = j;
}
else
if ( poc == x[j] )
{
if ( abs( midrange - j ) < abs( midrange - pocj ) )
{
poc = x[j];
pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n] = x[n] + total[n-1];
}

Value_area = ( total[relTodayRange] * percent ) / 100;

for ( a = 1; a <= relTodayRange; a++ )
{
if ( pocj - a > 0 AND pocj + a < relTodayRange )
{
if ( poc + total[pocj+a] - total[pocj] + ( total[pocj] - poc ) - total[pocj-( a+1 )] >= Value_area )
{
shiftup = a;
shiftdn = a;
break;
}
}
else
if ( pocj - a < 1 )
{
if ( poc + total[pocj+a] - total[pocj] + ( total[pocj] - poc ) >= Value_area )
{
shiftup = a;
shiftdn = pocj;
break;
}
}
else
if ( pocj + a > relTodayRange )
{
if ( poc + total[relTodayRange] - total[pocj] + ( total[pocj] - poc ) - total[pocj-( a+1 )] >= Value_area )
{
shiftup = floor( relTodayRange ) - pocj;
shiftdn = a + 1;
break;
}
}
}


if ( ViewVpoc == 1 )
{
Virginpoc = basey + pocj * den;
newi = Null;

for ( j = i; j <= ( BarCount - 1 ) ; j++ )
if ( L[j] < Virginpoc AND H[j] > Virginpoc )
{
newi = j;
break;
}
else
{
newi = BarCount;
}

Plot( LineArray( basex, basey + pocj*den, newi, basey + pocj*den ), "", Color_Virgin_POC, styleLine | styleNoRescale );
}

Vah = LineArray( baseX, baseY + ( pocj + shiftup ) * den, i, baseY + ( pocj + shiftup ) * den );
Val = LineArray( baseX, baseY + ( pocj - shiftdn ) * den, i, baseY + ( pocj - shiftdn ) * den );
pocline = LineArray( basex, basey + pocj * den, basex + poc, basey + pocj * den );


Vahn = LineArray( i, baseY + ( pocj + shiftup ) * den, i + t, baseY + ( pocj + shiftup ) * den );
pocn = LineArray( i, baseY + ( pocj ) * den, i + t, baseY + ( pocj ) * den );
Valn = LineArray( i, baseY + ( pocj - shiftdn ) * den, i + t, baseY + ( pocj - shiftdn ) * den );

if ( Version() > 5.4 && !use_original_version )
{
// pocline
Plot_horizon_line_with_GFX( baseX, basex + poc, basey + pocj * den, Color_POC_Line );
}
else
{
Plot( pocline, "", Color_POC_Line, styleLine | styleNoRescale | styleNoLabel );
}

if ( ViewYvalues == 1 )
{
Plot( Vahn, "", color_YVAH, styleDots | styleNoRescale );
Plot( Valn, "", color_YVAL, styleDots | styleNoRescale );
Plot( pocn, "", color_YPOC, styleDots | styleNoRescale );
}


if ( ViewTPO == 1 )
{
nnn = HHV( H, BarsInDay );
PlotText( "" + ( total[relTodayRange] - total[pocj] ), basex, nnn, colorLightGrey );
PlotText( "" + ( total[pocj-1] ), basex, basey - den, colorLightGrey );
}

if ( Viewvalues == 1 )
{
PlotText( "" + ( ( basey + pocj*den ) ), baseX, basey + pocj*den, colorWhite, colorDarkGrey );
PlotText( "" + ( ( baseY + ( pocj + shiftup )*den ) ), baseX, baseY + ( pocj + shiftup )*den, colorWhite, colorDarkGrey );
PlotText( "" + ( ( baseY + ( pocj - shiftdn )*den ) ), baseX, baseY + ( pocj - shiftdn )*den, colorWhite, colorDarkGrey );
}


if ( Version() > 5.4 && !use_original_version )
{
for ( p = 0; p <= relTodayRange + 1; p = p + multiplier )
{
Plot_horizon_line_with_GFX( baseX, baseX + x[p], baseY + p * Den, IIf( p > ( pocj + shiftup ), Color_Above_VA, IIf( p <= ( pocj + shiftup ) AND p >= ( pocj - shiftdn ), Color_VA, Color_Below_VA )));
}
}
else
{
for ( p = 0; p <= relTodayRange + 1; p = p + multiplier )
{
if ( P > 0 )
{
line = LineArray( baseX, baseY + ( p ) * Den, baseX + x[p], baseY + ( p ) * Den );
}
Plot( line, "", IIf( p > ( pocj + shiftup ), Color_Above_VA, IIf( p <= ( pocj + shiftup )AND p >= ( pocj - shiftdn ), Color_VA, Color_Below_VA ) ) , EnMP2 );
}
}

///////////////////
basex = 0;
x = 0;
Basex = i;
baseY = Bot;
relTodayRange = Range / Den;
Voloumeunit = Vol / LastValue( BarsInDay );

}

for ( j = 0; j <= relTodayRange ; j++ )
{
if ( L <= Bot + j*Den AND H >= Bot + j*Den )
{

if ( Type == "Price Profile" )
{
x[j] = ( x[j] ) + x_scale;
}
else
if ( Type == "Volume Profile" )
{
x[j] = x[j] + round( V / Voloumeunit ) + 1;
}

}
}
}


if ( EnIB == 1 )
{
IBH = HHV( H, IBBars );
IBL = LLV( L, IBBars );
Line1 = LineArray( basex, IBH[basex+IBBars-1], i, IBH[basex+IBBars-1] );
Plot( Line1, "", IBColor, IBstyle );
Line2 = LineArray( basex, IBL[basex+IBBars-1], i, IBL[basex+IBBars-1] );
Plot( Line2, "", IBColor, IBstyle );
}

//////////////////////////////////
poc = 0;
pocj = 0;
midrange = int( relTodayRange / 2 ) + 1;

for ( j = 1; j <= relTodayRange + 1 ; j++ )
{
if ( poc < x[j] )
{
poc = x[j];
pocj = j;
}
else
if ( poc == x[j] )
{
if ( abs( midrange - j ) < abs( midrange - pocj ) )
{
poc = x[j];
pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n] = x[n] + total[n-1];
}

Value_area = ( total[relTodayRange] * percent ) / 100;


for ( a = 1; a <= relTodayRange; a++ )
{
if ( pocj - a > 0 AND pocj + a < relTodayRange )
{
if ( poc + total[pocj+a] - total[pocj] + ( total[pocj] - poc ) - total[pocj-( a+1 )] >= Value_area )
{
shiftup = a;
shiftdn = a;
break;
}
}
else
if ( pocj - a < 1 )
{
if ( poc + total[pocj+a] - total[pocj] + ( total[pocj] - poc ) >= Value_area )
{
shiftup = a;
shiftdn = pocj;
break;
}
}
else
if ( pocj + a > relTodayRange )
{
if ( poc + total[relTodayRange] - total[pocj] + ( total[pocj] - poc ) - total[pocj-( a+1 )] >= Value_area )
{
shiftup = floor( relTodayRange ) - pocj;
shiftdn = a + 1;
break;
}
}
}

Vah = LineArray( baseX, baseY + ( pocj + shiftup ) * den, i, baseY + ( pocj + shiftup ) * den );
Val = LineArray( baseX, baseY + ( pocj - shiftdn ) * den, i, baseY + ( pocj - shiftdn ) * den );
pocline = LineArray( basex, basey + pocj * den, basex + poc, basey + pocj * den );

if ( ViewTPO == 1 )
{
PlotText( "" + ( total[relTodayRange] - total[pocj] ), basex, top, colorLightGrey );
PlotText( "" + ( total[pocj-1] + x_scale ), basex, basey - den, colorLightGrey );
}

if ( Viewvalues == 1 )
{
PlotText( "" + ( ( basey + pocj*den ) ), baseX, basey + pocj*den, colorWhite, colorDarkGrey );
PlotText( "" + ( ( baseY + ( pocj + shiftup )*den ) ), baseX, baseY + ( pocj + shiftup )*den, colorWhite, colorDarkGrey );
PlotText( "" + ( ( baseY + ( pocj - shiftdn )*den ) ), baseX, baseY + ( pocj - shiftdn )*den, colorWhite, colorDarkGrey );
}



if ( Version() > 5.4 && !use_original_version )
{
for ( p = 0; p <= relTodayRange + 1; p = p + multiplier )
{
Plot_horizon_line_with_GFX( baseX, baseX + x[p], baseY + p * Den, IIf( p > ( pocj + shiftup ), Color_Above_VA, IIf( p <= ( pocj + shiftup ) AND p >= ( pocj - shiftdn ), Color_VA, Color_Below_VA )));
}
// pocline
Plot_horizon_line_with_GFX( baseX, basex + poc, basey + pocj * den, Color_POC_Line );
}
else
{
for ( p = 0; p <= relTodayRange + 1; p = p + multiplier )
{
line = LineArray( baseX, baseY + p * Den, baseX + x[p], baseY + p * Den );
Plot( line, "", IIf( p > ( pocj + shiftup ), Color_Above_VA, IIf( p <= ( pocj + shiftup )AND p >= ( pocj - shiftdn ), Color_VA, Color_Below_VA ) ), EnMP2 );
}

Plot( pocline, "", Color_POC_Line, styleLine | styleNoRescale | styleNoLabel );
}
_SECTION_END();
 

Nehal_s143

Well-Known Member
Sir do you have any different solution for fixing the repaint ? please suggest...

Hello Nehal, Pratap

Simply placing a -ve sign before understanding the formula or calculations is risky. This particular TA technique happens to be shrouded by lots of confusion. Google it.
I've read about it in past but when I saw the first post of Nehal, I was not 100% sure if it was the same thing that I had encountered before.

Sure enough, it has been on T.J too. Take a look at what has happened here

Problem with this freely available AFL version is not in its being evidently wrong to anyone with basic AFL understanding but it actually misses the entire point. If you read his book, it talks of polynomials and what not. I am not convinced that all that the fix needed are two minus signs.

Yes, adding a minus this would make the problem disappear, but I honestly doubt overall authenticity of the code even with that fix.
 

Nehal_s143

Well-Known Member
Use amibroker higher version try 5.60

Hi Guyz,

I tried copying this code..

But getting more than 10 to 20 errores.. and few errors like

Error 32. Syntax error, probably missing semicolon at the end of the previous line
Error 29. Variable <kpautostop> used without having been initialized
Error 29. Variable <kp900> used without having been initialized


plz can u rectify these.. thank you...
 

Similar threads