Simple Coding Help - No Promise.

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);
 
if its possible can create this afl :-

Can try this setup for intraday play....

This strategy is for purely intraday.It has given me 600 points gain in last 6 days after brokerage.

STRATEGY
1) Time frame 3-min for EMA CROSSOVER and 5- min for PSAR (PARABOLIC STOP AND REVERSE)

2)In 3min tf, EMA3 and EMA15 cross over to be taken for buy and sell

3) if we get a buy signal from ema cross over, then look at psar for confirmation as follow

4)make time frame 5-min,select PSAR, add 20-ema.
if psar is below the cmp and cmp is above 20-ema, then it is a CONFIRMED BUY.(After step 3 then step 4)

5)Always buy 2 lots.Book 1 lot at +15 point , 2nd lot at +30 points.
If CONFIRMED SELL SIGN is generated, then reverse position.



 

Nehal_s143

Well-Known Member
need to add condition 4 using time frame expand for 20 ema & SAR, which only senior can help out

_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("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 3, 30, 100, 5);
ShortPer = Param("Short Period", 15, 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);
Sell = Cross(ShortMA, LongMA);
PlotShapes(shapeUpArrow * Buy, colorBrightGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);
_SECTION_END();


if its possible can create this afl :-

Can try this setup for intraday play....

This strategy is for purely intraday.It has given me 600 points gain in last 6 days after brokerage.

STRATEGY
1) Time frame 3-min for EMA CROSSOVER and 5- min for PSAR (PARABOLIC STOP AND REVERSE)

2)In 3min tf, EMA3 and EMA15 cross over to be taken for buy and sell

3) if we get a buy signal from ema cross over, then look at psar for confirmation as follow

4)make time frame 5-min,select PSAR, add 20-ema.
if psar is below the cmp and cmp is above 20-ema, then it is a CONFIRMED BUY.(After step 3 then step 4)

5)Always buy 2 lots.Book 1 lot at +15 point , 2nd lot at +30 points.
If CONFIRMED SELL SIGN is generated, then reverse position.



 
Code:
Avg_Vol = MA(V,200);  Nbar_Hi = HHV(H,20);  Nbar_Lo = LLV(L,20);
Buy  = H > Ref(H,-1)*1.01 AND H > Ref(Nbar_Hi,-1) AND V > Avg_Vol; 	
Sell = L < Ref(L,-1)*0.99 AND L < Ref(Nbar_Lo,-1) AND V > Avg_Vol;
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H)); Filter = Buy OR Sell
this will also flag gap-up/down by more than 1% with high volume


:) Happy

Above Code given by you happy ji,

Code is for scan 1% move in single candle with volumes..



i need a condition to be added that candle should move outside (20,2) Bollinger band area


So it will fliter limited scripts...

Kindly help me to do so..

Thanx you
 

XRAY27

Well-Known Member
Hi,
i want horizontal lines for day high and day low and previous day high and low spotted only on todays price without any marking on previous day..
 
Respected Happy Sir

can u cange the target & stop loss of above afl,
risk & reward ratio is 1 to 1, 2 to 1 & 3 to 1


Warm Regards
Chinmay

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

_SECTION_BEGIN("Signal Panel");
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
if (showsl == 1)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}

exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "Buy @ " + C, 1 );
AlertIf( Sell, "", "Sell @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "Buy";
sl = s5d;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "Sell";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "Buy", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount-3,entry,Null,colorBlue);
PlotText("TGT-1@"+tar1,BarCount-4,tar1,Null,Clr);PlotText("TGT-2@"+tar2,BarCount-4,tar2,Null,Clr);PlotText ("TGT-3@"+tar3,BarCount-4,tar3,Null,Clr);

}

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="Buy")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 310;

y = pxHeight;

GfxSelectPen( colorGreen, 5); // broader color
GfxRoundRect( x, y - 142, x2, y , 7, 7 ) ;
GfxTextOut( Name(),12,y-140);
GfxTextOut( " Last Traded Price = "+ C , 08,y- 120 );
GfxTextOut( ( "Signal Panel"),160,y-140);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-100) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="Buy",sig + " @ ",sig + " @") + " : " + entry), 13, y-80);
GfxTextOut( ("Trailing Stop Loss : " + sl + " (P/L:" + WriteVal(IIf(sig == "Sell",entry-sl,sl-entry), 2.2) + ")"), 13, y-60);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -40);
GfxTextOut( ("Current Profit/Loss : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 40, y-22);;

}
_SECTION_END();



_SECTION_BEGIN("Sound Alert");
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Sell " + C,2,1+2,1);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\tada.wav","Buy " + C,1,1+2,1);
_SECTION_END();



_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",15,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlue) );
Hor=Param("Horizontal Position",750,800,800,800);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut("L.T.P="+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5.45, Ver+45 );
_SECTION_END();


_SECTION_BEGIN("");
GfxSetOverlayMode(0);
GfxSelectPen( colorRed, 3 );
GfxSelectSolidBrush( colorLightYellow );
GfxRoundRect( 350, 38,665, 70, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 17.5, 700, False );
GfxSetTextColor( colorBrown );
GfxSetTextAlign(0);
GfxSetTextColor( colorBlack );
GfxTextOut( " Last Traded Price = "+ BuyPrice , 350, 40);
_SECTION_END();


_SECTION_BEGIN("Isfandi Technical Viewer");
//Plot(C,"",ParamColor( "Color", colorBlue ),ParamStyle("Style") );
//---- pivot points
GfxSetBkColor(colorBlue);
GfxSetTextColor( colorLime );
GfxSelectFont("Times New Roman", 20, 1,500, True );
GfxTextOut(" Intraday Trading System ", 20 , 40 );
_SECTION_END();


_SECTION_BEGIN(" Buy Sell Signal Confirm ");
BarColors =
IIf(BarsSince(Buy) < BarsSince(Sell)
AND BarsSince(Buy)!=0, colorGreen,
IIf(BarsSince(Sell) < BarsSince(Buy)
AND BarsSince(Sell)!=0, colorRed, colorBlue));
//Plot the Candlestick charts
Plot(C, "Close", BarColors, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ) ;
_SECTION_END();

_SECTION_BEGIN("Show Up Down Arrow & Price ");
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );

dist = 1.8*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy@" + L[ i ], i, L[ i ]-dist, colorWhite, colorGreen );
if( Sell ) PlotText( "Sell@" + H[ i ], i, H[ i ]+dist, colorWhite, colorRed );
}


PlotShapes( shape, IIf( Buy, colorBlue, colorRed ), 0, IIf( Buy, Low, High )
);

_SECTION_END();
 
Last edited:
if for a particular stock i want to place buy order candle high above 100 and sell when candle low below 90.
Is this AFL correct???


SUP=90;
REST=100;
for(i=1; i < BarCount; i++)
{


Sell = L<SUP;
Buy = H>REST;
}
 
if for a particular stock i want to place buy order candle high above 100 and sell when candle low below 90.
Is this AFL correct???


SUP=90;
REST=100;
for(i=1; i < BarCount; i++)
{


Sell = L<SUP;
Buy = H>REST;
}


It Should be Sell and Buy.. It is also better to place following line at top of the file

Code:
Buy = Sell = 0;
 

Similar threads