Simple Coding Help - No Promise.

pratapvb

Well-Known Member
my chart is showing 30min 12.30 as bearish for 12/24/2012

 

pratapvb

Well-Known Member
Hi abhig10,

Check the levels and targets on weekly and monthly charts also...it will be interesting.
This week banknifty spot weekly buy level is 10834.60 and sell level is 10673.60.

Today market respected those levels twice. Please check the charts. Morning took support at sell level in 9.30 candle and now took resistance at buy level in 10.30 candle.
 
Last edited:
Check this one.

Code:
RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 25;
SetPositionSize(4, spsShares);

_SECTION_BEGIN("Price");
// Toggle candle visibility
if (ParamToggle("Candles", "Show|Hide",0)){
	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("EMA Fast");
Periods1 = Param("Period Fast", 5, 2, 15, 1);
Periods1 = Optimize("Period Fast", Periods1, 2, 15, 1);
P1			= ParamField("Price field Fast", 3);
EMAFast = EMA( P1, Periods1 );
Plot( EMAFast, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA Slow");
Periods2 = Param("Period Slow", 13, 10, 30, 1);
Periods2 = Optimize("Periods Slow", Periods2, 10, 30, 1);
P2			= ParamField("Price field Slow", 3);
EMASlow = EMA( P2, Periods2 );
Plot( EMASlow, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

TimeFrameSet(in5Minute*3);
expand	= expandLast;

_SECTION_BEGIN("EMA Fast 15min");
Periods15 = Param("Period Fast 15min", 5, 2, 15, 1);
Periods15 = Optimize("Period Fast 15min", Periods1, 2, 15, 1);
P15			= ParamField("Price field Fast 15min", 3);
EMAFast15 = EMA( P15, Periods15 );
EMAFaste	= TimeFrameExpand(EMAFast15, in5Minute*3, expand);
Plot( EMAFaste, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA Slow 15min");
Periods25 = Param("Period Slow 15min", 13, 10, 30, 1);
Periods25 = Optimize("Periods Slow 15min", Periods2, 10, 30, 1);
P25			= ParamField("Price field Slow 15min", 3);
EMASlow5 = EMA( P25, Periods25 );
EMASlowe	= TimeFrameExpand(EMASlow5, in5Minute*3, expand);
Plot( EMASlowe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
TimeFrameRestore();

_SECTION_BEGIN("Trading signals");
Buy		= EMAFaste>EMASlowe AND Cross(EMAFast, EMASlow);
Short	= EMAFaste<EMASlowe AND Cross(EMASlow, EMAFast);

Cover	= Cross(EMAFast, EMASlow);
Sell	= Cross(EMASlow, EMAFast);

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

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

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);

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);
		sig		= "Buy";
	} else if( Short[i]) {
		PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
		sig	= "Short";
 	}
}
_SECTION_END();
yes it is working.thank u so much for ur time and help..now only 1 problem i am getting when i try this code on different systems it starts repainting. i have edited code as per my requirement but i am missing something. can u replace above code buy sell with below system buy sell logic which i am using for nifty future.

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

_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 2, 2, 300, 1 );
Width = Param("Width%", 0.15, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style", styleLine | styleNoLabel );

CenterLine = MA( P, Periods );
Buyline = CenterLine * (1 + Width * 0.01);
Selline = CenterLine * (1 - Width * 0.01);


Plot( Buyline, "Buyline" + _PARAM_VALUES(), colorGreen, Style );
Plot( Selline, "Selline" + _PARAM_VALUES(), colorRed, Style );

Buy1 = Cross(C,Buyline);BuyPrice = C;
Sell1 = Cross(Selline,C);SellPrice = C;
Cover = buy1;
Short = sell1;


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


GraphXSpace = 5;
dist = 3.5*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n" + C[ i ], i, L[ i ]-dist, colorGreen );
if( Sell ) PlotText( "sell\n" + C[ i ], i, L[ i ]+dist, colorRed);
}
 
Last edited:
Your code is fine. It's not repainting. Last candle sometimes would repaint as the close of the candle is never defined.
this is not repainting sir. i want signals on 5 min from referring 15 min buy sell candle close.. same afl like u created for me with ema crossover. instead of ema crossover buy sell logic, i want below afls buy sell logic. i tried to replace signals by below one but i failed to do so.. can u help me.

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

_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 2, 2, 300, 1 );
Width = Param("Width%", 0.15, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style", styleLine | styleNoLabel );

CenterLine = MA( P, Periods );
Buyline = CenterLine * (1 + Width * 0.01);
Selline = CenterLine * (1 - Width * 0.01);


Plot( Buyline, "Buyline" + _PARAM_VALUES(), colorGreen, Style );
Plot( Selline, "Selline" + _PARAM_VALUES(), colorRed, Style );

Buy1 = Cross(C,Buyline);BuyPrice = C;
Sell1 = Cross(Selline,C);SellPrice = C;
Cover = buy1;
Short = sell1;


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


GraphXSpace = 5;
dist = 3.5*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n" + C[ i ], i, L[ i ]-dist, colorGreen );
if( Sell ) PlotText( "sell\n" + C[ i ], i, L[ i ]+dist, colorRed);
}
 
Last edited:

pratapvb

Well-Known Member
sir the chart is for pnb futures...
oh...yours was PNB

will check post mkt
just use OR in these lines instead of AND

compbar4 = tf4he != Ref(tf4he, -1) OR tf4le != Ref(tf4le, -1) ;
compbar3 = tf3he != Ref(tf3he, -1) OR tf3le != Ref(tf3le, -1) ;
compbar2 = tf2he != Ref(tf2he, -1) OR tf2le != Ref(tf2le, -1) ;
compbar1 = tf1he != Ref(tf1he, -1) OR tf1le != Ref(tf1le, -1) ;


I wrote AND by mistake....my intention was always to use OR :D

sorry for posting a code with a stupid mistake and increasing the work for you people
 
just use OR in these lines instead of AND

compbar4 = tf4he != Ref(tf4he, -1) OR tf4le != Ref(tf4le, -1) ;
compbar3 = tf3he != Ref(tf3he, -1) OR tf3le != Ref(tf3le, -1) ;
compbar2 = tf2he != Ref(tf2he, -1) OR tf2le != Ref(tf2le, -1) ;
compbar1 = tf1he != Ref(tf1he, -1) OR tf1le != Ref(tf1le, -1) ;


I wrote AND by mistake....my intention was always to use OR :D

sorry for posting a code with a stupid mistake and increasing the work for you people
Thanks for the work
 
Hello Happy,

I am trying to write AFL but having tough time. Please help me how to use iif n plot functions when plotting the afl with:

1. An arrow is plotted when close price of current candle is less then or equal to previous candle AND current candle is a Bear Candle.

Many Thanks,
Aman.
 
Check this one.

Code:
RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 25;
SetPositionSize(4, spsShares);

_SECTION_BEGIN("Price");
// Toggle candle visibility
if (ParamToggle("Candles", "Show|Hide",0)){
	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("EMA Fast");
Periods1 = Param("Period Fast", 5, 2, 15, 1);
Periods1 = Optimize("Period Fast", Periods1, 2, 15, 1);
P1			= ParamField("Price field Fast", 3);
EMAFast = EMA( P1, Periods1 );
Plot( EMAFast, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA Slow");
Periods2 = Param("Period Slow", 13, 10, 30, 1);
Periods2 = Optimize("Periods Slow", Periods2, 10, 30, 1);
P2			= ParamField("Price field Slow", 3);
EMASlow = EMA( P2, Periods2 );
Plot( EMASlow, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

TimeFrameSet(in5Minute*3);
expand	= expandLast;

_SECTION_BEGIN("EMA Fast 15min");
Periods15 = Param("Period Fast 15min", 5, 2, 15, 1);
Periods15 = Optimize("Period Fast 15min", Periods1, 2, 15, 1);
P15			= ParamField("Price field Fast 15min", 3);
EMAFast15 = EMA( P15, Periods15 );
EMAFaste	= TimeFrameExpand(EMAFast15, in5Minute*3, expand);
Plot( EMAFaste, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA Slow 15min");
Periods25 = Param("Period Slow 15min", 13, 10, 30, 1);
Periods25 = Optimize("Periods Slow 15min", Periods2, 10, 30, 1);
P25			= ParamField("Price field Slow 15min", 3);
EMASlow5 = EMA( P25, Periods25 );
EMASlowe	= TimeFrameExpand(EMASlow5, in5Minute*3, expand);
Plot( EMASlowe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
TimeFrameRestore();

_SECTION_BEGIN("Trading signals");
Buy		= EMAFaste>EMASlowe AND Cross(EMAFast, EMASlow);
Short	= EMAFaste<EMASlowe AND Cross(EMASlow, EMAFast);

Cover	= Cross(EMAFast, EMASlow);
Sell	= Cross(EMASlow, EMAFast);

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

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

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);

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);
		sig		= "Buy";
	} else if( Short[i]) {
		PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
		sig	= "Short";
 	}
}
_SECTION_END();
I don't think I fully understand you. Do you want the Close of 15min candles to be followed or 5min candles for MA(Close), Buy and Short signals?
instead of ema crossover can u modify above afl with below buy sell logic..

_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 2, 2, 300, 1 );
Width = Param("Width%", 0.15, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style", styleLine | styleNoLabel );

CenterLine = MA( P, Periods );
Buyline = CenterLine * (1 + Width * 0.01);
Selline = CenterLine * (1 - Width * 0.01);


Plot( Buyline, "Buyline" + _PARAM_VALUES(), colorGreen, Style );
Plot( Selline, "Selline" + _PARAM_VALUES(), colorRed, Style );

Buy1 = Cross(C,Buyline);BuyPrice = C;
Sell1 = Cross(Selline,C);SellPrice = C;
Cover = buy1;
Short = sell1;


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

Similar threads