AFL writing guide for new user

HI,

I trade on color of candel stick when color of candel is red and next candel break previous candel low then sell and if candel color is green and previous candel break high then buy target randam 25 points in nifty and stoploss candel low.

it is possibale to make one aft these give buy call when candel color is green and next candel break his high and stop loss previous candel low and target is 25 points for all call buy or sell.

Also add sound aler in buy or sell call or target hit or stop loss hit.

If any one can do these pls try..

Time frame for buy or sell call is 30 min chart.

Thanks.
 
Hi Debarghya
Greetings!

I saw your post towards AFLs which is awesome and I was searching for help in some AFLs, I'm sending you my requirements, please see if you can help me. I'm a newbie to this so kindly bare with me....
:(

Here is my requirement:
I'm trying to generate a Excel sheet in the name of the script. <Nifty.xls> etc.,

Fields required are:
ScriptName | Date | Time | O | H | L | C | Vol | OpenInterst | Signal

When the code is embedded with any AFL this code should generate a excel file like backfill all available price data and the signal Col should be "Buy | Sell | Wait"
eg:
If buy signal then Sig Col value = Buy and rest following cells will be "Wait" until "Sell" is generated and same for "Sell" sig as well Sig Col changes from "Wait" to "Sell" and all other cells with "Wait" until "Buy".

this info should be like a back fill, I sourced a code in the forum which creates a CSV but then it creates a CSV when ever the AFL is activated or deactivated. not generating Signal properly. please help

below is the code that I have with me.

Code:
if(Buy[b])
	{
if(Buy[b]==1)
{		
sig="Buy Now";
}
else
{
sig = "Long Wait";

PlotText("\n\n\n\n Buy\n "+NumToStr(BuyPrice[b],1.2),b,BuyPrice[b],colorBrightGreen);
	
		dayhours = ParamToggle("Day hours only", "No|Yes");
fmkdir("c:\\AmiBackup\\");
SetBarsRequired(100000,100000);
lname = Name(); // gets the name of the symbol
// note: if you have names with invalid characters like / you must rename the file before you try to create a Name 
// add an IF line for each symbol you need to rename
if (lname == "ER2U8-GLOBEX-FUT") lname = "ER2U8";

fh = fopen( "c:\\AmiBackup\\" + lname + ".csv", "w"); 
if( fh ) 
{ 
	if(Interval() == inDaily OR Interval() == inMonthly OR Interval() ==
inWeekly)
	{
		fputs( "Ticker,Date,Open,High,Low,Close,Open Interest,Volume, sig \n", fh ); 
	   	for( i = 0; i < BarCount; i++ ) 
		{ 
 		  	y = Year(); 
 		  	m = Month(); 
		   	d = Day(); 
			fputs( Name() + "," , fh );
   		   	ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] ); 
   	   		fputs( ds, fh ); 
      		qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ], sig[i]); 
      		fputs( qs, fh ); 
			if(i == 1000000 OR i == 2000000 OR i == 3000000 OR i == 4000000)
			{
				fclose( fh ); 
				if(i == 1000000  ) fh = fopen( "c:\\AmiBackup\\" + lname + " A.csv", "w"); 
				if(i == 2000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " B.csv", "w"); 
				if(i == 3000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " C.csv", "w"); 
				if(i == 4000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " D.csv", "w"); 
			}
		}
	}
	else // intraday so add time field
	{
		fputs( "Ticker,Date,Time,Open,High,Low,Close,Open Interest,Volume, Signal \n", fh ); 
 	  	y = Year(); 
 	  	m = Month(); 
	   	d = Day(); 
	   	r = Hour();
	   	e = Minute();
	   	n = Second();
   
	   	for( i = 1; i < BarCount; i++ ) 
		{ 
			if (dayhours AND LastValue(TimeNum()) >= 92900 AND LastValue(TimeNum()) <=
161500)
			{ 
				fputs( Name() + "," , fh );
 		     	ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ 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,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ],sig[i]); 
		      	fputs( qs, fh ); 
			}
			else
			{ 
				fputs( Name() + "," , fh );
 		     	ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ 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,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ],sig[i] ); 
		      	fputs( qs, fh ); 
			}
			if(i == 1000000 OR i == 2000000 OR i == 3000000 OR i == 4000000)
			{
				fclose( fh ); 
				if(i == 1000000  ) fh = fopen( "c:\\AmiBackup\\" + lname + " A.csv", "w"); 
				if(i == 2000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " B.csv", "w"); 
				if(i == 3000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " C.csv", "w"); 
				if(i == 4000000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " D.csv", "w"); 
			}
 	  	} 
	}
   	fclose( fh ); 
}
}
}
else if ( Sell[b] )
{

I'm unable to do this properly since my level of expertise is NEWBIE for AFLs, Please help:(
 
Does anyone know how to find the highest volume price for a particular day on a 5 min chart? I realize there is an indicator but I cant seem to figure out how to use VAP in a trading system.

For example buy=iif(c==PreviousDayHighestVolumePrice,1,0);

anyone have a method as my attempts have not been successful lol
 
Hi DM,

I don't know whether by now you have abondoned this child you fathered once (this thread), but it is indeed very interesting. I started with only school level BASIC language programming info. Program codes have standard structures, functions, variables and parameters, common syntax, and, sometimes common syntax errors also. Your thread helped me to learn the basic of afl writing.

I would like to request you for continuing this highly commendable effort. And yes, we can only request. And if you continue, please whenever you will introducing any new function within a code, pls add one or two lines of explanation. that will help.

And last but not least, in general people are more inclined to readymade solutions. Just think of the students going for made-easy books instead of consulting various reference materials for preparaing own note. There is always less demand for things which require efforts. So please don't give up your effort by the number of responses you may get in this thread. You will always find some people, whatever less that may be in number, reaping benefit from your posts and explanations. They will always pay tribute to you. There remains the success of your thread.

Just think over it.

Sudip
 
Last edited:
Cond1 = C> EMA( C , 200 ) ;
Cond2=C< EMA( C , 15 ) ;
Cond3=Ref( High , -2 ) < Ref(High,-1);
Cond4=Ref( Low , -2 ) < Ref(Low,-1);
Cond5=( H) < Ref(High,-1);
Cond6=(L) < Ref(Low,-1);
Buy=Cond1 AND cond2 AND cond3 AND cond4 AND cond5 AND cond6;






Hello,

I am a new Amibroker User could anybody help me with coding this idea:

I want to code this system:

1.Today the stock is above 200 day moving average.
2.Today the stock close below 5 day moving average.
3.Two days ago the high and low price is below yesterdays high and close price
4.Today`s high and low price is below yesterdays high and low price.
5.Buy at netx day open.

Thanks for your help

Enrico
 

Vertigo_1985

Well-Known Member
I attempted to code a strategy for backtesting( 3 bar strategy by Vikas) but wasn't able to code it fully. I am having difficulty in coding it for backtesting purpose. Any help would be really appreciated.

This is the strategy http://www.traderji.com/technical-an...-strategy.html


I want sell signal to be taken at fixed profit % or price hitting trailing low.
Cover signal to be taken at fixed profit % or price hitting trailing high. Please add sell and cover signal to my code and make it appropriate for backtesting.

Below is what i have coded so far:-

// 1st 2 candles Inside bar
Buysignal1 = (Ref(L,-1) >= Ref(L,-2)) AND (Ref(H,-1) <= Ref(H,-2));


// 1st and third candles Bull candle
Buysignal2 = (Ref(O,-2) < Ref(C,-2)) AND ( Open < Close);

//2nd Candle bear candle
Buysignal3 = (Ref(O,-1) > Ref(C,-1));

// Buy when inside bar, 1st and 3rd bar green

Buy = Buysignal1 AND Buysignal2 AND Buysignal3 ;

// SHORT TRADE

//1st 2 candles Inside bar
ShortSignal1 = (Ref(L,-1) >= Ref(L,-2)) AND (Ref(H,-1) <= Ref(H,-2));

// 1st and third candles Bear candle
Shortsignal2 = (Ref(O,-2) > Ref(C,-2)) AND ( Open > Close);

//2nd Candle bull candle
Shortsignal3 = (Ref(O,-1) < Ref(C,-1));

Short = Shortsignal1 AND Shortsignal2 AND Shortsignal3 ;
 
hi friends,

please help how to change chart background color in afl

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

I want to change ColorRGB to ColorLavender, it is showing error

please help
 

Similar threads