TriggerLines

KelvinHand

Well-Known Member
#41
Post #7 by Johnnypeek
http://www.traderji.com/amibroker/77907-if-any-have-afl-support-resistance-colorful-pls-give-me.html

is the one with
Code:
_SECTION_BEGIN("Trigger Lines");
p1 = Param("TL 1 Periods", 55, 2, 200);
p2 = Param("TL 2 Periods", 3, 2, 200, 1);

BS_Arrow = ParamToggle("Buy/Sell Arrows", "No|Yes",1);

TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorRGB(0,192,255)), ParamColor("TL Dn Colour", colorRed));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);

if (BS_Arrow)
{
Buy=Cross(TL1, TL2);
Sell = Cross(TL2, TL1);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
}

_SECTION_END();
I altered to become TriggerLines2.afl to be used as "TJ Super CrossOver Indicator"
 
Last edited:

asnavale

Well-Known Member
#42
Re: MT4 FX Super CrossOver Indicator

Hello Anant

Is it not same as "LinearReg" ?

Cheers
:thumb:




EDIT: Try this :)

Code:
_SECTION_BEGIN("Linear Regression");
P = ParamField("Price field",-1);
Periods = Param("Periods", 25, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
:
YES IT IS EXACTLY SAME AS LINEARREG

-Anant
 

KelvinHand

Well-Known Member
#43
Re: MT4 FX Super CrossOver Indicator

The Triggerrline AFL (LSMA) is available in AmiBroker Library. It was posted by Ivanov Denis on 1-10-2009. I am reproducing it below. I have not coded it. Credit should go to Ivanov.

LSMA FORMULA

Code:
//		+---------------------------------------------
//		|	LSMA by Ivanov Denis
//		|	LSMA - indicator will be use for WoodieCCI
//		+---------------------------------------------
//

p1 =			Param("Period-LSMA",25,1,100,1);
summa=			0;
len=			p1;
i=				1;

while (i<=len)
{
	lenvar=	(len+1)/3;
	tmp= 		Ref(Close, i-len);
	tmp= 		(i-lenvar)*tmp;
	summa= 	summa+tmp;
	i=			i+1;
}

LSMA=			summa*6/(len*(len+1));

Plot(LSMA,"LSMA",colorRed,1+4);

-Anant
This AFL is the MT4 Code section.
 

asnavale

Well-Known Member
#44

KelvinHand

Well-Known Member
#45
Hi Kelvin,

But this AFL of Johny gives the delayed triggers. If we use LSMA alone, we get better triggers, of course, some whipsaws also will be there, but it is easy to avoid them.

-Anant
Is up to you to use.
I just created it for matching the MT4.

I maybe use it as trend changed direction, using PA or Price Pattern to do trigger.
I can do regression to mean trigger
 
Last edited:

asnavale

Well-Known Member
#46
Is up to you to use.
I just created it for matching the MT4.

I maybe use it as trend changed direction, using PA or Pattern to do entry
Yes I am trying to tweak the LSMA AFL

-Anant
 
#47
Kevin
Is there a way that we can create an excel / csv file when there is a buy / sell signal.....
I found a code to write an excel / csv file when the chart is activated.
however I'm looking for a code to create a excel / csv only if there is a buy or sell signal

{Excel Output}
Ticker Date Time Open High Low Close Open Interest Volume Signal
BANKNIFTY-I 12/12/2012 09:25:00 12382.6504 12399.5 12360.2002 12398.5 1322100 64675
BANKNIFTY-I 12/12/2012 09:35:00 12398 12400 12381 12395 1339825 47950
BANKNIFTY-I 12/12/2012 09:45:00 12396 12402 12370.5 12381 1337300 36550
{Excel output ends}

This method actualy backfills all data, and I'm looking to add all buy and sell signals in it once when a signal is generated then it should backfill data with all buy signals, please help create one for me.....; Thanks in advance

Above is the CSV genarated (Found this code in this forum), signal col is empty and is not genarating.... kindly help

Code:
Code:
if(Buy[b])
	{
		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 :thumb: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 ], Buy[b]); 
      		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,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ], Buy[b] ); 
		      	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,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ], Buy[b] ); 
		      	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] )
{

PlotText("Sell  "+NumToStr(SellPrice[b], 1.2),b,SellPrice[b],colorDarkRed);

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,Signal \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 ], Sell[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,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ],Sell[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,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
],OI[ i ],V[ i ],Sell[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 ); 
}		
};
}
 
#49
U can also use this.... Enjoy..


SetChartBkGradientFill( ParamColor( "TopColor", ColorRGB( 217, 197, 137 ) ), ParamColor( "BottomColor", ColorRGB( 254, 244, 224 ) ) );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

_SECTION_BEGIN("SingleMA");

SetChartOptions(0, chartShowDates | chartWrapTitle);
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
kk = Optimize( "mult", Param( "mult", 2, 1, 6, 0.25 ), 1, 2, 0.25 );
Per = Optimize( "period", Param( "period", 10, 5, 50, 1 ), 5, 50, 1 );
sdfact = Param( "Standard Deviation Factor", 2, 0.5, 5, 0.1 );
offset = Param( "Offset", 2, 1, 50, 1 );
tc = ParamList( "Channel Display", List = "No Channel|Channel|ChannelRT|Both
Channels", 1 );
ms = ParamToggle( "Trend", "Regular|Smoothed", 1 );

x = Cum( 1 );
HaClose = ( O + H + L + C ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

if ( ms == 0 )
{
nm = ( H - L );
j = ( O + H + L + C ) / 4;
}
else
{
nm = ( HaHigh - HaLow );
j = ( HaOpen + HaHigh + HaLow + HaClose ) / 4;
}

rfsctor = WMA( nm, Per );

revers = kk * rfsctor;
Trend = 1;
NW[0] = 0;

for ( i = 1;i < BarCount;i++ )
{
if ( Trend[i-1] == 1 )
{
if ( j < NW[i-1] )
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;

if ( ( j - Revers ) > NW[i-1] )
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}

if ( Trend[i-1] == -1 )
{
if ( j > NW[i-1] )
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;

if ( ( j + Revers ) < NW[i-1] )
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

cp = ( H + L ) / 2;

Plot( IIf( NW < j, NW, Null ), "\ntrailLong", ParamColor( "ColorTrailLong",
colorBlue ), styleStaircase | styleDots );
Plot( IIf( NW > j, NW, Null ), "\ntrailShort", ParamColor( "ColorTrailShort",
colorRed ), styleStaircase | styleDots );

Buy = NW < j;
Short = NW > j;

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

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBlue, 0,NW);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,NW);



_SECTION_END();

_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 55, 5, 50, 1);
p2 = Param("TL 2 Periods", 2, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();