Simple Coding Help - No Promise.

amitrandive

Well-Known Member
Code:
// Pattern 1 ----

A1 = Cross(KBot,C);
A2 = Cross(C,KBot);
Alert01 = Ref(A1,-1) and A2;


// Pattern 2 ----
B1 = Cross(C, KTop);
B2 = Cross(KTop,C);

Alert02 = Ref(B1,-1) and B2;

PlotShapes(Alert01*1,colorWhite,0,L,-12);
PlotShapes(Alert02*2,colorWhite,0,H,-12);

Try and see if this is what you need.
Have plotted arrows you can paste code to give sound alerts or change candle color etc

Thanks



Happy :)
Thanks Happyji

Helpful as everytime.:clapping:
 
Hi I have afl of nr7 can I merge with other afl like filter all those stocks which are in nr7 with orb and super trend buy signal I have afl of all these so I need to club and filter stocks with 3 conditions
 

josh1

Well-Known Member
Code:
// Pattern 1 ----

A1 = Cross(KBot,C);
A2 = Cross(C,KBot);
Alert01 = Ref(A1,-1) and A2;


// Pattern 2 ----
B1 = Cross(C, KTop);
B2 = Cross(KTop,C);

Alert02 = Ref(B1,-1) and B2;

PlotShapes(Alert01*1,colorWhite,0,L,-12);
PlotShapes(Alert02*2,colorWhite,0,H,-12);

Try and see if this is what you need.
Have plotted arrows you can paste code to give sound alerts or change candle color etc

Thanks



Happy :)
Ha Ha.. Was it so simple? I was able to code up to alert but became blank after that. It seems I have lost ability to code in AFL while learning C++ and AHK.
Thank god that Happy Singh is alway there to help. :thumb:
 
hello all and thanks

this code is overally chart diffrent time frame

can anyone convert this code to overally diffrent timeframe rsi , this is very usefull thanks

many many thanks
Code:
_SECTION_BEGIN("2 Timeframes Candlestick Bar Chart");
// Specially designed for use in day trading and to save chart space. This chart will displays 2 sets
// of candlestick bars. One for the time interval set for your chart- for example 1 Minute. 
// The higher timeframe candlestick bars are created by using gfx low-level graphics AND will display  
// according to the parameters you set- for example 5 minutes. 

// I got the idea from David's (dbwyatt_1999) 2 Timeframe chart code which was shared by him on the AmiBroker List. 
// It uses TimeFrame functions with the PlotOHLC function using styleCloud. So I was thinking it would look 
// very nice using low-level graphics instead. Little bit more complicated, but I got a few great pointers from Herman!

// If your chart background turns pink- please read the error message in the upper left corner of the chart.
// Then please observe this AFL code uses ColorBlend(ColorFrom, ColorTo, Factor) which was introduced in Version 5.21 beta.
// The rules are simple- time frames from 1 up to 60 minutes AND Lower time frame must be smaller than the Higher time frame.

Version(5.21); 
SetChartOptions(2, chartShowDates);
Title = Name();
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PARAMETERS AND SETTINGS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ChartLum 		= Param("Chart Background Color Intensity", 0.40, 0, 1, 0.01);
TFMinShort		= Param("Short Timeframe (Minutes)", 1, 1, 60, 1);
TFMinLong 		= Param("Long Timeframe (Minutes)", 5, 1, 60, 1);
OnSTFBars		= ParamToggle("Short 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("Long TF Bar Color Intensity", 0.70, 0, 1, 0.01);

SetChartBkColor(ColorBlend(colorLightBlue, colorWhite, ChartLum));
// Bar Colors for the Short Timeframe candlestick bars:
LineColor 		= ColorBlend(colorBlack, colorWhite, BarLum1);
UpBarColor		= ColorBlend(colorBrightGreen, colorWhite, BarLum1);
DnBarColor		= ColorBlend(colorRed, colorWhite, BarLum1);
// Bar Colors For The Long Timeframe candlestick bars:
TFLineColor 	= ColorBlend(colorBlack, colorWhite, BarLum2 - 0.1);
TFUpBarColor	= ColorBlend(colorBrightGreen, colorWhite, BarLum2);
TFDnBarColor	= ColorBlend(colorRed, colorWhite, BarLum2);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FUNCTIONS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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 ) ); 
} 

StaticVarKey = Name();
procedure xStaticVarSet(SName, SValue)
{
 global StaticVarKey;
 if (StaticVarKey != "")
 	StaticVarSet(Sname + StaticVarKey, Svalue);
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// MAIN PROGRAM:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if(Interval() != TFMinShort * 60)
{
 Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "Set the chart time Interval to: " + NumToStr(TFMinShort, 1.0, 1) + 
					" Minute(s) or change the Short Timeframe Parameter setting.";
 OnSTFBars		= 0;
 OnLTFBars		= 0;
 SetChartBkColor(colorRose);
} 

if(TFMinShort >= TFMinLong)
{
 Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "The Long
Timeframe setting must be longer than the Short Timeframe!";
 OnSTFBars		= 0;
 OnLTFBars		= 0;
 SetChartBkColor(colorRose);
}

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

TFSec = in1Minute * 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 			= Max(TFOpen, TFClose); 
CandleBottom		= Min(TFOpen, TFClose); 
//============================================================================
// GFX LOW-LEVEL GRAPHICS SECTION.
// DRAWING THE LONG TIMEFRAME CANDLESTICK BARS:
//============================================================================
if(OnLTFBars)
{ 
 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);

 // DRAW BAR HISTORY AND THE CURRENT BAR:
 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:
   GfxSelectPen(TFLineColor, 0);
   FillColor = IIf(TFOpen[i + fvb] < TFClose[i + fvb], TFUpBarColor,TFDnBarColor);
   GfxSelectSolidBrush(FillColor); 
   if(y1 == y2){y1 = y1 - Adjust; y2 = y2 + Adjust;
	GfxSelectSolidBrush(TFLineColor);}
   if(x1 > 0){
   		GfxRectangle( x1, y1, x2, y2); 
   		// Candle High and Low:
   		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); 
	}
 } 
}
_SECTION_END();
 

bunti_k23

Well-Known Member
Hi I have afl of nr7 can I merge with other afl like filter all those stocks which are in nr7 with orb and super trend buy signal I have afl of all these so I need to club and filter stocks with 3 conditions
:)yes ,its possible .copy all the codes into 1 afl then replace buy/sell of all the afls with any xyz name except 1 afl .then put ,

buy = ......AND xyz AND pqr;
sell = ......AND abc AND asd;

by this method u can filter out as many systems as u want...if u want to use signals from both the systems just use 'OR' instead of 'AND'....:thumb:
 
I want the stock in nr7 EOD and strategy recently developed by 5 min setup should be clubbed
Code:
_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;

for(i = 7; i < BarCount; i++)
{
if( R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] AND R[i] < R[i - 4] AND R[i] < R[i - 5] AND R[i] < R[i - 6]) 
{
NR7[i] = True;
m7[i] = 1;
}
}

for(i = 4; i < BarCount; i++)
{
if((R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] ) AND NOT NR7[i])
{
NR4[i] = True;
m4[i] = 1;
}
}
IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();
idm7 = IIf(IDNR7, 1, 0);
idm4 = IIf(IDNR4, 1, 0);
idm = IIf(id, 1, 0);

for(i = 1; i < BarCount; i++)
{
if(IDNR7[i] == IDNR7[i - 1]) idm7[i] = idm7[i] + idm7[i - 1];
if(IDNR4[i] == IDNR4[i - 1]) idm4[i] = idm4[i] + idm4[i - 1];
if(NR7[i] == NR7[i - 1]) m7[i] = m7[i] + m7[i - 1];
if(NR4[i] == NR4[i - 1]) m4[i] = m4[i] + m4[i - 1];
if(ID[i] == ID[i - 1]) idm[i] = idm[i] + idm[i - 1];
}

MarkerIDNR7 = MarkerIDNR4 = shapeStar ;

Marker7 = shapeDigit7;
NR7Color = colorBrightGreen;

Marker4 = shapeDigit4;
NR4Color = colorLightOrange;

MarkerID = shapeHollowCircle;
IDColor = colorYellow;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

MarkerDist = L * 0.995;
IDNRDist = H * 1.03;

if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}, {{DATE}} ({{INTERVAL}}): {{VALUES}}") + ", Range=" + Prec(R + 0.00001, 2) + "," 
+ WriteIf(IDNR7, EncodeColor(colorBrightGreen) + WriteIf(idm7 > 1, StrLeft(NumToStr(idm7), 4), "") + " IDNR7 ", "")
+ WriteIf(IDNR4, EncodeColor(colorLightOrange) + WriteIf(idm4 > 1, StrLeft(NumToStr(idm4), 4), "") + " IDNR4 ", "") 
+ WriteIf(NR7 AND NOT ID, EncodeColor(colorBrightGreen) + WriteIf(m7 > 1, StrLeft(NumToStr(m7), 4), "") + " NR7 ", "")
+ WriteIf(NR4 AND NOT ID, EncodeColor(colorLightOrange) + WriteIf(m4 > 1, StrLeft(NumToStr(m4), 4), "") + " NR4 ", "")
+ WriteIf(ID AND NOT NR7 AND NOT NR4, EncodeColor(colorTurquoise) + WriteIf(idm > 1, StrLeft(NumToStr(idm), 4), "") + " Inside Day ", ""));

PlotOHLC(O, H, L, C, "Close", colorLightGrey, styleBar);
PlotShapes(IIf(IDNR7, MarkerIDNR7, shapeNone), IDNR7Color, 0, IDNRDist);
PlotShapes(IIf(IDNR4 AND NOT IDNR7, MarkerIDNR4, shapeNone), IDNR4Color, 0, IDNRDist);
PlotShapes(IIf(NR7 AND NOT ID, Marker7, shapeNone), NR7Color, 0, MarkerDist);
PlotShapes(IIf(NR4 AND NOT NR7 AND NOT ID, Marker4, shapeNone), NR4Color, 0, MarkerDist);
PlotShapes(IIf(ID AND NOT NR7 AND NOT NR4, MarkerID, shapeNone), IDColor, 0, IDNRDist);
}

if(Status("action") == actionExplore)
{
Filter = (m7 > 0) OR (m4 > 0) OR (idm > 0);

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "DATE", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 120);
AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
AddColumn(IIf(idm, 48 + idm, 32), "INSIDE", formatChar, colorYellow, IIf(idm, colorLightBlue, colorDefault));
AddColumn(IIf(m4, 48 + m4, 32), "NR4", formatChar, colorYellow, IIf(m4, colorBlue, colorDefault));
AddColumn(IIf(m7, 48 + m7, 32), "NR7", formatChar, colorYellow, IIf(m7, colorGreen, colorDefault));
}

/************************** END OF AFL CODE *****************************/

_SECTION_END();


/*********************************************/

Those stocks in nr7 filtered and apply this afl as a scanner to buy
 
Last edited by a moderator:

Similar threads