Simple Coding Help - No Promise.

pratapvb

Well-Known Member
Hi,

I wanted small help from veteran members. I want to Scan Daily Top 20 Gainers and Losers from Specific Group or Watchlist in Amibroker. I have created a watchlist for CNX Nifty 500 stocks and want to know on daily basis top 20 gainers and loser stocks.

from wisetrader site i found following code, but it is not working out. I am not good at coding, so seek your help.

//////////////////////////////////////////////////////////
_SECTION_BEGIN("IntradaySuRe");
pchng = (C - Ref(C,-1)) /( Ref(C,-1) * 100);
pchng=ROC(C,1);
Filter = pchng;
AddColumn(Close, "Close Price",1);
AddColumn(pchng, "Percent Change",1 ,textcolor=IIf( Ref(C,- 1)>C,colorRed,colorGreen));
_SECTION_END();

Also if possible, please do the programming in such a way that Top 20 Gainers and Losers can be generated for Weekly also.

This would be of great help.. and Thanks in advance. :thumb:
what does this do? I think it will just list all the % gains....maybe then you can use column sort to arrange them in desending (gains) or ascending (losers) order?

and for weekly you could just use Weekly period in scan parameters

I have not tried above...just guessing based on code....if still problem then mention here
 

josh1

Well-Known Member
The following code identifies Demandpoint and Supply point as (H and L). Candle immediately after a demand point is Yellow and that immediately after Supplypoint is Purple.

I want to raise -
Buy - when price crosses 3 points above yellow candle but before next demand or supply point
Sell - when price crosses 3 points below purple candle but before next demand or supply point



Code:
colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));
GraphXSpace = 10;

_SECTION_BEGIN("Demand/Supply Point");
/*
Demand Point is that Bar whose Low is lower than the Low of two bars immediately before AND ahead it AND 
its Low may be equal to the Low of previous bar (to cover case of double bottom).
*/
//nbar=Param("N Pivot Bars",3,2,50,1); 

DemandPoint = (L < Ref(L, -2)  & L <= Ref(L, -1) & L < Ref(L, 1) & L < Ref(L, 2) ); //returns true/false
BuyP = 0;

//DemandPoint = L<Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar)>=L;

//Colour of Demand Line is user defined. Default is  ColorRGB(0, 128, 255) i.e.blueish
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));

// Supply Point is that Bar whose High is Higher than the High of two bars immediately before and ahead it and 
// its High may be equal to the High of previous bar (to cover case of double top).

SupplyPoint = (H > Ref(H, -2) & H >= Ref(H, -1) & H > Ref(H, 1) & H > Ref(H, 2) ); //returns True/false
SellP = 0;

//SupplyPoint = H>Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar)<=H;
//Colour of Supply Line is user defined. Default is  ColorRGB(255, 128, 0) i.e. Orange.
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
_SECTION_END();


_SECTION_BEGIN("Plot Trend Lines");

/* 
Trend Lines are drawn by joining two Demand Points (dx0 and dx1) or two Supply points (sx0 and sx1).
Where x0, x1 are on Time axis and y0, y1 are on price axis. 
Demand line is closed when a candle closes below it. Supply line is closed when a candle closes above it. 
A Trend Lines is extended until it is closed by any candle.
In this section we identify these points AND then Plot TLs. These points are initialsed as 0 in the beginning.
*/

CountTrendBars = 0;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;
LVB= Status("lastvisiblebar"); //Inserted by Josh1

//-- Modified by KelvinHand and later by Josh1----------- to plot only on visible chart
function VisiBarsPerChart()
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    return Min(lvb-fvb,BarCount-fvb);
}


nBars=1.5*VisiBarsPerChart(); 
if (nBars <LVB)
 iLimit = (LVB) - nBars+2;
else
 iLimit = 2; // end change by Josh1

//------------------------------------
  
//_TRACE( "LVB = "+NumToStr(LVB,1.0) );
//_TRACE( "Barcount = "+NumToStr(BarCount,1.0) );

 
// Next line changed by Josh1 since LVB includes blank bars. Now we get dynamic range from LVB to iLimit.
for (i = IIf(LVB>(BarCount-1),BarCount-1,LVB); i>iLimit; i--) {   
	if (DemandPoint[i]) {
		if (dx1 == 0 & dy1 == 0) {
			dx1 = i;  //
			dy1 = L[i];
		PlotText( "HL", i, L[ i ]-3, colorPink );  // Identify the demand point by as "HL" meaning low.

		} else {
			dx0 = i;
			dy0 = L[i];
		PlotText( "L", i, L[ i ]-3, colorPink );  // Identify the demand point by as "L" meaning low.
		colorHighliter[i+1] = ColorRGB(128, 128, 0); // // Highlight next candle with Yellow colour
		}

		if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
			if (dy0 < dy1) {    // 
				a = (dy0 - dy1) / (dx0 - dx1); // We calculate a = the slope of TL 
				b = dy0 - dx0 * a;   // This gives displacement on Y axis
				for (j = dx1; j < BarCount; j++) { 
					if (j != dx1) {
						y2 = a * j + b;
						if (C[j] < y2) {
							dy1 = y2;
							dx1 = j;
// Highlight candle breaking below demand line with Purple colour
//							colorHighliter[j] = ColorRGB(128, 0, 128); 
							CountTrendBars[j] = dx1 - dx0 - 1;
							break;
						}
					}
				}
				if (dy1 != y2) {
					dy1 = y2;
					dx1 = BarCount - 1; 
				}
				Plot(LineArray(dx0, dy0, dx1, dy1, 0), "", colorDemandPoint, styleLine|styleThick, Null, Null, 0, 2);

			}
			dx1 = dx0;
			dy1 = dy0;
			dx0 = dy0 = 0;
		}	
	}
	if (SupplyPoint[i]) {
		if (sx1 == 0 & sy1 == 0) {
			sx1 = i;
			sy1 = H[i];
		} else {
			sx0 = i;
			sy0 = H[i];
		PlotText( "H", i, H[ i ]+3, colorPink );  // Identify Supply point as "H" meaning high
							colorHighliter[i+1] = ColorRGB(128, 0, 128); // Identify next candle with Purple colour.
		}

		if (sx0 != 0 & sx1 != 0 & sy0 != 0 & sy1 != 0) {
			if (sy0 > sy1) {
				a = (-sy0 + sy1) / (-sx0 + sx1);
				b = sy0 - sx0 * a;
				for (j = sx1; j < BarCount; j++) { 
					if (j != sx1) {
						y2 = a * j + b;
						if (C[j] > y2) {
							sy1 = y2;
							sx1 = j;
// Highlight candle breaking above Supply line with Yellow colour
//							colorHighliter[j] = ColorRGB(128, 128, 0);
							CountTrendBars[j] = sx1 - sx0 - 1;
							break;
						}
					}
				}
				if (sy1 != y2) {
					sy1 = y2;
					sx1 = BarCount - 1; 
				}
				Plot(LineArray(sx0, sy0, sx1, sy1, 0), "", colorSupplyPoint, styleLine|styleThick, Null, Null, 0, 2);
			}
			sx1 = sx0;
			sy1 = sy0;
			sx0 = sy0 = 0;
		}	
	}
}

_SECTION_END();

//Price
SetBarFillColor(colorHighliter);
Plot(C, "Close", IIf(colorHighliter == ColorRGB(128, 0, 128), ColorRGB(255, 0, 255), IIf(colorHighliter == ColorRGB(128, 128, 0), ColorRGB(255, 255, 0), IIf(C > O, ColorRGB(0, 255, 0), IIf(C < O, ColorRGB(255, 0, 0), ColorRGB(255, 255, 255))))), styleCandle, Null, Null, 0, 1);

Title = "Trendline-Break +SRS  " + Name() + " - " +Interval()/60 +" Min -" + Date() + "-  Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) + 
EncodeColor(colorYellow)+ ", Close = " + NumToStr(C, 1.2) ;
 
hello,

can anyone code an AFL which shows chart from friday (first day of new expiry month) to the last Thursday of the same month??

basically i want the chart to show a single Bar of the entire month based on expiry days.

for example as the Feb series stared on 31st jan and will run till 26th feb, the chart must plot on this logic...

thanks

Regards
CA. Ritesh Bafna
anyone... pls...
 
Are you sure you write that code in VBScript !!!:D

007 must associate with J......................................................................................................................................................................Script.
Kelvin, Nice one!!!

Jokes aside, JScript is synonymous with VBScript at least in Windows world...
 

pratapvb

Well-Known Member
can i run 2 or more instances of amibroker on same system with different realtime data?
have you tried from diff drives?
 
_SECTION_BEGIN

x = EMA(Close,5);
y = EMA(Close,13);

Buy=Cross(x,y);
Sell=Cross(y,x);

PlotShapes(shapeUpArrow*Buy,colorGreen);
PlotShapes(shapeDownArrow*Sell,colorRed);

Plot(EMA(Close,5),"",colorBrightGreen,styleLine);
Plot(EMA(Close,13),"",colorRed,styleLine);

Cover = Buy;
Short = Sell;

_SECTION_END();

the above code is simple ema crossover system. how to add stoploss as per my requirement.

stoploss= when my trade will be in 0.5% profit.. fixed stoploss should be cost to cost at buy or sell signal.. can anyone help..
 
can i run 2 or more instances of amibroker on same system with different realtime data?
Yes, As long as they are not on same database and you are able to get your feeding application to correctly identify the AMI instance that it should be connected with.
 
_SECTION_BEGIN

x = EMA(Close,5);
y = EMA(Close,13);

Buy=Cross(x,y);
Sell=Cross(y,x);

PlotShapes(shapeUpArrow*Buy,colorGreen);
PlotShapes(shapeDownArrow*Sell,colorRed);

Plot(EMA(Close,5),"",colorBrightGreen,styleLine);
Plot(EMA(Close,13),"",colorRed,styleLine);

Cover = Buy;
Short = Sell;

_SECTION_END();

the above code is simple ema crossover system. how to add stoploss as per my requirement.

stoploss= when my trade will be in 0.5% profit.. fixed stoploss should be cost to cost at buy or sell signal.. can anyone help..
Add following

ApplyStop(0, 1, 0.5, 0, true, 1);
 
Add following

ApplyStop(0, 1, 0.5, 0, true, 1);
thanks for reply. this is just fixed stop loss. what i want is different. suppose i got buy signal at 6000 when price moves to 6030 that means i am in 0.5% profit. now stop loss should be at buy signal 6000 ( fixed stop loss ) and vice versa for short signal. is it possible ?
 

Similar threads