Simple Coding Help - No Promise.

Here is another alternative

added to chart
Code:
su = Study( "SU", GetChartID() ); // support

nm         = Name(); 
uniqueID   = "12345";
uniqueName = nm + uniqueID; // static variable of support line depends on symbol and id
StaticVarSet( "SUMaster_" + uniqueName, su); // set static variable dependent on set unique name
StaticVarSetText( "ChartSymbol_" + uniqueID, nm );
Analysis code
Code:
uniqueID = "12345";
nm = StaticVarGetText( "ChartSymbol_" + uniqueID );
uniqueName = nm + uniqueID;

su  = LastValue( Nz( StaticVarGet( "SUMaster_" + uniqueName ) ) );

Close_ = Foreign( nm, "C" );
SUcond = Cross( su, Close_ ); // cross of price below suppport

Filter = Status( "LastBarInRange" );

AddTextcolumn( nm, "Chart Ticker", 1 );
AddTextcolumn( WriteIf( SUcond, "True", "False" ), "Support Line Cross DN", 1 );
Addcolumn( Close_, "Chart Price", 1.2 );
Addcolumn( su, "Support", 1.2 );
Thank you very much Trash and Pratapvb for the solution.

Trash - I was trying out the analysis but it is giving unpredictable results, I mean it is not showing all the stocks (1-2 are missing) which has crossed the support from top. Not sure why it is happening :( I will try with more no of stocks and will let you know the results.

Once again thank you very much for immediate solution!!
 

trash

Well-Known Member
Thank you very much Trash and Pratapvb for the solution.

Trash - I was trying out the analysis but it is giving unpredictable results, I mean it is not showing all the stocks (1-2 are missing) which has crossed the support from top. Not sure why it is happening :( I will try with more no of stocks and will let you know the results.

Once again thank you very much for immediate solution!!
Since you are not precise I can't follow your problem.

As for my !example!
The analysis outputs what is set in the chart. If you have applied the first code in just one chart then only one symbol is being looked at in analysis.

You could use setforeign to set multiple panes one below another one applied on different symbols if you don't wanna open multiple charts. Remember to set uniqueID differently.

If using setforeign then StudyID() function has to be used outside of setforeign.
 
Last edited:
Since you are not precise I can't follow your problem.

As for my !example!
The analysis outputs what is set in the chart. If you have applied the first code in just one chart then only one symbol is being looked at in analysis.

You could use setforeign to set multiple panes one below another one applied on different symbols if you don't wanna open multiple charts. Remember to set uniqueID differently.
Ok, I would like to use this code for EOD analysis. I have 300+ stocks in my watchlist and have drawn the support / resistance line on each chart. Now at eod, I would like to know on which stocks the price has reached near or crossed the support or resistance line, those stocks should appear in exploration result.
I do not want to open all the charts and run the analysis. Hope I am clear now.

so is it possible or is there any alternative way? Thanks!
 

trash

Well-Known Member
I do not want to open all the charts and run the analysis.
That's not possible. Think about it, AmiBroker can not look inside your mind like a magician and guess what's going on there if there is no manually drawn active line available. Then you would have to write some code to define a line for each symbol. See LineArray
 
Included 3 filters:
1) You can set the start and end time
2) The Open for today have to be below yesterday's high day and above yesterday's low
3) You can set the open-y's high and open-y's low minimum difference.

Code:
// Written by: Abhishek Gupta

RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 500;
SetPositionSize(4,spsShares);
SetBarsRequired(100);


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Trading signals");
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);
Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);
StartTime	= ParamTime("Start time", "09:25");
CloseTime	= ParamTime("Closing Time", "15:20");
GapFix		= Param("Minimum stop loss", 0.015, 0, 1, 0.05);
GapFix1	= GapFix/100;

HighY	= TimeFrameGetPrice("High", inDaily, -1);
LowY	= TimeFrameGetPrice("Low", inDaily, -1);

OpenD	= TimeFrameGetPrice("Open", inDaily);
//LowD	= TimeFrameGetPrice("Low", inDaily);
//HighD	= TimeFrameGetPrice("High", inDaily);
xFilter	= BarsSince(Cross(High, HighY))>BarsSince(NewDay) OR BarsSince(Cross(LowY, Low))>BarsSince(NewDay);
LowD	= ValueWhen(xFilter, LowestSince(NewDay, Low));
HighD	= ValueWhen(xFilter, HighestSince(NewDay, High));


Plot(HighY, "Y's H ", ParamColor("Y's High Color", colorYellow), ParamStyle("Y's High Style", styleDashed));
Plot(LowY, "Y's L ", ParamColor("Y's Low Color", colorYellow), ParamStyle("Y's Low Style", styleDashed));
Plot(OpenD, "Day's O ", ParamColor("Day's Open Color", colorRed), ParamStyle("Day's Open Style", styleDashed));
Plot(LowD, "Day's L ", ParamColor("Day's Low Color", colorGreen), ParamStyle("Day's Low Style", styleDashed));
Plot(HighD, "Day's H ", ParamColor("Day's High Color", colorGreen), ParamStyle("Day's High Style", styleDashed));

// Filter time, low and high conditions
Conds		= TimeNum()>StartTime AND TimeNum()<CloseTime AND (OpenD*(1+GapFix1))<HighY AND (OpenD*(1-GapFix1))>LowY;

Buy		= Conds AND OpenD==LowD AND Cross(High, HighY);
Sell	= Cross(TimeNum(), CloseTime) OR Cross(OpenD, Close);
Short	= Conds AND OpenD==HighD AND Cross(LowY, Low);
Cover	= Cross(TimeNum(), CloseTime) OR Cross(Close, OpenD);

Buy		= ExRem(Buy, Sell);
Sell	= ExRem(Sell, Buy);
Short	= ExRem(Short, Cover);
Cover	= ExRem(Cover, Short);

BuyPrice		= ValueWhen(Buy, Close);
ShortPrice		= ValueWhen(Short, Close);
CoverPrice		= ValueWhen(Cover, Close);
SellPrice		= ValueWhen(Sell, Close);


dist	= 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
	if (Cover[i]) {
		PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
		PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if (Sell[i]) {
		PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
		PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
	}
	if(Buy[i]) {
		PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if( Short[i]) {
		PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
 	}
}

PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);

printf("\nSignal came " + IIf(BarsSince(Short)>BarsSince(Buy), BarsSince(Buy), BarsSince(Short)) + " bars ago");
WriteIf(BarsSince(Short)>BarsSince(Buy), "\nBuy@ " + BuyPrice, "\nShort@ " + ShortPrice);

printf("\nPossiblities ");
printf("\nMax Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (HighD-BuyPrice), (ShortPrice-LowD)));
printf("\nMin Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (OpenD-BuyPrice), (ShortPrice-OpenD)));


// Write Messages
printf("\n\nLet the profit run.");
printf("\nClose a call only when trailing SL hits");
_SECTION_END();
Abhi,

Thanks for your efforts, when i tried it, it plots yeterday's range and today's open and range. I do not see any buy/sell arrows and also there is no results in backtest.

i have tried in all different time frames, still entry/exit arrows are not getting plotted and buy/sell price doesn't show up in backtest

 

trash

Well-Known Member
Thank you very much Trash and Pratapvb for the solution.

Trash - I was trying out the analysis but it is giving unpredictable results, I mean it is not showing all the stocks (1-2 are missing) which has crossed the support from top. Not sure why it is happening :( I will try with more no of stocks and will let you know the results.

Once again thank you very much for immediate solution!!
Also keep in mind that Cross is not equal to Close < Line or Close > line.

Cross bar is a bar that is touching a line.
 
That's not possible. Think about it, AmiBroker can not look inside your mind like a magician and guess what's going on there if there is no manually drawn active line available. Then you would have to write some code to define a line for each symbol. See LineArray
Thanks Trash, I wish it could read my mind ;)
I do not have expertise in writing AFLs, can write basic AFL code. The alternative way could be to open multiple windows. I can do this way -
1. Open all stock charts in separate window (one time tedious task) and save that layout so i can use same again & again to run analysis.
2. After that run analysis, save results in a watchlist and change the layout. I tried it with six stocks open in separate windows and it's working so I will try with all stocks. Appreciate your help, thanks again..:)
 

amitrandive

Well-Known Member
Hi All

Below exploration for ORB works only for 15 min,30 min or Hourly basis.

How can I make it work for 5 min or 10 min?:confused:

Code:
_SECTION_BEGIN("Intraday ORB Exploration");
 
SetChartOptions( 0, chartShowArrows | chartShowDates );
//("ORB");
 
BT = ParamTime ("Open Breakout Time", "09:15");
afterbreakout0 = Cross(TimeNum(),BT);
afterbreakout1 = TimeNum()>=BT;
NewDay = Day()!= Ref(Day(), -1);
highestoftheday = HighestSince(newday,H,1);
Lowestoftheday =LowestSince(newday,L,1);
ORBH = ValueWhen(afterbreakout0,highestoftheday,1);
ORBL = ValueWhen(afterbreakout0,lowestoftheday,1);
ORBM = (ORBH + ORBL)/2;
Plot(ORBH,"",colorGreen,styleDots);
Plot(ORBL,"",colorRed,styleDots);
Plot(ORBM, "", colorBlack, styleDots);
Plot ( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
ORBHG=H-ORBH;
ORBLG=ORBl-L;
Filter = ORBH OR ORBL;
AddColumn( ORBH, "C>ORBH", 1.2, colorDefault, IIf(Close>ORBH, colorGreen, IIf(Close>ORBM, colorSeaGreen, colorDefault)));
AddColumn( ORBL, "C<ORBL", 1.2, colorDefault, IIf(Close<ORBL, colorRed, IIf(Close<ORBM, colorOrange, colorDefault)));
AddColumn( ORBHG, "ORB High Breakout Gain", 1.2, colorDefault, IIf(ORBHG>0, colorGreen, colorDefault));
AddColumn( ORBLG, "ORB Low Breakout Gain", 1.2, colorDefault, IIf (ORBLG>0, colorRed, colorDefault));
Any help ??:confused:
 

Similar threads