Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
i want to export my ieod data for a specific date range , i have tried by below afl , which is posted by anant sir , but it is not giving data , it is only showing starting date of databse , plz , can any one correct this afl or can post a afl to export ieod data ...........to csv or txt
for a specific date range .......
try this

//The easiest way to export quotes to CSV file is to use the below formula from Automatic Analysis window:
//(Analysis -> Automatic Analysis)
// In Automatic Analysis window select Apply to: All Stocks, Range: All quotations (or any other time range or filter, depending on what you need to export)
// Press Explore button
// Press File, Export and save csv file


Filter=1;
AddColumn(O,"Open");
AddColumn(H,"High");
AddColumn(L,"Low");
AddColumn(C,"Close");
AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0);
 

Nehal_s143

Well-Known Member
also try this

/*
Export intraday and EOD data to TXT files
One file for each stock
In the first line insert the directory you want to save them to, make sure the
directory exists
Select your charts to export with the "Apply to" filter in AA window
Select the timeframe period you want to save as using the AA "Settings"
Press Scan button
by Graham Kavanagh 05 Feb 2004
*/

fh = fopen( "C:\\Program Files\\Amibroker\\"+Name()+".txt", "w");
if( fh )
{
fputs( "<ticker>,<date>,<time>,<open>,<high>,<low>,<close>,<vol>\n",
fh );
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
n = Second();

for( i = 0; i < BarCount; i++ )
{
fputs( Name() + "," , fh );
ds = StrFormat("%02.0f%02.0f%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

ts = StrFormat("%02.0f:%02.0f:%02.0f,",
r[ i ],e[ i ],n[ i ] );
fputs( ts, fh );

qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}

fclose( fh );
}

Buy = 0;
 

Nehal_s143

Well-Known Member
For EOD data

/*
Export intraday and EOD data to TXT files
One file for each stock
In the first line insert the directory you want to save them to, make sure the
directory exists
Select your charts to export with the "Apply to" filter in Automatic Analysis window
Select the timeframe period you want to save as using the Automatic Analysis "Settings"
Press Scan button
by Graham Kavanagh 05 Feb 2004
*/

fh = fopen( "d:\\msdata.txt", "a");
if( fh )
{
fputs( "<ticker>,<name>,<per>,<date>,<open>,<high>,<low>,<close>,<vol>\n",
fh );
y = Year();
m = Month();
d = Day();

for( i = 0; i < BarCount; i++ )
{
fputs( Name() +","+ Name() +",d," , fh );
ds = StrFormat("%02.0f%02.0f%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );



qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}
fclose(fh);
}
Buy=0;
 

Nehal_s143

Well-Known Member
one more method, hope out of this 4 methods, at-list 1 will work for you :)

Turnover = C*V; Filter = 1;
/* all symbols and quotes accepted */
AddTextColumn(FullName(),"Full name");
AddColumn(High,"HIGH",1.2);
AddColumn(Low,"LOW",1.2);
AddColumn(Close,"CLOSE",1.1);
AddColumn(Volume,"Volume",1.1);
AddColumn(OI,"Open Int",1.1);
 

KelvinHand

Well-Known Member
i want to export my ieod data for a specific date range , i have tried by below afl , which is posted by anant sir , but it is not giving data , it is only showing starting date of databse , plz , can any one correct this afl or can post a afl to export ieod data ...........to csv or txt
for a specific date range .......
Ask youself this question:
Did you create a directory folder => c:\SaveData\ ?

If not, create it.
 

mcxinvest

Well-Known Member
hello,
can anyone help me in coding the below strategy. Main coding is with exit/trailstoploss.

Buy = crossover of MA 25 to MA 50
Sell = SAR hits the price.

here I required is, the SAR should start once there is a cross over of MA's.
i.e the starting point of SAR should be at the time when buy/short calls are triggered.
 
hello,can anyone tell me the Methods for speeding up AFL code ?
I want to calculate all past k-bar data once in market open time and never calculate the same thing twice.
I had try this way but it will change backtest result and take up PC memory very much
Thank you for any further help you can suggest.


result =0;
if( market_open_time=="1" )
{
A=A+B+C+..........................................;
result = A;
StaticVarSet("m_result",result );



}
result=StaticVarGet("m_result " );
 
Last edited:

Nehal_s143

Well-Known Member
hello,
can anyone help me in coding the below strategy. Main coding is with exit/trailstoploss.

Buy = crossover of MA 25 to MA 50
Sell = SAR hits the price.

here I required is, the SAR should start once there is a cross over of MA's.
i.e the starting point of SAR should be at the time when buy/short calls are triggered.
_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{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", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 25, 30, 100, 5);
ShortPer = Param("Short Period", 50, 30, 100, 5);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Buy = Cross(LongMA, ShortMA);
Short=SAR( acc, accm )>C;
Sell = Cross(ShortMA, LongMA);
Cover=SAR( acc, accm )<C;

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

PlotShapes(Buy*shapeSmallUpTriangle,colorBlue ,0,L,-51);
PlotShapes(Sell*shapeHollowDownTriangle,colorPink, 0,L,-45);
PlotShapes(Short*shapeSmallDownTriangle,colorRed,0,H,-51);
PlotShapes(Cover*shapeHollowUpTriangle,colorSkyblue,0,H,-45);

_SECTION_END();
 

amitrandive

Well-Known Member
AFL Experts , the below AFL is supposed to explore an opening range breakout , currently when explored the exploration does not return anything but only blank columns


Code:
/* Intraday Open Range Breakout Exploration AFL by GMS
 
What's the open range breakout system ?
 
1. it identifies the highest price and lowest price reached since open upto the Start Time,
2. Enter long when Price cross above ORBH (Open Range Breakout High) with a stop loss at ORBL(open Range Breakout Low), once in trade adjust SL as per your risk tollarence level.
3. Enter Short when Price cross below ORBL (open Range Breakout Low) with a stop loss at ORBH((Open Range Breakout High),once in trade adjust SL as per your risk tollarence level.
 
What is in this AFL?
1) Draws regular Candle chart
2) Set ORB Time as per param
3) Marks "ORB High" Green dotted line, "ORB Low" Red dottend line and additional Black dotted line which is middle of ORBH & ORBL on chart
4) Possible to explore, Exploration results are sorted alphabatically and shows following columns
Column 1 = Script
Column 2 = Date
Column 3 = ORBH - Open Range Breakout High value, Green means already triggered.
Column 4 = ORBL - Open Range Breakout Low value, Red Mean already triggered.
Column 5 = ORB High Breakout gain, that is maximum gain if entered long as per ORBH
Column 6 = ORB Low Breakout gain, that is maiimum gain if short as per ORBL
 
How to trade?
 
Once ORBH & ORBL are values are set as per param time, place 2 orders
 1) BUY stop loss order if price crosses above ORBH price
 2) SELL stop loss order if price crosses below ORBL price.
 
Please strictly trade with stop loss, ideally for long stop loss = ORBL & for short stop loss = ORBH. Please feel free to adjust stop loss based on your risk tollarence level.
 
*/
 
_SECTION_BEGIN("Intraday ORB Exploration");
 
SetChartOptions( 0, chartShowArrows | chartShowDates );
//("ORB");
 
BT = ParamTime ("Open Breakout Time", "09:20");
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));
SetSortColumns(1);
Can anyone please help ?:confused:
 

Similar threads