_SECTION_BEGIN("Neeraj Darvas 09APR2023"); _SECTION_BEGIN("BOTTOM1"); ///*AutoTrade*/ // #include // IB_AutoTrade(); ///////////// _SECTION_END(); 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 ) ); candle = ParamToggle("Candle HA or Normal","Normal|Heikenashi",1); if(candle) { C1 = HaClose; O1 = HaOpen; H1 = HaHigh; L1 = HaLow; } else { C1 = c; O1 = o; H1 = h; L1 = l; } barcolor = IIf(C1 >= o1,colorGreen,colorRed); PlotOHLC( O1, H1, L1, C1, "", barcolor, styleCandle ); SetChartOptions(0,chartShowArrows|chartShowDates); //printf( "\nExtype " + Extype +"\n"); //printf( "\nBP " + BP +"\n"); _SECTION_END(); _SECTION_BEGIN("New Chart"); SetOption("WarningLevel",True); //barcolor = ((IIf(C>O,colorGreen,colorRed))); //SetBarFillColor(barcolor); //Plot( C, "Price", barcolor, styleCandle ); //SetBarsRequired( sbrAll,sbrAll); GraphXSpace=Param("Chart",10,-100,10000,1); x2 = Status("pxchartright"); y2 = Status("pxchartleft"); SetOption("WarningLevel",True); GfxSelectPen( colorGreen, 2 ); GfxSelectSolidBrush( colorDarkTeal); GfxRectangle( 3, 2, x2, 53 ); GfxSelectFont( "Tahoma", Param("Text Size,",15), 350 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorBrightGreen ); GfxTextOut(""+Interval(2),y2+20,15); GfxSetTextColor(colorred ); GfxTextOut(" "+DateTimeToStr(SelectedValue(DateTime())),y2+120,15); GfxSetTextColor( colorAqua ); GfxTextOut("Open = "+O1,y2+380,15); GfxSetTextColor( colorbrightGreen ); GfxTextOut("High = "+H1,y2+580,15); GfxSetTextColor( colorRed ); GfxTextOut("Low = "+L1,y2+780,15); GfxSetTextColor( colorYellow ); GfxTextOut("Close = "+C1,y2+960,15); GfxSetTextColor( colorTurquoise ); GfxTextOut("ROC % = "+Prec(SelectedValue( ROC( C, 1 ) ),2),y2+1160,15); _SECTION_END(); dn = Day(); newday = dn != Ref( dn, -1 ); bar=BarsSince(newday); //_SECTION_BEGIN("Indicator Setting"); _SECTION_BEGIN("Intraday Timing Condition"); Intra = ParamToggle("Intraday Mode On/Off","OFF|ON",1); FirstTradeTime = ParamTime( "First Session Start Time", "09:15" ); // Earliest time to take a trade LastTradeTime = ParamTime( "First Session End Time", "15:00" ); // Latest time to take new trades FirstTradeTime1 = ParamTime( "Second Session Start Time", "1:30" ); // Earliest time to take a trade LastTradeTime1 = ParamTime( "Second Session End Time", "15:00" ); // Latest time to take new trades ExitAllPositionsTime = ParamTime( "Exit Time", "15:15" ); // Exit all trades _SECTION_BEGIN("Trade Direction Long/Short"); dir = ParamList("Trade Direction Long/Short/Both","Long_Only|Short_Only|Both",2); _SECTION_BEGIN("Trade Setting"); maxtrade = Param("Max Trade Per Day ",10,01,1000,1); Type = ParamToggle("Entry Buffer Point or Percent","Percent|Point",0); type1 = ParamList("Stoploss Type","Percent|Point|Darvas",2); buf = Param("Entry Buffer ",.00,0.000,1000,0.05); BT = Param("Take Profit 1(Risk:Reward)",1,0.1,10,0.5); BT2 = Param("Take Profit 2(Risk:Reward)",2,0.1,10,0.5); SL = Param("Stop Loss ",0.45,0.1,1000,0.5); TrailOn = ParamToggle("Trail Method (From Entry or From Target 1)","From Entry Point |After Initial Target",1); //Trailtype = ParamToggle("Trail Type ATR or Higher High lower low ","ATR|HHLL",0); _SECTION_END(); _SECTION_BEGIN("Indicator Setting"); WM = ParamToggle("Mavlin OR WAdah Rule AND/OR","AND|OR",1); emaLength = Param("EMA Length ",5,1,100,1); boxp = Param("Box Length",5,1,100,1); fmal = Param("First Moving Average length",3,1,100,1); smal = Param("Second Moving Average length",5,1,100,1); sensitivity = Param("Sensitivity",150,1,1000,1); fastLength = Param("FastEMA Length",20,1,1000,1); slowLength = Param("SlowEMA Length",40,1,1000,1); r3 = Param( "Signal avg", 9, 2, 200, 1 ); channelLength = Param("BB Channel Length",20,1,1000,1); mult = Param("BB Stdev Multiplier",2.0,0.1,10,0.1); ero = Param("ATR multiple", 1, 0.5, 10, 0.1 )*Param("ATR period", 8, 3, 50 ); _SECTION_END(); _SECTION_BEGIN("Indicator Show/Hide"); plotbox = ParamToggle("Plot TBbox/BBbox","Off|On",1); plotmavw = ParamToggle("Plot MAVW","Off|On",0); mavilimold = ParamToggle("Show Previous Version of MavilimW?","Off|On",0); _SECTION_END(); _SECTION_BEGIN("Stoxxo Setting"); EntryQty = Param("Lot Size for Entry",2,2,1000,1); PExitQty = Param("Lot Size for Partial Exit ",1,1,1000,1); iab_stag = ParamStr("Strategy Tag", "DARVAS"); _SECTION_END(); if (Intra) { Entrytimecondition = (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime ) OR (TimeNum() >= FirstTradeTime1 AND TimeNum() <= LastTradeTime1 ); Exittimecondition = Cross(TimeNum(),ExitAllPositionsTime); } else { Entrytimecondition = True; Exittimecondition = false; } EMA1 = ema(C1,emaLength); Plot( EMA1,"EMA" ,colorOrange,styleLine,Null,Null,0,0,1); LL = LLV(L1,boxp); k1 = HHV(H1,boxp); k2 = HHV(H1,boxp-1); k3 = HHV(H1,boxp-2); NH = valuewhen(H1>Ref(k1,-1),H1) ; box1 =k3Ref(k1,-1))==boxp-2 and box1, NH); BottomBox = valuewhen(barssince(H1>Ref(k1,-1))==boxp-2 and box1, LL) ; Plot( IIf(plotbox,TopBox,Null),"TopBox" ,colorGreen,styleLine,Null,Null,0,0,2); Plot(IIf(plotbox, BottomBox,Null),"BottomBox" ,colorred,styleLine,Null,Null,0,0,2); tmal=fmal+smal ; Fmal=smal+tmal ; Ftmal=tmal+Fmal ; Smal=Fmal+Ftmal ; M1= wma(C1, fmal) ; M2= wma(M1, smal); M3= wma(M2, tmal) ; M4= wma(M3, Fmal); M5= wma(M4, Ftmal); MAVW= wma(M5, Smal); col1= MAVW>Ref(MAVW,-1); col3= MAVW= 0) , t1 , 0); trendDown = IIf((t1 < 0) , (-1*t1) , 0); BWadah = trendUp and (trendUp > DEAD_ZONE); Swadah = trendDown and (trendDown > DEAD_ZONE) ; BMavlin = (C1 > MAVW); Smavlin = (C1 < MAVW); r=HHV(H1,ero); s=LLV(L1,ero); ab=IIf(H1>Ref(r,-1),1,IIf(L1 EMA1) and (C1 > TopBox) and BRule3 AND Entrytimecondition AND (dir=="Long_Only" OR dir=="Both"); _short = (C1 < EMA1) and (C1 < BottomBox) and SRule3 AND Swadah AND Entrytimecondition AND (dir=="Short_Only" OR dir=="Both"); _Sell = Ref(Cross(Sl2,C1),-1); _cover = Ref(Cross(C1,sl2),-1); //PlotShapes(_buy*shapeStar,colorGold,0,Graph0,-15); //PlotShapes(_short*shapeStar,colorGold,0,Graph0,-15); dayvalid = ((O1 < TopBox and C1 > TopBox) or (O1 > BottomBox and C1 < BottomBox)) and Entrytimecondition; dayflag = 0; Buy = Sell = Short = Cover = TSL = Null; buyh = refbsl = refbtp = refbtp2 =0; shortl = refssl = refstp = refstp2 =0; LongFlag = ShortFlag = Target = _BuyPrice = ShortTarget=ShortTarget2=st2 = 0; //Simple flags _shortprice = buytarget=shorttarget=t=st=bsl=ssl=bp=sp=buytarget2=0; buysl = shortsl=0; Starget= sstoploss = 0; LF=SF=0; Btarget = Starget = BSL = SSL = TradeCounter = TC = Check = 0; Btarget2 = Starget2 = 0; Check1 = ""; ExitType = 0; BTflag=Stflag=0; trailARRAY = Null; trailstop = 0; StrailARRAY = Null; Strailstop = 0; BTTF = STTF =0; sell3=cover3=0; Xqty1=EntryQty; xqty= 0; //Using Loop to generate signals for( i = 1; i < BarCount; i++ ) { /////////////////////////////////////////Long Positions if (newday[i]) { buyh = 100000; shortl = 0; refbsl = 0; refssl = 0; refbtp = 0; refstp = 0; TradeCounter = 0; BuyPrice = Null; ShortPrice = Null; SellPrice = Null; CoverPrice = Null; Xqty1 = EntryQty[i]; } if (dayvalid[i]) { Dayflag = 1 ; } if (Exittimecondition[i]) { Dayflag = 0 ; } if (C[i-1] < TopBox[i-1] AND LongFlag == 0 AND ShortFlag==0 AND Dayflag==1) { buyh = 100000; } if (_buy[i-1] AND LongFlag == 0 AND ShortFlag==0 AND Dayflag==1) { if ( type==0) { buyh = c1 [i-1] * (1+(buf/100)); } else { buyh = c1 [i-1] + (buf); } if ( type1=="Percent") { refbsl = buyh[i]*(1-(SL/100)); } else if (type1=="Point") { refbsl = buyh[i] - sl; } else { refbsl = BottomBox[i]; } refbtp = buyh[i] + ((TopBox[i]-BottomBox[i])* bt); refbtp2 = buyh[i] + ((TopBox[i]-BottomBox[i])* bt2); } if (C[i-1] > BottomBox[i-1] AND LongFlag == 0 AND ShortFlag==0 AND Dayflag==1) { shortl = 0; } if (_short[i-1] AND LongFlag == 0 AND ShortFlag==0 AND Dayflag==1) { if ( type==0) { shortl = c1 [i-1] * (1-(buf/100)); } else { shortl = c1 [i-1] - (buf); } if ( type1=="Percent") { refssl = shortl[i]*(1+(SL/100)); } else if (type1=="Point") { refssl = shortl[i] + sl; } else { refssl = TopBox[i]; } refstp = shortl[i] - ((TopBox[i]-BottomBox[i]) * bt); refstp2 = shortl[i] - ((TopBox[i]-BottomBox[i]) * bt2); } if (BTflag[i]==1 AND Longflag==1) { trailstop = Max( buysl[i] , L1[i-1] ); trailARRAY[ i ] = trailstop[i]; } if( LongFlag==1 AND High[i]>buytarget[i] AND BTflag==0 AND ! Exittimecondition[i]) { buysl = _BuyPrice[i] ; Sell3[ i ] = 1; SellPrice[i] = buytarget[i]; //LongFlag = 0; ExitType[i] = 1; BTflag = 0; trailstop = 0; BTflag = 1; Xqty1 = PExitQty; } if( LongFlag==1 AND High[i]>buytarget2[i] ) { Sell[ i ] = 1; SellPrice[i] = buytarget2[i]; LongFlag = 0; ExitType[i] = 2; BTflag = 0; trailstop = 0; Xqty1 = EntryQty - PExitQty; } if( LongFlag==1 AND L[i] < trailstop[i] AND False ) { Sell[ i ] = 1; SellPrice[i] = trailstop[i]; if(BTflag) Xqty1 = EntryQty - PExitQty; else xQty1 = EntryQty; _TRACE("Trail Stop Code BTFlag " + BTFlag + " Qty : " + xQty1 ); LongFlag = 0; ExitType[i] = 3; BTflag = 0; trailstop = 0; BTflag = 0; trailstop = 0; } if( LongFlag==1 AND L[i] < buysl[i]) { Sell[ i ] = 1; SellPrice[i] = buysl[i]; if(BTflag) Xqty1 = EntryQty - PExitQty; else xQty1 = EntryQty; LongFlag = 0; ExitType[i] = 4; BTflag = 0; trailstop = 0; //_TRACE(" Stop Code BTFlag " + BTFlag + " Qty : " + xQty1 ); } else if(LongFlag==1 AND Exittimecondition[i]) { Sell[ i ] = 1; SellPrice[i] = Open[i]; if(BTflag) Xqty1 = EntryQty - PExitQty; else Xqty1 = EntryQty ; LongFlag = 0; ExitType[i] = 5; BTflag = 0; trailstop = 0; } else if(LongFlag==1 AND _sell[i] AND (Btflag==1 OR TrailOn==0) ) { Sell[ i ] = 1; SellPrice[i] = O[i]; if(BTflag) Xqty1 = EntryQty - PExitQty; else Xqty1 = EntryQty; LongFlag = 0; ExitType[i] = 6; BTflag = 0; trailstop = 0; } /////////////////////////////////////////////////Short Positions if (STflag[i]==1 AND ShortFlag==1) { strailstop = Min( Shortsl[i] , H1[i-1] ); strailARRAY[ i ] = strailstop[i]; } if( ShortFlag==1 AND High[i]>Shortsl[i] ) { Cover[ i ] = 1; if(STflag) Xqty1 = EntryQty - PExitQty; else Xqty1 = EntryQty; CoverPrice[i] = Shortsl[i]; ShortFlag = 0; ExitType[i] = 11; STflag = 0; strailstop = 0; } if( ShortFlag==1 AND L[i] < shorttarget[i] AND STflag==0 AND ! Exittimecondition[i]) { Shortsl = _ShortPrice[i]; Cover3[ i ] = 1; Xqty1 = PExitQty; coverPrice[i] = shorttarget[i]; //ShortFlag = 0; ExitType[i] = 12; STflag = 0; strailstop = 0; STflag = 1; } if( ShortFlag==1 AND L[i] < shorttarget2[i] ) { Cover[ i ] = 1; coverPrice[i] = shorttarget2[i]; if(STflag) Xqty1 = EntryQty - PExitQty; ShortFlag = 0; ExitType[i] = 13; STflag = 0; strailstop = 0; STflag = 0; } if(ShortFlag==1 AND Exittimecondition[i]) { Cover[ i ] = 1; COverPrice[i] = Open[i]; if(STflag) Xqty1 = EntryQty - PExitQty; else Xqty1 = EntryQty ; ShortFlag = 0; ExitType[i] = 14; STflag = 0; strailstop = 0; } else if(ShortFlag==1 AND _cover[i] AND (Stflag==1 OR TrailOn==0)) { Cover[ i ] = 1; COverPrice[i] = Open[i]; if(STflag) Xqty1 = EntryQty - PExitQty; else Xqty1 = EntryQty ; ShortFlag = 0; ExitType[i] = 15; STflag = 0; strailstop = 0; } //////////////// BUY SELL /////////////////////////// if( High[ i ] > buyh[i] AND LongFlag == 0 AND ShortFlag==0 AND Entrytimecondition[i] AND TradeCounter[i] <= MaxTrade AND Dayflag==1) { Buy[ i ] = 1; BuyPrice[i] = buyh[i]; _BuyPrice = buyh[i]; LongFlag = 1; buytarget = refbtp[i] ; buytarget2 = refbtp2[i] ; buysl = refbsl[i] ; buyh = 100000; refbsl = 0; refbtp = 0; Xqty1 = EntryQty[i]; trailstop = buysl[i]; BTflag = 0; } if( LongFlag==1 AND High[i]>buytarget[i] AND BTflag==0 ) { buysl = _BuyPrice[i] ; Sell3[ i ] = 1; SellPrice[i] = buytarget[i]; ExitType[i] = 7; trailstop = 0; BTflag = 1; Xqty1 = PExitQty; } if( LongFlag==1 AND High[i]>buytarget2[i] ) { Sell[ i ] = 1; SellPrice[i] = buytarget2[i]; LongFlag = 0; ExitType[i] = 8; BTflag = 0; trailstop = 0; Xqty1 = EntryQty - PExitQty; } if( Low[ i ] < shortl[i] AND LongFlag == 0 AND ShortFlag==0 AND Entrytimecondition[i] AND TradeCounter[i] <= MaxTrade AND Dayflag==1) { Short[ i ] = 1; ShortPrice[i] = shortl[i]; _ShortPrice = shortl[i]; ShortFlag = 1; shorttarget = refstp[i] ; shorttarget2 = refstp2[i] ; Shortsl = refssl[i]; shortl = 0; refssl = 0; refstp = 0; Xqty1 = round(EntryQty[i]); strailstop = Shortsl[i]; STflag = 0; } if( ShortFlag==1 AND L[i] < shorttarget[i] AND STflag==0) { Shortsl = _ShortPrice[i]; Cover3[ i ] = 1; coverPrice[i] = shorttarget[i]; ExitType[i] = 17; strailstop = 0; STflag = 1; Xqty1 = PExitQty; } if( ShortFlag==1 AND L[i] < shorttarget2[i]) { Cover[ i ] = 1; coverPrice[i] = shorttarget2[i]; if(STflag) Xqty1 = EntryQty - PExitQty; ShortFlag = 0; ExitType[i] = 18; STflag = 0; strailstop = 0; STflag = 0; Xqty1 = EntryQty - PExitQty; } if (Buy[i]==1 OR Short[i]==1) { TradeCounter +=1; Xqty1 = round(EntryQty); } /* if((sell3[i]==1 && ! Sell[i]) OR (cover3[i]==1 && !Cover[i])) { Xqty1 = PExitQty; } */ Btarget[i] = buyTarget[i]; Starget[i] = ShortTarget[i]; Btarget2[i] = buyTarget2[i]; Starget2[i] = ShortTarget2[i]; bsl[i] = buysl[i]; ssl[i] = shortsl[i]; bp[i] = _buyprice[i]; sp[i] = _shortprice[i]; LF[i] = longflag[i];; SF[i] = shortflag[i]; TC[i] = TradeCounter[i]; Xqty[i] = Xqty1; BTTF[i] = BTflag[i]; STTF[i] = STflag[i]; } "TC = "+TC; "ExitType = "+ExitType; ""; "BP = "+bp; "BT 1 = "+Btarget; "BT 2 = "+Btarget2; "BSL = "+bsl; "LF = "+lf; ""; "SP = "+Sp; "ST 1 = "+Starget; "ST 2 = "+Starget2; "SSL = "+Ssl; "SF = "+SF; Buyflag = Flip(Buy,Sell AND lf==0); Shortflag11 = Flip(Short,Cover AND sf==0); Plot(IIf(Buyflag,Btarget,Null),"Buy Target",colorGreen,styleThick,Null,0,0,0,2); Plot(IIf(Shortflag11,Starget,Null),"Short Target",colorGreen,styleThick,Null,0,0,0,2); Plot(IIf(Buyflag,Btarget2,Null),"Buy Target 2",colorGreen,styleThick,Null,0,0,0,2); Plot(IIf(Shortflag11,Starget2,Null),"Short Target 2",colorGreen,styleThick,Null,0,0,0,2); BT = Btarget; ST = Starget; BTt = Btarget2; STt = Starget2; Plot(IIf(Buyflag,bsl,Null),"Buy SL",colorRed,styleThick); Plot(IIf(Shortflag11,SSL,Null),"Short SL",colorRed,styleThick); Plot(IIf(Buyflag,BP,Null),"BuyPrice",colorWhite,styleDashed|styleThick); Plot(IIf(Shortflag11,SP,Null),"ShortPrice",colorWhite,styleDashed|styleThick); //Plot(IIf(Buyflag,trailARRAY,Null),"trailARRAY",colorYellow,styleLine|styleThick,Null,Null,0,0,2); //Plot(IIf(Shortflag11,StrailARRAY,Null),"StrailARRAY",colorYellow,styleLine|styleThick,Null,Null,0,0,2); Plot(IIf(Buyflag AND (BTTF OR trailon==0),sl2,Null),"ATR SL Buy", colorYellow, styleStaircase,Null,0,0,0,2); // or styleaArea Plot(IIf(Shortflag11 AND (STTF OR trailon==0),sl2,Null), "ATR SL Short", colorYellow, styleStaircase,Null,0,0,0,2); // or styleaArea PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L1, Offset = -40 ); PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L1, Offset = -50 ); PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L1, Offset = -45 ); PlotShapes( IIf( Sell OR sell3 , shapeDownArrow, shapeNone ), colorRed, 0, H1+1, Offset = -45 ); PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H1, Offset = 40 ); PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H1, Offset = 50 ); PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H1, Offset = -45 ); PlotShapes( IIf( Cover OR cover3, shapeUpArrow, shapeNone ), colorYellow, 0, L1, Offset = -45 ); Stock_OPT_Round = Param("Stock Option Round Value",10); Spot = WriteIf(Name()=="BANKNIFTY" OR Name()=="BANKNIFTY-FUT" OR Name()=="BANKNIFTY_I","BANKNIFTY",WriteIf(Name()=="NIFTY" OR Name()=="NIFTY-FUT" OR Name()=="NIFTY_I","NIFTY",Name())); Strike_Round = iif(Name()=="BANKNIFTY" OR Name()=="BANKNIFTY-FUT" OR Name()=="BANKNIFTY_I",100,iif(Name()=="NIFTY" OR Name()=="NIFTY-FUT" OR Name()=="NIFTY_I",100,Stock_OPT_Round)); Feeder = "Amifeed" ; weeklyFlag = ParamToggle( "Expiry type" , "Monthly|Weekly", 1 ); ExpiryOp = ParamDate( "Expiry Date (Options)", "11-01-2024", 2 ); CE_interval = Param("CALL Strike Interval",0,0,10000,100); PE_interval = Param("PUT Strike Interval",0,0,10000,100); Strike_CE = bp ; Strike_PE = sp ; CE_Round =(round((Strike_CE)/Strike_Round)*Strike_Round)+CE_interval; PE_Round =(round((Strike_PE)/Strike_Round)*Strike_Round)+PE_interval; if( Feeder == "AccelPix" ) { //DateStr = DateTimeFormat( "%d", expiryOp ); // expiryPre = WriteIf( weeklyFlag, DateStr + StrToUpper( DateTimeFormat( "%b", expiryOp ) ) + DateTimeFormat( "%y", expiryOp ), StrToUpper( DateTimeFormat( "%b", expiryOp ) ) + DateTimeFormat( "%y", expiryOp ) ); CE_Symbol = Spot + LastValue( CE_Round ) + expiryPre + "CE"; PE_Symbol = Spot + LastValue( CE_Round ) + expiryPre + "PE"; } else if( Feeder == "Amifeed" ) { CE_Symbol = Spot+"WK"+CE_Round+"CE" ; PE_Symbol = Spot+"WK"+PE_Round+"PE" ; } GfxTextOut( "CE : "+CE_Symbol,30,80); GfxTextOut( "PE : "+PE_Symbol,30,110); _SECTION_BEGIN("Explorer"); Filter = (Buy OR Sell); //AddTextColumn(WriteIf(Buy,"Buy","Sell"),"Buy/Sell"); _SECTION_BEGIN("EXPLORATION"); Filter=Buy or Sell OR Short OR cover; SetSortColumns(-0); //AddSummaryRows(TYPE=10,1.2,ONLYCOL=0); SetOption( "NoDefaultColumns", True ); AddTextColumn( Name(), "Ticker", 1, fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed), 120 ); AddColumn( Datetime(), "DateTime",formatDateTime, colorDefault, colorDefault, 120 ); AddColumn(C,"LTP",1.2,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),80); AddColumn(V,"VOL",1.2,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),80); AddColumn(OI,"OPENINT",1.2,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),80); AddColumn(IIf(Buy,'B','S'),"S",formatChar,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),20); AddColumn(IIf(Buy,'U','E'),"I",formatChar,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),20); AddColumn(IIf(Buy,'Y','L'),"D",formatChar,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),20); AddColumn(IIf(Buy,'Y','L'),"E",formatChar,fgcolor=IIf(Buy,colorWhite,colorWhite),bkcolor=IIf(Buy,colorGreen,colorRed),20); _SECTION_END(); GfxSelectFont( "Tahoma", 11, 110 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); GfxSetBkMode(1); GfxSelectFont( "Tahoma", 11, 100 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); boxcolor =StrToNum( ""+IIf(Buyflag,colorGreen,IIf(Shortflag11,colorDarkRed,colorDarkTeal))); EnableTextOutput(1); ""+boxcolor; ""+ colorGreen; ""+colorDarkRed; ""+ colorDarkTeal; GfxSelectSolidBrush( colorDarkTeal ); // this is the box background color pxHeight = Status( "pxchartheight" ) ; xx = Status( "pxchartwidth" ); Left = 1100; width = 310; x = 5; x2 = 310; y = pxHeight; GfxSelectPen( colorGreen, 1 ); // broader color GfxRoundRect( x, y - 200, x2-130, y-30 , 7, 7 ) ; RequestTimedRefresh( 1, False ) ; Sfs = WriteIf(Sf==1,"1","0"); Sfs1 = WriteIf(Ref(Sf==1,-1) OR sf==1,"1","0"); lfs = WriteIf(lf==1,"1","0"); lfs1 = WriteIf(Ref(lf==1,-1) OR lf==1,"1","0"); bpnlc =StrToNum(""+IIf(Buyflag AND c - bp > 0,colorGreen,colorRed)); pnlc =StrToNum(""+IIf(Shortflag11 AND sp - C > 0,colorGreen,colorRed)); if (sfs1=="1") { GfxSelectFont( "", 15, 300 ); //GfxTextOut("NEERAJ DARVAS", Status("pxwidth")/ 64.7, Status("pxheight")/ 1.60 ); GfxSelectFont( "Tahoma", 10, 300 ); GfxTextOut("Trade Dir : "+"SHORT", Status("pxwidth")/ 64.7, Status("pxheight")/ 1.35 ); GfxTextOut("Symbol : "+Name(), Status("pxwidth")/ 64.7, Status("pxheight")/ 1.31 ); GfxTextOut("Entry Price : "+sp, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.275 ); GfxTextOut("Target 1 : "+st, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.24 ); GfxTextOut("Target 2 : "+STT, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.205 ); GfxTextOut("Stoploss : "+ssl, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.175 ); GfxTextOut("Trail SL : "+sl2, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.145 ); GfxSetTextColor( pnlc ); GfxTextOut("PnL : "+Prec((sp-C),2) , Status("pxwidth")/64.7, Status("pxheight")/ 1.115 ); GfxSelectFont( "Tahoma", 20, 150 ); GfxTextOut("PnL : "+Prec((sp-C),2),y2+1520,10); } else if (lfs1=="1") { GfxSelectFont( "", 15, 300 ); //GfxTextOut("NEERAJ DARVAS", Status("pxwidth")/ 64.7, Status("pxheight")/ 1.60 ); GfxSelectFont( "Tahoma", 10, 300 ); GfxTextOut("Trade Dir : "+"BUY", Status("pxwidth")/ 64.7, Status("pxheight")/ 1.35 ); GfxTextOut("Symbol : "+Name(), Status("pxwidth")/ 64.7, Status("pxheight")/ 1.31 ); GfxTextOut("Entry Price : "+bp, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.275 ); GfxTextOut("Target 1 : "+bt, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.24 ); GfxTextOut("Target 2 : "+BTT, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.205 ); GfxTextOut("Stoploss : "+Bsl, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.175 ); GfxTextOut("Trail SL : "+sl2, Status("pxwidth")/ 64.7, Status("pxheight")/ 1.145 ); GfxSetTextColor( bpnlc ); GfxTextOut("PnL : "+Prec((c-bp),2) , Status("pxwidth")/64.7, Status("pxheight")/ 1.115 ); GfxSelectFont( "Tahoma", 20, 150 ); GfxTextOut("PnL : "+Prec((c-bp),2) ,y2+1520,10); } else { GfxSelectFont( "Tahoma", 20, 150 ); GfxTextOut("No Position", Status("pxwidth")/ 64.7, Status("pxheight")/ 1.17 ); } GfxSelectFont( "Tahoma", 20, 150 ); GfxSetTextColor( colorOrange ); GfxTextOut("QTY = "+Xqty,y2+1350,10); GfxSetBkMode(1); _SECTION_BEGIN("NMN Chart Stamp"); SetFormulaName("NMN Chart Stamp"); GfxFont = "Times New Roman"; GfxSetOverlayMode(0); GfxSelectFont(GfxFont, Status("pxheight")/18); GfxSetTextAlign(6); // center alignment GfxSetTextColor(ColorRGB(100,100,100)); GfxSetBkMode(0); // transparent GfxTextOut(Name(), Status("pxwidth")/2, Status("pxheight")/12); GfxSelectFont(GfxFont, Status("pxheight")/28); GfxSelectFont(GfxFont, Status("pxheight")/18); GfxSelectFont("Tahoma", Status("pxheight")/36); _SECTION_END(); _SECTION_BEGIN("AT AUTOMATION"); DOp = ValueWhen(newday,O); _SECTION_BEGIN("IAB AUTOMATION"); //qty = Param("QTY",1,1,100000,1); iab_limit = 0;//Param("Limit Price %", 0, 0, 10, 0.01) / 100; // percentage better than last trade price iab_quantity =StrToNum(""+xqty);// Param("Quantity", 1050, 0, 10000000, 1); // 0 input implies that quantity will be taken from symbol mapping iab_quantity1 =StrToNum(""+ xQTY); iab_order = "MARKET"; iab_prod=Null; if(Intra==1) { iab_prod = "MIS";/*/*/ } if(Intra==0) { iab_prod = "NRML";/*/*/ } iab_long_symbol = CE_Symbol; iab_short_symbol = PE_Symbol ; iab_short_trade_dir = "S"; iab_se = Short; iab_sx = Cover; VarName = Name()+GetChartID()+"153113"; tn = TimeNum(); if(LastValue(tn) != Nz(StaticVarGet("IBBuyOTime"+VarName))) StaticVarSet("IBBuyO"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBCoverOTime"+VarName))) StaticVarSet("IBCoverO"+VarName,False); iab_time = TimeNum(); oid = 0;//StrToNum(""+round(bp)); oid1 = 0;//StrToNum(""+round(sp)); tn =TimeNum(); _SECTION_BEGIN("IB"); VarName = Name()+GetChartID()+"29551"; if(LastValue(tn) != Nz(StaticVarGet("IBBuyOTime"+VarName))) StaticVarSet("IBBuyO"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBSellOTime"+VarName))) StaticVarSet("IBSellO"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBShortOTime"+VarName))) StaticVarSet("IBShortO"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBCoverOTime"+VarName))) StaticVarSet("IBCoverO"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBSellOTime1"+VarName))) StaticVarSet("IBSellO1"+VarName,False); if(LastValue(tn) != Nz(StaticVarGet("IBCoverOTime1"+VarName))) StaticVarSet("IBCoverO1"+VarName,False); if(LastValue(Sell ) AND Nz(StaticVarGet("IBSellO"+VarName))==False) { _TRACE("CE Exit - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LX", iab_long_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBSellO"+VarName,True); StaticVarSet("IBSellOTime"+VarName,LastValue(tn)); } if(LastValue(Cover ) AND Nz(StaticVarGet("IBCoverO"+VarName))==False) { _TRACE("PE Exit - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LX", iab_short_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid1, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBCoverO"+VarName,True); StaticVarSet("IBCoverOTime"+VarName,LastValue(tn)); } if(LastValue(Sell3 ) AND Nz(StaticVarGet("IBSellO1"+VarName))==False AND Nz(StaticVarGet("IBSellO"+VarName))==False) { _TRACE("CE Exit - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LX", iab_long_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBSellO1"+VarName,True); StaticVarSet("IBSellOTime1"+VarName,LastValue(tn)); } if(LastValue(Cover3 ) AND Nz(StaticVarGet("IBCoverO1"+VarName))==False AND Nz(StaticVarGet("IBCoverO"+VarName))==False) { _TRACE("PE Exit - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LX", iab_short_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid1, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBCoverO1"+VarName,True); StaticVarSet("IBCoverOTime1"+VarName,LastValue(tn)); } if(LastValue(Buy) AND Nz(StaticVarGet("IBBuyO"+VarName))==False) { _TRACE("CE - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LE", iab_long_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBBuyO"+VarName,True); StaticVarSet("IBBuyOTime"+VarName,LastValue(tn)); } if(LastValue(Short) AND Nz(StaticVarGet("IBShortO"+VarName))==False) { _TRACE("PE - "+"QTY = "+iab_quantity); IB_MappedOrderAdv("LE", iab_short_symbol, iab_order, "", "", "", iab_stag, iab_prod, "", oid1, 0, LastValue(C) * (1 + iab_limit), iab_quantity, 0); StaticVarSet("IBShortO"+VarName,True); StaticVarSet("IBShortOTime"+VarName,LastValue(tn)); } _SECTION_END(); GfxSelectFont("Tahoma",12,800); GfxSetTextColor(colorGrey40); GfxTextOut( ""+iab_prod,50,150); ; _SECTION_BEGIN("telegram"); #include _SECTION_END();