_SECTION_BEGIN("New Chart"); barcolor = ((IIf(C>O,colorGreen,colorRed))); SetBarFillColor(barcolor); Plot( C, "Price", barcolor, styleCandle ); GfxSelectFont( "Tahoma", 11, 110 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); SetChartOptions(0,chartShowArrows|chartShowDates); SetBarsRequired(sbrAll,sbrAll); GraphXSpace=50; GfxSelectPen( colorGreen, 2 ); GfxSelectSolidBrush( colorDarkTeal); GfxRectangle( 3, 2, 1580, 53 ); //GfxRectangle( 3, 320, 280, 53 ); GfxSelectFont( "Tahoma", 12, 350 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorBrightGreen ); GfxTextOut(""+Interval(2),30,15); GfxSetTextColor(colorred ); GfxTextOut(" "+DateTimeToStr(SelectedValue(DateTime())),30*4.5,15); GfxSetTextColor( colorAqua ); GfxTextOut("Open = "+open,30*12.5,15); GfxSetTextColor( colorbrightGreen ); GfxTextOut("High = "+high,30*18,15); GfxSetTextColor( colorRed ); GfxTextOut("Low = "+low,30*23.5,15); GfxSetTextColor( colorYellow ); GfxTextOut("Close = "+close,30*28.5,15); GfxSetTextColor( colorTurquoise ); GfxTextOut("ROC % = "+Prec(SelectedValue( ROC( C, 1 ) ),2),30*34.5,15); GfxSetTextColor( colorOrange ); GfxTextOut("Volume = "+Volume,30*40,15); _SECTION_END(); _SECTION_BEGIN("Intraday Timing Condition"); YFirstTradeTime = ParamTime( "Start Time", "09:15" ); // Earliest time to take a trade YLastTradeTime = ParamTime( "End Time", "15:00" ); // Latest time to take new trades YExitAllPositionsTime = ParamTime( "Exit Time", "15:09" ); // Exit all trades YEntrytimecondition = (TimeNum() >= YFirstTradeTime AND TimeNum() <= YLastTradeTime ); Exittimecondition = (TimeNum()>=YExitAllPositionsTime); _SECTION_END(); dn = Day(); newday = dn != Ref( dn, -1 ); bar=BarsSince(newday); /////////////////////////////////////////////////////////////////////////////// // Bull & Bear Pin Start // /////////////////////////////////////////////////////////////////////////////// _SECTION_BEGIN( "Pin Bar AFL" ); MaxNoseBodySize = 0.33; // Max. Body / Candle length ratio of the Nose Bar NoseBodyPosition = 0.4; // Body position in Nose Bar (e.g. top/bottom 40%) LeftEyeOppositeDirection = True; // true = Direction of Left Eye Bar should be opposite to pattern (bearish bar for bullish Pinbar pattern and vice versa) NoseSameDirection = False; // true = Direction of Nose Bar should be the same as of pattern (bullish bar for bullish Pinbar pattern and vice versa) NoseBodyInsideLeftEyeBody = False; // true = Nose Body should be contained inside Left Eye Body LeftEyeMinBodySize = 0.1; // Min. Body / Candle length ratio of the Left Eye Bar NoseProtruding = 0.5; // Minmum protrusion of Nose Bar compared to Nose Bar length NoseBodyToLeftEyeBody = 1; // Maximum relative size of the Nose Bar Body to Left Eye Bar Body NoseLengthToLeftEyeLength = 0; // Minimum relative size of the Nose Bar Length to Left Eye Bar Length LeftEyeDepth = 0.2; // Minimum relative depth of the Left Eye to its length; depth is difference with Nose's back up = down = 0; point = 0.1; blpin = brpin = False; for( i = 1; i < BarCount; i++ ) { NoseLength = High[i] - Low[i]; if( NoseLength == 0 ) NoseLength = Point; LeftEyeLength = High[i - 1] - Low[i - 1]; if( LeftEyeLength == 0 ) LeftEyeLength = Point; NoseBody = abs( Open[i] - Close[i] ); if( NoseBody == 0 ) NoseBody = point; LeftEyeBody = abs( Open[i - 1] - Close[i - 1] ); if( LeftEyeBody == 0 ) LeftEyeBody = point; // Bearish Pinbar if( High[i] - High[i - 1] >= NoseLength * NoseProtruding ) // Nose protrusion { if( NoseBody / NoseLength <= MaxNoseBodySize ) // Nose body to candle length ratio { if( 1 - ( High[i] - Max( Open[i], Close[i] ) ) / NoseLength < NoseBodyPosition ) // Nose body position in bottom part of the bar { if( ( !LeftEyeOppositeDirection ) || ( Close[i - 1] > Open[i - 1] ) ) // Left Eye bullish if required { if( ( !NoseSameDirection ) || ( Close[i] < Open[i] ) ) // Nose bearish if required { if( LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize ) // Left eye body to candle length ratio { if( ( Max( Open[i], Close[i] ) <= High[i - 1] ) && ( Min( Open[i], Close[i] ) >= Low[i - 1] ) ) // Nose body inside Left Eye bar { if( NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody ) // Nose body to Left Eye body ratio { if( NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength ) // Nose length to Left Eye length ratio { if( Low[i] - Low[i - 1] >= LeftEyeLength * LeftEyeDepth ) // Left Eye low is low enough { if( ( !NoseBodyInsideLeftEyeBody ) || ( ( Max( Open[i], Close[i] ) <= Max( Open[i - 1], Close[i - 1] ) ) && ( Min( Open[i], Close[i] ) >= Min( Open[i - 1], Close[i - 1] ) ) ) ) // Nose body inside Left Eye body if required { Down[i] = High[i] + 5 * Point + NoseLength / 5; brpin[i] = True; } } } } } } } } } } } // Bullish Pinbar if( Low[i - 1] - Low[i] >= NoseLength * NoseProtruding ) // Nose protrusion { if( NoseBody / NoseLength <= MaxNoseBodySize ) // Nose body to candle length ratio { if( 1 - ( Min( Open[i], Close[i] ) - Low[i] ) / NoseLength < NoseBodyPosition ) // Nose body position in top part of the bar { if( ( !LeftEyeOppositeDirection ) || ( Close[i - 1] < Open[i - 1] ) ) // Left Eye bearish if required { if( ( !NoseSameDirection ) || ( Close[i] > Open[i] ) ) // Nose bullish if required { if( LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize ) // Left eye body to candle length ratio { if( ( Max( Open[i], Close[i] ) <= High[i - 1] ) && ( Min( Open[i], Close[i] ) >= Low[i - 1] ) ) // Nose body inside Left Eye bar { if( NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody ) // Nose body to Left Eye body ratio { if( NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength ) // Nose length to Left Eye length ratio { if( High[i - 1] - High[i] >= LeftEyeLength * LeftEyeDepth ) // Left Eye high is high enough { if( ( !NoseBodyInsideLeftEyeBody ) || ( ( Max( Open[i], Close[i] ) <= Max( Open[i - 1], Close[i - 1] ) ) && ( Min( Open[i], Close[i] ) >= Min( Open[i - 1], Close[i - 1] ) ) ) ) // Nose body inside Left Eye body if required { Up[i] = Low[i] - 5 * Point - NoseLength / 5; blpin[i] = True; } } } } } } } } } } } } for( i = 1; i < BarCount; i++ ) { if( blpin[i] ) PlotText( "Bull.pin " , i, L[ i ] - 52.5, colorLime ); if( brpin[i] ) PlotText( " Bear pin" , i, H[ i ] + 52.5, colorOrange ); } PlotShapes( shapesmallCircle*brpin, 4, 0, H+5 , 5 ); PlotShapes( shapesmallCircle*blpin, 5, 0, L-5 , -5 ); Filter = brpin OR blpin; AddColumn( brpin, "Bearish Pin", 1.2 ); AddColumn( blpin, "Bullish Pin", 1.2 ); BEntry4 = Ref(blpin,-1) AND H > Ref(h,-1); SEntry4 = Ref(brpin,-1) AND L < Ref(l,-1); _SECTION_END(); //Bulish Pin means buy on next candle //Bearish Pin bar means Short on next candle /////////////////////////////////////////////////////////////////////////////// // Bull & Bear Pin End // /////////////////////////////////////////////////////////////////////////////// EntryBuffer = Param("Entry Buffer", .7,0,10,.1); _O =O; _H=H; _L = L; _C = C; //Target in Percentage Target = Param("Target Multiplier", 1,1,40,.1); //Stoploss in Percentage InitialSL = Param("Stoploss BUffer %", 1,1,40,.1); Offset = 100; _SECTION_BEGIN( "Functions" ); SymName = "BANKNIFTY";//Name(); DMY = ParamStr("DMY","16SEP21"); BaseName = StrReplace( SymName, "-I.NFO", "" ); StepSize = 100; PostNameCE = "CE.NFO"; PostNamePE = "PE.NFO"; function StrikeSelection( price ) { return round( price / StepSize ) * StepSize; } function ATMStrikeC( price ) { return BaseName + DMY + price + PostNameCE; } function ATMStrikeP( price ) { return BaseName + DMY + price + PostNamePE; } daycheck =ValueWhen(blpin,DateNum()); dayreset = daycheck==DateNum(); daycheck1 =ValueWhen(brpin,DateNum()); dayreset1 = daycheck1==DateNum(); "dayreset = "+dayreset; "dayreset1 = "+dayreset1; call = blpin AND dayreset ; put = brpin AND dayreset1 ; BLhigh = ValueWhen(call AND dayreset, H); BLlow = ValueWhen(call AND dayreset, L); Brhigh = ValueWhen(put AND dayreset1, H); Brlow = ValueWhen(put AND dayreset1, L); BLrange = BLhigh - BLlow; BRrange = Brhigh - Brlow; call1 = Ref(blpin,-1) ; put1 = Ref(brpin ,-1) ; //printf( "\ndayreset1 " + blpin +"\n"); //printf( "\nBreakout Price " + BuyPrice +"\n"); CStrikeSelection = ValueWhen(call, StrikeSelection(c) + Offset); PStrikeSelection = ValueWhen(put, StrikeSelection(c) - Offset); printf("\nCStrikeSelection " + CStrikeSelection + "\n"); printf("\nPStrikeSelection " + PStrikeSelection + "\n"); /////////////////////////////////////////////////////////////////////////////// // For Loop Section // /////////////////////////////////////////////////////////////////////////////// _SECTION_BEGIN( "Main" ); DT = DateTime(); DN = DateNum(); Buy = Sell = Short = Cover = 0; nd = Day() != Ref( Day(), -1 ); bsnd = BarsSince( nd ) + 1; tn = TimeNum(); priceatbuy = 0; highsincebuy = 0; exit = sexit = 0; Cover = Sell = 0; price = 0; SLP = TP = 0; ASLP = ATP = 0; OptionName = ""; TodayDate = LastValue( dn ); EntryPriceWB = 0; BuyPrice = Null; test = 0; CPType = 0; ACPType = 0; EntryTypeCEPE =0; CEL = 0; PEH =0; OptionNameonEntry = ""; PreviousOptionNameonEntry =""; extype = 0; for( i = 1; i < BarCount; i++ ) { if( dn[i] < TodayDate ) continue; if( nd[i] ) { priceatbuy = 0; PriceatShort = 0; EntryPriceWB = 0; } if( priceatbuy > 0 ) { if(exit == 0 AND _h[ i ] >= TP AND EntryTypeCEPE == 1 ) //Long Target Achieved { exit = 1; SellPrice[i] = TP; } if( exit == 0 AND _L[i] < SLP AND EntryTypeCEPE == 1) // Long Normal Stoploss Exit { exit = 4; SellPrice[i] = SLP; } if(exit == 0 AND _l[ i ] <= TP AND EntryTypeCEPE == 2 ) // Short Target Achieved { exit = 1; SellPrice[i] = TP; } if( exit == 0 AND _h[i] > SLP AND EntryTypeCEPE == 2) // Short Normal Stoploss Exit { exit = 4; SellPrice[i] = SLP; } if( exit == 0 AND( ( EntryTypeCEPE == 1 AND put1[i] ) OR( EntryTypeCEPE == 2 AND call1[i] ) ) ) // Reverse Signal Exit { exit = 6; SellPrice[i] = O[i]; } if( exit == 0 AND( Exittimecondition[i] ) ) // Time Exit { exit = 7; SellPrice[i] = O[i]; } extype[i] = exit; if( exit > 0 ) { PreviousOptionNameonEntry = OptionNameonEntry; Sell[ i ] = exit; // mark appropriate exit code exit = 0; priceatbuy = 0; // reset price EntryPriceWB = 0; RestorePriceArrays(); } } if( call1[ i ] ) { OptionName = ATMStrikeC( CStrikeSelection[i] ); SetForeign( OptionName ); TH = H[i-1]; EntryPriceWB = TH[i] * ( 1 + EntryBuffer / 100 ); CPType = 1; CEl = _L[i]; } if( put1[ i ] ) { OptionName = ATMStrikeP( PStrikeSelection[i] ); SetForeign( OptionName ); TH = H[i-1]; EntryPriceWB = TH[i] * ( 1 + EntryBuffer / 100 ); CPType = 2; PEH = _H[i]; } if( priceatbuy == 0 AND H[i] > EntryPriceWB AND EntryPriceWB AND YEntrytimecondition[i] ) { priceatbuy = EntryPriceWB; OptionNameonEntry = OptionName; Buy[i] = 1; EntryTypeCEPE = CPType; if(CPtype==1) { SLP = BLlow[i]; TP = BLhigh[i] + (BLrange[i]*target); } if( CPtype==2) { SLP = Brhigh[i]; TP = BRlow[i] - (BRrange[i]*target); } } ACPType[i] = CPType; if( priceatbuy ) BuyPrice[i] = priceatbuy; else BuyPrice[i] = EntryPriceWB; ATP[i] = TP[i]; ASLP[i] = SLP[i]; } printf("Current Strike " + OptionName); _SECTION_END(); _SECTION_BEGIN( "Plotting" ); Sell = Sell AND 1; if( NOT status( "action" ) == actionScan ) { printf( "\nExtype " + Extype +"\n"); printf( "\nBreakout Price " + BuyPrice +"\n"); printf( "\nTarget Price " + ATP +"\n"); printf( "\nStoploss Price " + ASLP +"\n"); ExitType = LastValue( Sell ); if( ExitType == 6 ) Printf( "Exiting Based on Reverse Signal" ); LF= Flip(Buy,Sell); SF = Flip(Short,Cover); Plot( IIf( ATP>0, ATP, null ), "TP",colorGreen,styleLine); Plot( IIf( ASLP>0, ASLP, null ), "SL",colorREd,styleLine); PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorWhite, 0, _l, -25 ); PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), IIf(ACPType==1,colorGreen,colorRed), 0, _L, -25 ); PlotShapes( IIf( sell, shapeSquare, shapeNone ), colorWhite, 0, _H, 20 ); PlotShapes( IIf( sell, shapeSmallCircle, shapeNone ), colorGreen, 0, _H, 20 ); } printf("\nEntry Symbol :- " + OptionNameonEntry + "\n"); printf("\nExit Symbol :- " + PreviousOptionNameonEntry + "\n"); //////************** By Easyalgo.in *************////// ////// +91-8448735946, Support@easyalgo.in /////////// //***************************************************// GfxSetBkMode(1); _SECTION_BEGIN("NMN Chart Stamp"); SetFormulaName("NMN Chart Stamp"); GfxFont = "Times New Roman"; GfxSetOverlayMode(0); GfxSelectFont(GfxFont, Status("pxheight")/25); GfxSetTextAlign(6); // center alignment GfxSetTextColor(ColorRGB(100,100,100)); GfxSetBkMode(0); // transparent GfxTextOut(Name(), Status("pxwidth")/2, Status("pxheight")/12); GfxSetTextColor(ColorRGB(200,200,200)); GfxTextOut("Easyalgo.in", Status("pxwidth")/1.15, Status("pxheight")/1.15); //GfxSelectFont(GfxFont, Status("pxheight")/28); //GfxSelectFont(GfxFont, Status("pxheight")/18); //GfxSelectFont("Tahoma", Status("pxheight")/18); _SECTION_END();