Simple Coding Help - No Promise.

josh1

Well-Known Member
Code:
H1 = TimeFrameGetPrice("H",inHourly,-1);
L1 = TimeFrameGetPrice("L",inHourly,-1);
UP = Cross(H,H1);		DN = Cross(L1,L);
if (SelectedValue(UP))	Say( "JOSH Please WAKE-UP . . . , We need to look for  Long trades now . . ." );
if (SelectedValue(DN))	Say( "JOSH Please WAKE-UP . . . , We need to look for Short trades now . . ." );
Happy :)
Happy :),

I did some Bar Replay. In 5 min Time frame, with this code AB keeps shouting at me for 5 minutes :rofl: Also when I opened AB in the morning, it starts shouting. No visible bar was selected. Clicked on the blank bars area.
May be this code is required in a For loop ?
 
Happy :),

I did some Bar Replay. In 5 min Time frame, with this code AB keeps shouting at me for 5 minutes :rofl: Also when I opened AB in the morning, it starts shouting. No visible bar was selected. Clicked on the blank bars area.
May be this code is required in a For loop ?
Sorry, did not test the alert part before posting, . . . :D

One solution can be instead of if, we can use Alertif (point it to our sound file)

Code:
H1 = TimeFrameGetPrice("H",inHourly,-1);
L1 = TimeFrameGetPrice("L",inHourly,-1);
UP = Cross(H,H1);		DN = Cross(L1,L);
AlertIf(UP, "SOUND D:\\My_UP_Sound_File.wav", "Audio alert", 2 );
AlertIf(DN, "SOUND D:\\My_DN_Sound_File.wav", "Audio alert", 2 );
Change the name/location of your sound file used for alert (wav format)

Happy :)
 
Last edited:
I had imported 2010 NIFTY data and tried backtesting with Start Dt: 1-Jan-2010 and End Dt: 31-Dec-2010.

Profit margin I got is 60%.

Next I imported 2011 data also, in addition to already existing 2010 data.

I tried repeating the same procedure - backtesting with Start Dt: 1-Jan-2010 and End Dt: 31-Dec-2010.

However, profit margin I got this time is 72%.

Kindly help in understanding why testing the same period is giving different result!! My code is not future looking.
 
hello and thanks for all ,can you convert 2 metatrader indicator code to amibroker , many many thanks for all of you , special KelvinHand for your help ,
//----------------------------------------------------------------------------------------------
//#1indicator nst
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Orange
#property indicator_level1 -50
#property indicator_level2 0
#property indicator_level3 50
#property indicator_levelcolor Gray
#property indicator_levelstyle 2
#property indicator_minimum -100
#property indicator_maximum 100

extern int NST_period = 20;
extern int SmLen = 10;


static datetime lastcalctime;

double NST[];
double RawNST[];
double maNST[];

double fC0Buffer[];
double fA8Buffer[];
double fC8Buffer[];
double list[128], ring1[128], ring2[11], buffer[62];
bool initFlag;
int limitValue, startValue, loopParam, loopCriteria;
int cycleLimit, highLimit, counterA, counterB;
double cycleDelta, lowDValue, highDValue, absValue, paramA, paramB;
double phaseParam, logParam, JMAValue, series, sValue, sqrtParam, lengthDivider;
int s58, s60, s40, s38, s68;

int init()
{
if(SmLen < 5) SmLen = 5;
else if(SmLen > 15) SmLen = 15;
string nstname = "NST(" + NST_period + ", " + SmLen + ")";
IndicatorShortName(nstname);
IndicatorDigits(0);
IndicatorBuffers(3);
SetIndexBuffer(0, NST);
SetIndexLabel(0, nstname);
SetIndexBuffer(1, RawNST);
SetIndexBuffer(2, maNST);
return(0);
}

int start()
{

if(bars <= NST_period + 3*SmLen) return(0);
if(counted_bars < 0) counted_bars = 0;
if(counted_bars > NST_period) limit = bars - counted_bars;
else limit = bars - NST_period - 1;

for(i = limit; i >= 0; i--)
{
double SumWgt = 0, SumDnm = 0, HghAry, LowAry, RngAry, FrcAry, TmeAry, WgtAry;
for(ii = 0; ii <= NST_period; ii++)
{
if(ii < 2) HghAry = High; else HghAry = High[iHighest(NULL, 0, MODE_HIGH, ii, i)];
if(ii < 2) LowAry = Low; else LowAry = Low[iLowest(NULL, 0, MODE_LOW, ii, i)];
RngAry = HghAry - LowAry;
if(RngAry == 0) FrcAry = 0; else FrcAry = (Close - LowAry) / RngAry;
TmeAry = 1 / MathPow(ii+1, 0.5);
WgtAry = TmeAry * FrcAry;
SumWgt += WgtAry;
SumDnm += TmeAry;
}
RawNST = (200 * SumWgt / SumDnm) - 100;
}

double ExpSmooth = 2, XAvg1, XAvg2, XAvg3;
ExpSmooth = ExpSmooth / (SmLen + 1);
for(i = bars - NST_period - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNST - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNST = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
if(i < bars - NST_period - 1 - 3*SmLen)
{
if(maNST > 85) NST = MathRound(85 + (maNST - 85) / 2);
else if(maNST < -85) NST = MathRound(-85 - (MathAbs(maNST) - 85) / 2);
else NST = MathRound(maNST);
}
}

return(0);
}


int IntPortion(double param)
{
if (param > 0) return (MathFloor (param));
if (param < 0) return (MathCeil (param));
return (0);
}

//----------------------------------------------------------------------------------------------

//----------#2 indicator nxc

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Lime
#property indicator_level1 -50
#property indicator_level2 0
#property indicator_level3 50
#property indicator_levelcolor Gray
#property indicator_levelstyle 2
#property indicator_minimum -100
#property indicator_maximum 100

extern int NDX_period = 40;
extern int NDX_SmLen = 20;
extern int NST_period = 20;
extern int NST_SmLen = 10;


static datetime lastcalctime;

double NXC[];
double ZH[];
double RawNDX[];
double RawNST[];

double maNDX[];
double maNST[];

double fC0Buffer[];
double fA8Buffer[];
double fC8Buffer[];
double list[128], ring1[128], ring2[11], buffer[62];
bool initFlag;
int limitValue, startValue, loopParam, loopCriteria;
int cycleLimit, highLimit, counterA, counterB;
double cycleDelta, lowDValue, highDValue, absValue, paramA, paramB;
double phaseParam, logParam, JMAValue, series, sValue, sqrtParam, lengthDivider;
int s58, s60, s40, s38, s68;

int init()
{
if(NDX_SmLen < 10) NDX_SmLen = 10;
else if(NDX_SmLen > 30) NDX_SmLen = 30;
if(NST_SmLen < 5) NST_SmLen = 5;
else if(NST_SmLen > 15) NST_SmLen = 15;
string nxcname = "NXC(" + NDX_period + ", " + NDX_SmLen + ", " +
NST_period + ", " + NST_SmLen + ")";

IndicatorShortName(nxcname);
IndicatorDigits(0);
IndicatorBuffers(4);
SetIndexBuffer(0, NXC);
SetIndexLabel(0, nxcname);
SetIndexBuffer(1, ZH);
SetIndexLabel(1, "NXC_ZH");
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, ZH_symbol);
SetIndexBuffer(2, RawNDX);
SetIndexBuffer(3, RawNST);
return(0);
}

int start()
{

double ExpSmooth, XAvg1, XAvg2, XAvg3, avg, sign;

if(MaxBars > 0) { bars = MaxBars; if(counted_bars > bars) counted_bars = bars - 2; } else bars = Bars;
int start = 3*MathMax(NDX_SmLen, NST_SmLen);

if(bars <= MathMax(NDX_period, NST_period) + start) return(0);
if(counted_bars < 0) counted_bars = 0;
if(counted_bars > MathMax(NDX_period, NST_period)) limit = bars - counted_bars;
else limit = bars - MathMax(NDX_period, NST_period) - 1;

for(i = limit; i >= 0; i--)
{
double SumWght = 0, SumDnom = 0, DifAry, DnomAry, FracAry, TimeAry, WghtAry;
for(ii = 1; ii <= NDX_period; ii++)
{
DifAry = MathLog(Close[i+ii-1]) - MathLog(Close[i+ii]);
if(ii == 1) DnomAry = MathAbs(DifAry); else DnomAry += MathAbs(DifAry);
if(DnomAry == 0) FracAry = 0; else FracAry = (MathLog(Close) - MathLog(Close[i+ii])) / DnomAry;
TimeAry = 1 / MathPow(ii, 0.5);
WghtAry = FracAry * TimeAry;
SumWght += WghtAry;
SumDnom += TimeAry;
}
RawNDX = 100 * SumWght / SumDnom;
}

ArrayResize(maNDX, bars - MathMax(NDX_period, NST_period));
ArraySetAsSeries(maNDX, true);
ArrayInitialize(maNDX, 0);

ExpSmooth = 2; XAvg1 = 0; XAvg2 = 0; XAvg3 = 0;
ExpSmooth = ExpSmooth / (NDX_SmLen + 1);
for(i = bars - MathMax(NDX_period, NST_period) - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNDX - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNDX = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
}



for(i = limit; i >= 0; i--)
{
double SumWgt = 0, SumDnm = 0, HghAry, LowAry, RngAry, FrcAry, TmeAry, WgtAry;
for(ii = 0; ii <= NST_period; ii++)
{
if(ii < 2) HghAry = High; else HghAry = High[iHighest(NULL, 0, MODE_HIGH, ii, i)];
if(ii < 2) LowAry = Low; else LowAry = Low[iLowest(NULL, 0, MODE_LOW, ii, i)];
RngAry = HghAry - LowAry;
if(RngAry == 0) FrcAry = 0; else FrcAry = (Close - LowAry) / RngAry;
TmeAry = 1 / MathPow(ii+1, 0.5);
WgtAry = TmeAry * FrcAry;
SumWgt += WgtAry;
SumDnm += TmeAry;
}
RawNST = (200 * SumWgt / SumDnm) - 100;
}

ArrayResize(maNST, bars - MathMax(NDX_period, NST_period));
ArraySetAsSeries(maNST, true);
ArrayInitialize(maNST, 0);

ExpSmooth = 2; XAvg1 = 0; XAvg2 = 0; XAvg3 = 0;
ExpSmooth = ExpSmooth / (NST_SmLen + 1);
for(i = bars - MathMax(NDX_period, NST_period) - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNST - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNST = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
}


for(i = limit; i >= 0; i--)
if(i < bars - MathMax(NDX_period, NST_period) - 1 - start)
{
avg = ((MathAbs(maNDX) * maNST) + (MathAbs(maNST) * maNDX)) / 2;
if(avg > 0) sign = 1;
else if(avg < 0) sign = -1;
else sign = 0;
NXC = MathRound(sign * MathSqrt(MathAbs(avg)));
}

return(0);
}


int IntPortion(double param)
{
if (param > 0) return (MathFloor (param));
if (param < 0) return (MathCeil (param));
return (0);
}


can anyone help me to convert this 2 indicators , please
 
I had imported 2010 NIFTY data and tried backtesting with Start Dt: 1-Jan-2010 and End Dt: 31-Dec-2010.

Profit margin I got is 60%.

Next I imported 2011 data also, in addition to already existing 2010 data.

I tried repeating the same procedure - backtesting with Start Dt: 1-Jan-2010 and End Dt: 31-Dec-2010.

However, profit margin I got this time is 72%.

Kindly help in understanding why testing the same period is giving different result!! My code is not future looking.

how can we tell whenever u dont post ur afl & information in which tf u backtest it

Abhishek
 

manishchan

Well-Known Member
One request which sounds lil tricky to me... if anyone has used Trader Tiger.. they know that the tooltip in TT is super fast and always the mouse pointer turns like a dot when hovering over the chart. On other hand Amibroker tool tip (mouse hover) is lil slow responding. After you hover over the mouse.. it takes like 3 sec for the tool tip to populate.

Is there a way to show OHLC by just hovering the mouse over a candle.. possibly quicker than 3 sec (the default tooltip) ?
 

amitrandive

Well-Known Member
One request which sounds lil tricky to me... if anyone has used Trader Tiger.. they know that the tooltip in TT is super fast and always the mouse pointer turns like a dot when hovering over the chart. On other hand Amibroker tool tip (mouse hover) is lil slow responding. After you hover over the mouse.. it takes like 3 sec for the tool tip to populate.

Is there a way to show OHLC by just hovering the mouse over a candle.. possibly quicker than 3 sec (the default tooltip) ?
Mine refreshes faster than 3 seconds.
If your AFL has third party plugins or is very very long , it will refresh slow.
 

toocool

Well-Known Member
And then people start to wonder why AB reacts slow. Exactly because of codes similar to your one or worse. Next time please also use arrays within loop. Thank you!


EDIT:

much better readable/maintainable and faster

Code:
_SECTION_BEGIN("Floor Pivots");
// modified, optimized, cleaned by trash

dd = Day();
Today = LastValue( dd );
lastday = Today == dd;
    
function lastdayarray( array )
{    
    return IIf( lastday, array, Null );
}

SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );

FibCol = ParamColor( "Fib Line Color", colorOrange );//

SetBarFillColor( IIf( C > O, colorWhite , IIf( C < O, colorCustom4 , colorYellow ) ) );
Plot( C, "Close", IIf( C > Ref( C, -1 ), colorWhite , IIf( C < Ref( C, -1 ), colorSkyblue , colorYellow ) ), 64 );


DayH = TimeFrameGetPrice( "H", inDaily, -1 );
DayL = TimeFrameGetPrice( "L", inDaily, -1 );

DayO = TimeFrameGetPrice( "O", inDaily, -1 );
DayC = TimeFrameGetPrice( "C", inDaily, -1 );

// some unknown leftovers, not used in this code
//DD = C - DayC;
//xx = Prec( ( DD / DayC ) * 100, 2 );

defaultcol = EncodeColor( 55 );
Title = StrFormat( defaultcol + Name() + "     " +
                   defaultcol + Date() + "      " + EncodeColor( 5 ) + "{{INTERVAL}}" +
                   defaultcol + " Open = " + EncodeColor( 52 ) + "%g" +
                   defaultcol + " High = " + EncodeColor( 5 ) + "%g" +
                   defaultcol + " Low = " + EncodeColor( 33 ) + "%g" +
                   defaultcol + " Close = " + EncodeColor( 52 ) + "%g", O, H, L, C );
                   

RANGE = ( DayH - DayL );
PP = ( DayL + DayH + DayC ) / 3;
//PPI = LastValue ( PP, 1 ); // Pivot, unused variable
R1 = ( 2 * PP ) - DayL  ;
S1 = ( 2 * PP ) - DayH;
R2 = PP + RANGE;
S2 = PP - RANGE;
R3 = R1 + RANGE;
S3 = S1 - RANGE;
R4 = R3 + ( R2 - R1 );
S4 = S3 - ( S1 - S2 );

BC = ( DayH + DayL ) / 2;
TC = ( PP - BC ) + PP;


style = styleDots | styleNoRescale | styleNoTitle;

Plot( lastdayarray( PP ), "PP", colorGold, style );
Plot( lastdayarray( R1 ), "R1", colorOrange, style );
Plot( lastdayarray( S1 ), "S1", colorPaleGreen, style );
Plot( lastdayarray( R2 ), "R2", colorOrange, style );
Plot( lastdayarray( S2 ), "S2", colorPaleGreen, style );
Plot( lastdayarray( R3 ), "R3", colorOrange, style );
Plot( lastdayarray( S3 ), "S3", colorPaleGreen, style );
Plot( lastdayarray( R4 ), "R4", colorOrange, style );
Plot( lastdayarray( S4 ), "S4", colorPaleGreen, style );

Plot( lastdayarray( TC ), "TC", colorWhite, style );
Plot( lastdayarray( BC ), "BC", colorWhite, style );


numbars = LastValue( Cum( Status( "barvisible" ) ) );
hts = -33.5;
xtext = LastValue( BarIndex() ) - ( numbars / hts );

PlotText( StrFormat( "Pivot = %g", pp ), xtext, LastValue ( pp, 1 ), colorGold );
PlotText( StrFormat( "R1 = %g", R1 ), xtext, LastValue ( R1, 1 ), colorOrange );
PlotText( StrFormat( "S1 = %g", S1 ), xtext, LastValue ( S1, 1 ), colorPaleGreen );
PlotText( StrFormat( "R2 = %g", R2 ), xtext, LastValue ( R2, 1 ), colorOrange );
PlotText( StrFormat( "S2 = %g", S2 ), xtext, LastValue ( S2, 1 ), colorPaleGreen );
PlotText( StrFormat( "R3 = %g", R3 ), xtext, LastValue ( R3, 1 ), colorOrange );
PlotText( StrFormat( "S3 = %g", S3 ), xtext, LastValue ( S3, 1 ), colorPaleGreen );
PlotText( StrFormat( "R4 = %g", R4 ), xtext, LastValue ( R4, 1 ), colorOrange );
PlotText( StrFormat( "S4 = %g", S4 ), xtext, LastValue ( S4, 1 ), colorPaleGreen );

PlotText( StrFormat( "TC = %g", TC ), xtext, LastValue ( TC, 1 ), colorWhite );
PlotText( StrFormat( "BC = %g", BC ), xtext, LastValue ( BC, 1 ), colorWhite );
_SECTION_END();

@trash and fxarun , thanks you for your efforts guys:thumb::thumb::thumb: , its actually quite similar to what i needed , with some additions still needed , can you guys please add following into the AFL..please:clapping::clapping:

1-custom color change settings and plotting lines customization

2-i need to draw weekly ,daily as well as monthly pivots simultaneously on the charts too , with option to hide any or all of them

3- i also need to draw all these pivots for previous weeks days and months but with an option to only plot current timeframe like current daily weekly monthly pivot too , just like in the image

4-lastly i need to draw pivots for customizable time frame too , all in the same chart , i mean separate from daily, weekly and monthly .............for example if i could draw pivot for 10 days only in addition to daily weekly and monthly.all four in same chart , all customizable colors enabled to distinguish

i know guys i asked for a lot from you and i know its a lot of work , but i will be highly obliged to you if you could do that ............:thumb::thumb::clapping::clapping:

it would look like this for all weekly pivots plotted on charts , its my java chart and it cant plot all 4 types for me , only 1 time frame at a time

 
Last edited:

Similar threads