Simple Coding Help - No Promise.

pannet1

Well-Known Member
Hi coders.... need a help

below is a exploration code of monthly high/Low of previous month. I want to add date column for both high/low so that I can easily understand when any particular symbol made high/low in previous month.


PMH = TimeFrameGetPrice("H",inMonthly,0,expandLast);
PML = TimeFrameGetPrice("L",inMonthly,0,expandLast);
Filter = 1;
AddColumn(PMH,"P Month High");
AddColumn(PML,"P Month Low");


attaching image for reference View attachment 43060
hello traders,

is it possible to scan live ticks for option mispricing and arrive at a some calculation to see if there is nett credit or not.

for example,
HDFC BANK FUTURE PRICE - PUT OPTION STRIKE PRICE + PUT PURCHASE AMOUNT - CALL CREDIT = CALCULATED FIGURE

similarly for 10 instruments and whenever i see a nett credit, a signal to place basket of orders (spread) need to be placed. can this be done with amibroker.
 
Hi everyone....Really great to see that people are coming forward to help others.

I have a query with the below code -

Code:
Cond1 = Volume > EMA(Volume, 20) * 2;
Cond2 = Volume < EMA(Volume, 20) * 0.00003;
Buy= Cond1;
Sell= Cond2;
Buy = Exrem (Buy, Sell);
Sell = Exrem (Sell, Buy);
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, shapeHollowDownTriangle, shapeNone),colorRed, 0,H, Offset=-65);
Filter = Buy OR Sell ;
AddColumn(C,"Close");
AddColumn(H,"High");
AddColumn(L,"Low");
AddColumn( Buy, "Buy", 1, colorDefault, IIf( Buy, colorGreen, colorDefault ) );
AddColumn( Sell, "Sell", 1, colorDefault, IIf( Sell, colorRed, colorDefault ) );

I want to explore the stocks with volume > 2x of EMA Volume of last 20 candles. The issue is-
  1. If I am not putting the Exrem lines, I am getting the correct output, but then I am getting more than one signal per day whenever the condition is met (which I don't want).
  2. If I am putting the Exrem lines, I am not getting the correct output.
Request help on this issue. I am running this on hourly timeframe and using amibroker 6.2 version.
 
Hi all my problem is to merge this two afl below. The objective is to create a ribbon color when there are particoular conditions like this filter: red PPO-PercentileRank and buy MACD condition need to be filtered out. Due to a lot of function available on both afl I can't merge it sequencially as I normally doing with other formulas so consequently I'm not albe to create a ribbon color line that has both function/parts of borh formulas. (I also tried to use include function but the issue persist) Here the two afl splitted in sequence (first one is the CM-Laguerre-PPO-PercentileRank-Mkt-Tops-Bottoms Converted by Kelvinhand @20160123) and the other one is the BB macd ehlers (modified by Kevinhand and derek2209 in another forum some year ago) . Plot of macd is included in the dominant cycle formula function, so the MACD I suppose is calculated correctly using the ehlers dominant cycle. I'm using a registered 6.20 amibroker version.
Thanks in adv. for your effort/help.

/****
CM-Laguerre-PPO-PercentileRank-Mkt-Tops-Bottoms
Converted by Kelvinhand @20160123
From: https://jp.tradingview.com/script/ng...-Tops-Bottoms/

****/

pctile = Param("Percentile Threshold Extreme Value, Exceeding Creates Colored Histogram", 90, 1, 999);
wrnpctile = Param("Percentile Threshold Warning Value, Exceeding Creates Colored Histogram", 70, 1,999);
pmShort = Param("PPO Setting - Short", 0.4, 0.1, 100, 0.1);
pmLong = Param("PPO Setting - Long",0.8, 0.1, 100, 0.1);

lkbT = Param("Look Back Period for 'Tops' %Rank is based off of?", 200, 3, 999);
lkbB = Param("Look Back Period For 'Bottoms' %Rank is based off of?", 200, 3, 999);

sl=ParamToggle("Show Threshold Line?", "No|Yes", 1);
swl=ParamToggle("Show Warning Threshold Line?", "No|Yes", 1);


//Laguerre PPO Code from TheLark
function lag(g,p)
{

f[0]=L0[0] = L1[0] = L2[0] = L3[0] = 0;

for(i=1;i<BarCount;i++)
{
L0 = (1-g)*p+g*L0[i-1];
L1 = -g*L0+L0[i-1]+g*L1[i-1];
L2 = -g*L1+L1[i-1]+g*L2[i-1];
L3 = -g*L2+L2[i-1]+g*L3[i-1];
f = (L0+2*L1+ 2*L2 + L3)/6;
}

return f;

}


hl2 = (H+L)/2;

lmas = lag(pmShort, hl2);
lmal = lag(pmLong, hl2);


pctileB = -1*pctile;
wrnpctileB = -wrnpctile;

//PPO Plot
ppoT = 100*(lmas - lmal)/lmal;
ppoB = 100*(lmal - lmas)/lmal;

//PercentRank of PPO
pctRankT = percentrank(ppoT, lkbT);
pctRankB = -1*percentrank(ppoB, lkbB);

//Color Definition of Columns
colT = IIf(pctRankT >= pctile, colorred, IIf(pctRankT >= wrnpctile and pctRankT < pctile, colororange , colorgrey50));
colB = IIf(pctRankB <= pctileB, colorlime, IIf(pctRankB <= wrnpctileB and pctRankB < pctileB, colorgreen , colorgrey50));

//Plot Statements.
SetBarFillColor(colT);
plot(pctRankT,"Tops %Rank Columns", colorLightGrey, styleArea|styleThick, Null, Null, 0, -1);
PlotGrid(IIf(sl and pctile , pctile, Null), colorred, 10,4);
PlotGrid(IIf(swl and wrnpctile , wrnpctile, Null), colorOrange, 10,4);

SetBarFillColor(colB);
plot(pctRankB,"Bottoms %Rank Columns", colorLightGrey, styleArea|styleThick, Null, Null, 0, -1);
PlotGrid(IIf(sl and pctileB, pctileB, Null), colorlime, 10,4);
PlotGrid(IIf(swl and wrnpctileB, wrnpctileB, Null), colorGreen, 10,4);

plotGrid(0, colorGrey40,9, 5);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//BB MACD EHLERS FORMULA AFL (CONVERTED BY KEVINHAND AND MODIFIED BY DEREK2209 - SEPTEMBER 2016 ref. topic here //http://www.traderslaboratory.com/fo...ycle-as-calculated-//by-//otehlers-autocorre/):
//Ehlers Autocorrelation Periodogram for Amibroker (AFL)

/*
Autocorrelation Periodogram
2013 John F. Ehlers
*/

SetBarsRequired(sbrAll);

LPeriod = Param("Low-pass Period", 10, 3, 20);
HPeriod = Param("High-pass Period", 48, 22, 80);
IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1);
IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes");

pi=3.1415926;

function RoofingFilter(lpPeriod, hpPeriod)
{
alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod);
a1 = exp(-1.414*pi / lpPeriod);
b1 = 2*a1*cos(1.414*pi / lpPeriod);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;

HP = Close;
Filt = HP;

for(i = 2; i < BarCount; i++)
{
HP = ((1 - alpha1 / 2)^2)*(Close - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2];
Filt = c1*(HP + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2];
}

return Filt;
}

function AGC(lowerCutoff, higherCutoff, acceptableSlope)
{
factor = 0;
accSlope = -acceptableSlope; //acceptableSlope = 1.5 dB
halfLC = lowerCutoff / 2;
halfHC = higherCutoff / 2;
ratio = 10^(accSlope/20);
if(halfHC - halfLC > 0)
factor = ratio^(1/(halfHC - halfLC));
return factor;
}

function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc)
{
avgLength = 3;
dominantCycle = 0;

//Pearson correlation for each value of lag
for(lag = 0; lag <= 48; lag++)
{
//Set the average length as M
M = avgLength;
if(avgLength == 0)
M = lag;
//Initialize correlation sums
Sx = 0;
Sy = 0;
Sxx = 0;
Syy = 0;
Sxy = 0;
//Advance samples of both data streams and sum Pearson components
for(count = 0; count <= M-1; count++)
{
X = Ref(data, -count);
Y = Ref(data, -(lag + count));
Sx += X;
Sy += Y;
Sxx += X^2;
Syy += Y^2;
Sxy += X*Y;
}
var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2);
VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0)); //Compute correlation for each value of lag
//VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0)); //Scale each correlation to range between 0 and 1
}

/*//Plot as a Heatmap (for scale each correlation to range between 0 and 1)
for(period = 3; period <= 48; period++)
{
corr = VarGet("corrScale" + period);
Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255);
Green = IIf(corr > 0.5, 255, 2*255*corr);
PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel);
}*/

/*
The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest.
The sum of the squares of each of these values represents the relative power at each period.
*/
for(period = 10; period <= 48; period++)
{
cosinePart = 0;
sinePart = 0;

for(n = 3; n <= 48; n++)
{
cosinePart += VarGet("corr" + n)*cos(2*pi*n / period);
sinePart += VarGet("corr" + n)*sin(2*pi*n / period);
}
VarSet("sqSum" + period, cosinePart^2 + sinePart^2);
}

//EMA is used to smooth the power measurement at each period
for(period = 10; period <= 48; period++)
VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2));

//Find Maximum Power Level for Normalization
K = AGC(10, 48, 1.5);
for(period = 10; period <= 48; period++)
{
if(period == 10)
VarSet("maxPwr", 0);
VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr")));
}

//Normalization power
for(period = 10; period <= 48; period++)
VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr"));

//Compute the dominant cycle using the CG of the spectrum
Spx = 0;
Sp = 0;
for(period = 10; period <= 48; period++)
{
Spx += IIf(VarGet("pwr" + period) >= 0.5, period*VarGet("pwr" + period), 0);
Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0);
}
dominantCycle = IIf(Sp != 0, Spx / Sp, 0);
dominantCycle =(dominantCycle);

if(isHeatMap)
{
//Plot as a Heatmap
for(period = 10; period <= 48; period++)
{
pwr = VarGet("pwr" + period);
Red = IIf(pwr > 0.5, 255, 2*255*pwr);
Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0);
PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0);
}
}

if(isDomCyc)
Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1);

pds=LastValue(dominantCycle,1);

//"BB-MACD") Created by KelvinHand

SetChartBkColor( ParamColor("background",colorBlack) );
A1=EMA(C,pds/2)-EMA(C,pds);
BBtop=BBandTop(A1,10,1);
BBbot=BBandBot(A1,10,1);
Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1<Ref(a1,-1),colorCustom12,colorRed)));

Plot(a1,"MACD",color,styleThick+styleLine);
Plot(BBtop,"BBtop",colorWhite,styleDashed);
Plot(BBbot,"BBbot",colorWhite,styleDashed);
Plot(0,"",colorWhite,1);

AddColumn(round(dominantCycle), " DominantCycle", 2.0 , colorRed, colorLightYellow,50) ;


return dominantCycle;


}

filtData = RoofingFilter(LPeriod, HPeriod);
AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle);
 
Can someone please build two additional conditions in the below strategy. The below strategy works really well on Bank Nifty. The attached AFL is missing SL conditions , can someone add that please in the AFL. Also, if possible can u add exploration features of 5 F&O stocks that are with highest volume opened above Previous Day High and 5 stocks with Highest volume opened below Previous Day Low. Thank you!

GapUp and ORB :
_______________
Today's Open > Yesterday's High
And
Current High > Today's High (9.15-9.30 HIgh)
And
Current Close > Today's High (9.15-9.30 High)
Enter a Buy and Keep till 3.15 pm
Stoploss is 9.15- 9.30 Lowest Low
GapDown and ORB :
_________________
Today's Open < Yesterday's Low
And
Current Low < Today's Low (9.15-9.30 Low)
And
Current Close < Today's Low (9.15-9.30 Low)
Enter a sell and Keep till 3.15 pm
Stoploss is 9.15 - 9.30 Highest High


GAP UP & ORB AFL
-----------------------------------------------------------------------------

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();
_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",27,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGold) );
Hor=Param("Horizontal Position",1140,1,1200,1);
Ver=Param("Vertical Position",1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
_SECTION_END();
Plot(V, "Volume", ColorRGB(27, 79, 114),styleHistogram|styleOwnScale|styleThick, 10);
grid_day = Month()!=Ref(Month(),-1);
Plot(grid_day,"",colorLightYellow,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
grid_day6 = Day()!=Ref(Day(),-1);
Plot(grid_day6,"",colorGrey50,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
H1 = Ref(H,-1);H2 = Ref(H,-2);H3 = Ref(H,-3);
L1 = Ref(L,-1);L2 = Ref(L,-2);L3 = Ref(L,-3);
C1 = Ref(C,-1); C2 = Ref(C,-2); C3 = Ref(C,-3);
O1 = Ref(O,-1); O2 = Ref(O,-2); O3 = Ref(O,-3);
BarsSinceOpen = BarsSince(Day() != Ref( Day(), -1 ));
DL = (LLV(L,BarsSince(BarsSinceOpen)));
DH = (HHV (H,BarsSince(BarsSinceOpen)));
PDH = TimeFrameGetPrice( "H", InDaily ,-1);
PDL = TimeFrameGetPrice( "L", inDaily,-1 );
TDO = TimeFrameGetPrice( "O", inDaily);
Plot(pdh,"",colorYellow,styleDashed,Null,Null,0,0,0.25);
Plot(pdl,"",colorYellow,styleDashed,Null,Null,0,0,0.25);
Cond_Gap = TDO > PDH OR TDO < PDL;
p=Param("Bar no",2,2,20,1);
BarsSinceOpen = BarsSince(Day() != Ref( Day(), -1 ));
Tt=(BarsSinceOpen == p);
fWHigh = ValueWhen(tt, HHV(H,3));
fWLow = ValueWhen(tt, LLV(L,3));
Plot(fWHigh,"\nHigh of "+(p-2)+" bar",5,24);
Plot(fWLow,"\nLow of "+(p-2)+" bar",4,24);
BuyR = Cond_Gap AND Cross(C,fWHigh) AND TimeNum() > 092900;
ShortR = Cond_Gap AND Cross (fWLow,C) AND TimeNum() > 092900;
dn = DateNum();
newDay = dn != Ref( dn,-1);
OneTrade = Flip(newDay, Ref(BuyR OR ShortR, -1));
Buy = BuyR AND oneTrade;
Short = ShortR AND OneTrade;
BuyPrice= ValueWhen(Buy,C);
ShortPrice = iIf(Short,C,Null);
ENTRY = IIf(Buy,BuyPrice,IIf(Short,ShortPrice,Null));
Stoploss = IIf(Buy,fWLow,IIf(Short,fWHigh,Null));
dist = 0.5*ATR(10);
dist1 = 2*ATR(14);
for( i = 0; i < BarCount; i++ )
{
if ( Buy )
PlotText( "Buy", i , L[ i ] - dist1, colorDarkGreen, colorYellow ) ;
if (Short)
PlotText( "Sell", i , H[ i ] + dist1, colorRed, colorYellow );
}
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( " ....................................... " , i-1, c[ i ],colorGreen );
if( Short ) PlotText( " ...................................... " , I-1, c[ i ], colorRed );
}
//------Exploration------------------//
Filter= Buy OR Short;
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar );
AddColumn(ENTRY,"ENTRY AT",1.2);
AddColumn(stoploss,"STOPLOSS AT",1.2);
//Shapes
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(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?