Hi AB gurus,
When there is a middle/scroll wheel click on the bar , I am getting the clicked bar OHLCV data using
x = GetCursorXPosition();
bistemp = Lookup (BarIndex(), x, 0);
fetched OHLCV data is accurate.
Want to get EMA(20) on the volume, so am populating a array (volumearray) with -100 bar from clicked bar to array and using function EMA ( volumearray, 20), the output is not matching the plotted value of ema20 on the chart refer the attached picture. tried reversing array, tried using function AMA, results are not matching plotted values.
Or May be my logic of calculated the ema is wrong.
Open picture in new tab
Appreciate all your help
Thanks
function AlertCandle (Abind, xcord) {
_TRACEF ("fn Alert candle start..."+Abind);
bi = BarIndex();
lastbi = LastValue(bi); // + 1;
tempbind = Abind;
Abind = Abind - bi; // - Abind;
//Abind = -1 * Abind;// - bi; // - Abind;
//tempbind = Abind - bi;
//_TRACEF ("alert bi="+bi+"=Bind="+Abind+"=abind-bi="+tempbind+"=lastvalue bi="+lastbi);
AC1O = Ref (O, Abind);
AC1H = Ref (H, Abind);
AC1L = Ref (L, Abind);
AC1C = Ref (C, Abind);
AC1V = Ref (V, Abind);
t=0;
tAEMAC1V = 0;
// Get volume from previous bar till 100th Bar
for( i = 1; i <= 100; i++ )
{
global Abind;
tA = V[(Abind[0] - i)];
tAEMAC1V[t] = tA;
t++;
tA=0;
}
AEMAC1V = 0;
// Get EMA of array http://www.amibroker.com/guide/afl/ema.html
AEMAC1V = EMA (tAEMAC1V, 20);
//Using Below the values are not matching
//AEMAC1V = EMA (Ref (V, Abind[0]), 20);
//AEMAC1V = EMA(Ref(V, xcord ), 20);
// Add values of Open High Low Close Volume EMA of seleced bar to string to be displayed on screen
checksig = "AC1O=" +AC1O +"=AC2H=" +AC1H + "=AC1L=" +AC1L +"=AC1C=" +AC1C + "AC1V=" +StrFormat ("%11.00f",AC1V) +"=AEMAC1O="+StrFormat ("%11.00f",AEMAC1V[20]);
StaticVarSetText("alertstring"+Name(), checksig);
for( i = 0; i <= 21; i++ )
{
_TRACEF ("AEMAC1V="+AEMAC1V+"=0="+AEMAC1V[i]+"=i="+i);
}
// Reverse Array volume to check if reversing the volume array will help, but the result are not matching to actual
AEMAC1V = 0;
tRAEMAC1V = Reverse( tAEMAC1V, first = 0, last = 100) ;
AEMAC1V = EMA (tRAEMAC1V, 20);
for( i = 0; i <= 21; i++ )
{
_TRACEF ("Reverse AEMAC1V="+AEMAC1V+"=0="+AEMAC1V[i]+"=i="+i);
}
AC2O = Ref (O, Abind - 1 );
AC2H = Ref (H, Abind - 1 );
AC2L = Ref (L, Abind - 1 );
AC2C = Ref (C, Abind - 1 );
AC2V = Ref (V, Abind - 1 );
AC3O = Ref (O, Abind - 2 );
AC3H = Ref (H, Abind - 2 );
AC3L = Ref (L, Abind - 2 );
AC3C = Ref (C, Abind - 2 );
AC3V = Ref (V, Abind - 2 );
// Below Other computation based on values of above
}
_SECTION_BEGIN("BarsV2");
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( EMA( C, 20 ), "EMA20", colorTurquoise, ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN ("Alert");
StaticVarGet ("bis"+Name());
StaticVarGetText("alertstring"+Name());
mousebuttons = GetCursorMouseButtons();
// Click center button or scroll wheel
if (mousebuttons == 12) {
x = GetCursorXPosition();
bistemp = Lookup (BarIndex(), x, 0);
StaticVarSet ("bis"+Name(), bistemp);
AlertCandle(StaticVarGet ("bis"+Name()), x );
}
// Display OHLCV and EMA on screen
GfxMoveTo (0,0);
GfxSelectFont("Times New Roman", 10, 700, True );
GfxTextOut(StaticVarGetText("alertstring"+Name()), 420, 0);
_SECTION_END();