[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Working Code for "if (Buy[i] >= 0) not behaving as expected" message



PureBytes Links

Trading Reference Links

Well folks, here is the working code. Excuse my illiteracy with programming, and thanks for all the help.

The way I use it is:
EOD data - becasue of the AddToComposite
Indicator - plot all tickers that meet crieria within a specific list
Explore - review the RSI and ROC of each ticker.

Try it out:
1) In AutoAnalysis, Run SCAN against specific list (Apply To) to build ~sumROC and ~sumRSI composites stored in Group 253
2) In AutoAnalysis, Run Explore to review Buy, Sell, Scores, etc.(using the same list of course)
3) Plot Indicator of list (use Parameters) and only those meeting the criteria plot in Relative Performance

>From my original needs, I was wanting to see how TRA (Terra Industries) was doing in relation to all other in the Industry - Agricultural Chemicals.
Essentially wanting to choose the better half of any industry based on my criteria of RSI and ROC.

_SECTION_BEGIN("Relative Performance ALL");
Category 			= "";
function ParamCategory() // This is the main category where we look for our list
{
 global CategoryList; 
 CategoryList		= "Market   ,Group    ,Sector   ,Industry ,Watchlist,Favorite ,Index    ";
 Tickercategory	= ParamList("Ticker category", "Market|Group|Sector|Industry|Watchlist|Favorite|Index",3); // set to 3 for Industry
 Category 			= TickerCategory;
 TickerCategory	= (StrFind( CategoryList, Tickercategory)-1)/10;
 return TickerCategory;
}

function ParamListNum(Category ) // This is where we find the List Number
{
 global ListNum;
	ListNum 		= Param("List Number", 4, 0, 255, 1); // set to 4 for Agricultural Chemicals
 return ListNum;
}

TickerCategory 	= ParamCategory();
TickerListNum 	= ParamListNum(TickerCategory);
CategoryListOK	= IIf(StrLen(CategoryGetSymbols(TickerCategory, TickerListNum)) > 0, 1, 0);
ManualRefresh		= ParamTrigger( "Manual Refresh:", "REFRESH NOW");
ListName			= CategoryGetName(Tickercategory,ListNum);
Title1				= ListName + " - " + ListNum + " - ";
Tickerlist			= CategoryGetSymbols(Tickercategory, ListNum);
_SECTION_END();

_SECTION_BEGIN("Composite Calculation"); // for Explore
// Rxxt = of the Ticker
 periods			= Param("Periods",14,1,50,1);
 ROCt				= ROC (C, periods );
 RSIt				= RSI (periods);
 AddToComposite(ROCt,"~sumROC","X",7); AddToComposite(1,"~sumROC","V",7);
 AddToComposite(RSIt,"~sumRSI","X",7); AddToComposite(1,"~sumRSI","V",7);
// Rxxc = of the Composite
 ROCc				= ROC(Foreign("~sumROC","Close"),periods); // not what I thought
 RSIc				= RSIa(Foreign("~sumRSI","Close"),periods);
_SECTION_END();

_SECTION_BEGIN("Buy Sell Deal"); // for Explore
// Buy Sell criteria
Buy					= IIf(ROCt > 0 AND RSIt > RSIc, 1, 0);
Sell				= IIf(ROCt < 0 AND RSIt < RSIc, -1, 0);
Deal				= IIf(Buy == 1, 1, IIf (Sell == -1, -1, 0));
_SECTION_END();

_SECTION_BEGIN("Relative Performance Calculations"); // for Plotting
//NumBars			= 20; // don't need this
fvb = Status("firstvisiblebar");
Plot( 100 * ( C - C[ fvb ] ) / C[ fvb ], Name(), colorRed, styleThick | styleDots);

fc					= "";
result				= "";
RSIValue 			= "";
function MyPlot(fc,TopHalf) // used to control which plots are drawn
{
RSIValue			= Param("RSI Valuelevel",50,0,100,1);
//TopHalf			= IIf(RSIa(fc,14) > RSIValue, 1, -1);
Tophalf 			= IIf(ROC(fc,periods) > 0 AND RSIa(fc,periods) > RSIc, 1,
					  IIf(ROC(fc,periods) < 0 AND RSIa(fc,periods) < RSIc, -1,0));
return (TopHalf[BarCount -1] == 1 );
}

function ShouldPlot(price, fvb) // original - keep for quick retest
{
return (fc[fvb] >= 35);
}

TopHalf					= 0;
fvb					= Status("firstvisiblebar");
for( i = 0; ( sym = StrExtract( TickerList, i ) ) != ""; i++ )
{
	fc = Foreign(sym, "Close");
//	if (ShouldPlot(fc,fvb)) // original - keep for quick retest
	if (MyPlot(fc,TopHalf))
	{
	Plot( 100 * ( fc - fc[ fvb ] )/ fc[ fvb ], sym, colorLightOrange + ( (2*i) % 15 ), styleLine );
	}
}

_SECTION_END();

_SECTION_BEGIN("Outputs");
Filter				= 1;
SetChartOptions(2,chartShowDates | chartWrapTitle );
_N( Title = "{{NAME}} {{DATE}} - Relative Performance [%]: {{VALUES}}" );
// Columns
AddColumn (C,"Close");
AddColumn (Foreign("~sumROC","Close"),"sumROC");
AddColumn (Foreign("~sumRSI","Close"),"sumRSI");
AddColumn (ROCt,"ROC",1.2,colorDefault,colorDefault,40);
AddColumn (RSIt,"RSI",1.2,colorDefault,colorDefault,40);
AddColumn (ROCc,"CompROC",1.2,colorDefault,colorDefault,60);
AddColumn (RSIc,"CompRSI",1.2,colorDefault,colorDefault,60);
AddColumn(Deal,"Buy/Sell",colorDefault, IIf(Buy ==1, colorGreen, IIf(Sell == -1, colorRed, colorDefault)));
// Scoring
Score1			= (RSIt + ROCt) * Deal;
Score2			= (RSIt + ROCt);
AddColumn (Score1,"Score1",1.2,colorDefault,colorDefault,40);
AddColumn (Score2,"Score2",1.2,colorDefault,colorDefault,40);
// Write to commentary window
EnableTextOutput(True); 
SetSortColumns(-10,1);
_SECTION_END();






------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/