Simple Coding Help - No Promise.

amsin21

Well-Known Member
Thnks Amitji for prompt reply .
but i was looking for buy/sell signal and colour change only when MACD signal line cross zero line either from above or below .
Thanks again for cooperation.
MACD + Histogram + Buy/Sell arrows

_SECTION_BEGIN("MACDPrediction");

//The probable Cross between MACD AND its Signal, by D. Tsokakis, Feb2005

SetBarsRequired(10000,0);
function EMAn ( Cnext , r3)
{
return ( 2 * Cnext + ( r3 - 1 ) * EMA ( C , r3 ) ) / ( r3 + 1 ) ;
}
function MACDn ( Cnext , r1 , r2 )
{
return EMAn ( Cnext ,r1 ) - EMAn ( Cnext , r2 ) ;
}
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );

det = 500 ;
perc = 25/100 ;
Clast = SelectedValue ( C ) ;
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1,r2), ParamColor("MACD color", colorTeal ), ParamStyle("MACD style") );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorRed ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", IIf(ml-sl > 0,colorBrightGreen,colorRed ), styleNoTitle | ParamStyle("Histogram style",styleHistogram | styleNoLabel, maskHistogram ));

det = 500 ;
perc = 25/100 ;
Clast = SelectedValue ( C ) ;


Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1,
r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
//Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorRed ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", IIf(ml-sl > 0,colorBrightGreen,colorRed ), styleNoTitle | ParamStyle("Histogram style",styleHistogram | styleNoLabel, maskHistogram ));
MACDlast = SelectedValue(MACD());
Buy= Cross(MACD(12,26),Signal(12,26,9));
Sell = Cross( Signal(12, 26, 9), MACD(12,26) );
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

SIGNALlast = SelectedValue ( Signal ( ) );
Title = Name ( ) + ", " + Date ( ) + ", MACD=" + WriteVal ( MACDlast )+ " ,SIGNAL=" + WriteVal ( SignalLAST );
Cnextmin = ( 1 - perc ) * Clast ;Cnextmax = ( 1 + perc ) * Clast ;
step = ( Cnextmax - Cnextmin ) / det ;
nextROC1 = -100 * perc ;
nextROC2 = -100 * perc ;
for ( Cnext = Cnextmin ; Cnext <= Cnextmax ; Cnext = Cnext + step )
{
X = MACDn ( Cnext , 12 , 26 ) ;
Y = EMA ( X , 9 ) ;
MACDnext = SelectedValue ( X );
SIGNALnext = SelectedValue ( Y );
NextROC = 100 * ( -1 + Cnext / Clast ) ;
NextROC0 = 100 * ( -1 + Cnext / Clast ) ;
if ( macdnext < SignalLAST )
{
NextROC1 = NextROC ;
}
if ( MACDnext < MACDlast )
{
nextROC2 = nextROC0;
}
}
Title = Title;
Plot ( 0 ,"", colorBlack ,styleDashed ) ;
_SECTION_END();
 

Attachments

Last edited:

Nehal_s143

Well-Known Member
I require the AFL code for the below condition.

1. I want values of the HIGH and LOW of the bar at the time of 9.30 am.
2. Draw horizontal line at 9.30 AM bar high and low.

Please help.
Code:
breakoutime = 093000;
 afterbreakout0 = Cross(TimeNum(),093000);
 afterbreakout1 = TimeNum()>=093000;
 NewDay = Day()!= Ref(Day(), -1);
 highestoftheday = HighestSince(newday,H,1);
 Lowestoftheday =LowestSince(newday,L,1);
 ORBHigh = ValueWhen(afterbreakout0,highestoftheday,1);
 ORBLow = ValueWhen(afterbreakout0,lowestoftheday,1);
 Buy= Cross(C,orbhigh) AND afterbreakout1;
 Sell = Cross(orblow,C) AND afterbreakout1;
 Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);


Short=Cross(C,ORblow) AND afterbreakout1;
Cover=Cross(ORbhigh,C) AND afterbreakout1;

 Plot(C,"",colorYellow,styleBar);
 PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
 PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);
 Plot(afterbreakout0,"",colorBlue,styleHistogram|styleOwnScale);
 Plot(ORBHigh,"",colorGreen,styleDots);
 Plot(ORBLow,"",colorRed,styleDots);
 
I require the AFL code for the below condition.

1. I want values of the HIGH and LOW of the bar at the time of 9.30 am.
2. Draw horizontal line at 9.30 AM bar high and low.

Please help.
Code given below will plot High and Low as recorded by 930 AM for the most recent day only. I am assuming you are dealign with NSE so I've set starting point as 915.
Code:
C1 = ((Day() == LastValue(Day())) AND (TimeNum() <= 093000));
C2 = ((Day() == LastValue(Day())) AND (TimeNum() <= 091500));
DHigh = ValueWhen(C1,HHV(High, BarsSince(C2)));
DLow  = ValueWhen(C1,LLV(Low, BarsSince(C2)));
Plot(DHigh, "930 High",colorGreen,styleDots);
Plot(DLow, "930 Low",colorRed,styleDots);
 

yasu222

Active Member
Thanks for your kind help...

One small request..

If i want any time candle breakout , for this i need AFl please...

Example - at 9.46 am / 10.21 am / 7.21 pm like that any one candle High / Low breakout. minimum 1 minute candle
 

yasu222

Active Member
Please code for below horizontal lines -

Bid price - Bright green horizontal line.

Ask price - Bright Yellow horizontal line.

At the left end of horizontal lines, i need bid and ask quantity. Please help.
 

yasu222

Active Member
BID-ASK-CHART - May be useful.

_SECTION_BEGIN("BETTER CANDLE");
dojidiv =5;
CloseEqualOpen = ( High - Low ) / dojidiv > abs( Open - Close );
RefC = Ref( C, -1 );
RefO = Ref( O, -1 );
Up = C > O;
Down = C < O ;
UpDoji = CloseEqualOpen AND RefC > RefO;
DownDoji = CloseEqualOpen AND RefC < RefO;
colcond = IIf( up || updoji, colorBrightGreen, colorRed );
SetBarFillColor( colcond );
Plot( C, "Price", colcond, styleCandle );
_SECTION_END();

_SECTION_BEGIN("Bid-Ask-LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorRed,styleLine,1) ;
Plot(ASK,"ASK",colorBrightGreen,styleLine,1) ;
}
_SECTION_END();

_SECTION_BEGIN("Dashboard");

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");

GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");

x = 1000;
x2 =1090;

y = pxHeight-400;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y-50 , 7, 7 ) ;
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location

GfxSelectSolidBrush( colorOrange );

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x+92, y - 98, x2+92, y-50 , 7, 7 ) ;
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location

}

_SECTION_END();
 
Last edited:

amsin21

Well-Known Member
BID-ASK-CHART - May be useful.

_SECTION_BEGIN("BETTER CANDLE");
dojidiv =5;
CloseEqualOpen = ( High - Low ) / dojidiv > abs( Open - Close );
RefC = Ref( C, -1 );
RefO = Ref( O, -1 );
Up = C > O;
Down = C < O ;
UpDoji = CloseEqualOpen AND RefC > RefO;
DownDoji = CloseEqualOpen AND RefC < RefO;
colcond = IIf( up || updoji, colorBrightGreen, colorRed );
SetBarFillColor( colcond );
Plot( C, "Price", colcond, styleCandle );
_SECTION_END();

_SECTION_BEGIN("Bid-Ask-LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorRed,styleLine|styleNoLabel|styleNoRescale) ;
Plot(ASK,"ASK",colorBrightGreen,styleLine|styleNoLabel|styleNoRescale) ;
}
_SECTION_END();

_SECTION_BEGIN("Dashboard");

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");

GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");

x = 1000;
x2 =1090;

y = pxHeight-400;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y-50 , 7, 7 ) ;
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location

GfxSelectSolidBrush( colorOrange );

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x+92, y - 98, x2+92, y-50 , 7, 7 ) ;
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location

}

_SECTION_END();
Good one. Data feed should support RTD - Ask & Bid.
 

yasu222

Active Member
Lets design trading systems as per Ask/Bid prices instead closing prices as

buy = ask>condi1;
sell = bid<cond2;

OR

no1 = param("spread",.05,0,20,.05);
diff=(ask-bid);
spread = (diff<=no1);

buy = c>condi1 AND spread;
sell = c<condi2 AND spread;

like that for scalping / intraday strategies.,...
 
Last edited:

yasu222

Active Member
Lets design trading systems as per Ask/Bid prices instead closing prices as
no1 = param("spread",.05,0,20,.05);
diff=(ask-bid);
spread = (diff<=no1);
buy = c>condi1 AND spread;
sell = c<condi2 AND spread;
like that for scalping / intraday strategies.,...
I want afl for the below condition -

Place both buy and sell orders in NEST/NOW trading platforms whenever spread = particular number
example-

if Live bank-nifty spread is more than 7 points, then i want to place both orders as

ask - live spread-0.10
bid - ask-4.10

once ask price execute then my bid order should be cancelled and
place another bid order = (executed) ask price-4 points.

this process continues till to accumulate maximum of 5000 bank nifty future Lots either buy side or sell side.
Once it reaches that quantity then place 10000 Lots at market price either sell side / buy side.
 
Last edited:

Similar threads