0% found this document useful (0 votes)
72 views

Bbband+adx - Evening Code

The document defines indicators and trading logic for a trading strategy that uses ADX and Bollinger Bands. Signals are generated based on the indicator values and timing parameters. The signals are then passed to an Algoji trading interface using static variables to track order IDs and prevent duplicate signals. Buttons are also defined to manually trigger trades via the Algoji interface.

Uploaded by

Animesh Choubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Bbband+adx - Evening Code

The document defines indicators and trading logic for a trading strategy that uses ADX and Bollinger Bands. Signals are generated based on the indicator values and timing parameters. The signals are then passed to an Algoji trading interface using static variables to track order IDs and prevent duplicate signals. Buttons are also defined to manually trigger trades via the Algoji interface.

Uploaded by

Animesh Choubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

_SECTION_BEGIN("Colored ADX histogram Bars");

drt = StDev(C,22)-ATR(15);
range = Param("Periods", 10, 2, 200, 1 );
iadx = HMA(ADX(range),10);
inc = iadx > Ref(iadx,-1);
dec = iadx < Ref(iadx,-1);
//SetChartBkColor(ColorBlend(colorGrey40,colorBlack));

color = IIf(inc AND iadx >40, colorBlue, IIf(inc AND iadx > 30, colorGreen, IIf(inc
AND iadx > 20,colorbrightGreen, IIf(inc, colorPaleGreen,
IIf(dec AND iadx >40, colorBrown, IIf(dec AND iadx > 30 ,
colorDarkRed, IIf(dec AND iadx > 20 , colorRed, IIf(dec,
colorLightOrange,colorGrey40))))))));

//Plot( iadx, _DEFAULT_NAME(), color, styleHistogram | styleThick ) ;

Bollitop = BBandTop(C,20,2);
Bollibottom = BBandBot(C,20,2);

C1 = inc AND iadx >40;


C2 = inc AND iadx >30;
C3 = inc AND iadx > 20;

Cbuy= C1 OR C2 OR C3;

Cshort = C1 OR C2 OR C3 ;

S1 = dec AND iadx >40;


S2 = dec AND iadx > 30;
S3 = dec AND iadx > 20;

Csell = dec AND iadx < 40;

TimeRange = ParamToggle("Time","No|Yes");
Starttime = Param("Starttime",093000,090000,235500,0);
Closetime = Param("Closetime",144000,100000,235500,0);
ExitToday = (Ref(DateNum(),1) > DateNum());

Highmorningbuy = Close>Ref(close,-1) AND Ref(Close,-1) > Ref(Close,-2);


Highmorningshort = Close < Ref(Close,-1) AND Ref(Close,-1) < Ref (Close,-2);

B1= High > Bollitop AND High > Ref(Close,-1) AND Cbuy AND RSI(10)>60 AND
ADX(10)>25 AND drt >0 ;
S1 = Close<EMA(Close,10) ;

Sh1 = Low < Bollibottom AND Cshort AND RSI(10)<40 AND ADX(10)>25 AND drt >0 ;

Co1 = Close>EMA(Close,10) ;

Buy = IIf(TimeRange==False,B1,B1 AND TimeNum() > Starttime AND TimeNum() <


Closetime);
Sell = IIf(TimeRange==False,S1,S1 OR TimeNum() > Closetime OR ExitToday);
Short = IIf(Timerange==False,Sh1,Sh1 AND TimeNum() > Starttime AND TimeNum() <
Closetime);
Cover = IIf(Timerange==False,Co1,Co1 OR TimeNum() > Closetime OR ExitToday);

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

Short =ExRem (Short,Cover);


Cover = ExRem(Cover,Short);

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorDarkGreen, 0, L, Offset=-40);


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorDarkGreen, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-40);


PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorwhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorDarkRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorDarkRed, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

//section begins for auto trade

instr= ParamList("Instrument Name","|EQ|FUTIDX|FUTSTK|OPTIDX|OPTSTK|FUTCOM");


delay= ParamToggle("Trade Intrabar?", "YES|Candle Completion", 1);
stag= ParamStr("Strategy Tag", "STG1");
dlong= ParamToggle("Disable Long?", "NO|YES");
dshort= ParamToggle("Disable Short?", "NO|YES");
bp= sp= NumToStr(Close[BarCount-1],1.2, False);
if(dlong){Buy=Sell=0;}
if(dshort){Short=Cover=0;}
RequestTimedRefresh( 1, onlyvisible = False ) ;
qty= "1";

if(delay)
{Buy=Ref(Buy,-1); Sell=Ref(Sell,-1); Short= Ref(Short,-1); Cover= Ref(Cover,-1);}

global algoji;
algoji = Name() + NumToStr( Interval() / 60, 1.0, False ) ;

procedure aStaticVarSet( SName, Svalue )


{
global algoji;

StaticVarSet( Sname + algoji, Svalue );


}
function aStaticVarGet( SName )
{
global algoji;
Var = StaticVarGet( Sname + algoji );

if ( IsNull( Var = StaticVarGet( Sname + algoji ) ) )


Var = 0;

return Var;
}

sym = Name();

//_TRACE("t"+t);

Checkdt=Nz(aStaticVarGet("lastdt"));
dt = LastValue( DateTime() );
Checkdtss=Nz(aStaticVarGet("lastdtss"));
dtss = LastValue( DateTime() );
Checkdtc=Nz(aStaticVarGet("lastdtc"));
dtc = LastValue( DateTime() );
Checkdts=Nz(aStaticVarGet("lastdts"));
dts = LastValue( DateTime() );
RTBuy = LastValue( Buy) AND Checkdt != dt;
RTShort = LastValue( Short) AND Checkdtss != dtss;
RTCover = LastValue( Cover) AND Checkdtc != dtc;
RTSell = LastValue( Sell) AND Checkdts != dts;

if ( RTCover )
{
aStaticVarSet("lastdtc",dtc );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",SX,"+sym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"SX",sym,"M","",bp,qty,instr,stag);
}

if ( RTSell )
{
aStaticVarSet("lastdts",dts );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+sym+",,," +sp
+","+qty+",,,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",sym,"M","",sp,qty,instr,stag);
}

if ( RTBuy )
{
aStaticVarSet("lastdt",dt );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LE,"+sym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",sym,"M","",bp,qty,instr,stag);
}

if ( RTShort )
{
aStaticVarSet("lastdtss",dtss );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
sp= NumToStr(Close[BarCount-1],1.2, False);
_TRACE( "#"+Nz(StaticVarGet("counter"))+",SE,"+sym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"SE",sym,"M","",bp,qty,instr,stag);
}

Button = ParamToggle( "Enable Button Trading", "YES|NO" );


expiry= ParamStr("Expiry","");
strike= ParamStr("Strike","");
type= ParamStr("Option Type", "");
sym = Name()+ "|"+expiry+ "|" +strike+ "|" +type;

function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}

function PopupWindowEx( popupID, bodytext, captiontext, timeout, left, top )


{
displayText = bodytext + captiontext;
if ( ( StaticVarGetText( "prevPopup" + popupID ) != displayText) OR
( StaticVarGet( "prevPopupTime" + popupID ) < GetSecondNum() ) )
{
StaticVarSetText( "prevPopup" + popupID, displayText);
StaticVarSet( "prevPopupTime" + popupID, GetSecondNum() + timeout );
PopupWindow( bodytext, Captiontext + popupID, timeout, Left, top );
}
}

x1= Status( "pxchartleft" )+10;


y1= Status( "pxcharttop" )+20;

if ( Button == 0 )
{
click = GetCursorMouseButtons() == 9;
Px = GetCursorXPosition( 1 );
Py = GetCursorYPosition( 1 );

x2 = x1 + 60;
y2 = y1 + 60;
GfxSelectSolidBrush( ColorRGB( 0, 102, 0 ) ); //buy
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxRoundRect( x1, y1, x2, y2 , 7, 7 ) ;
GfxTextOut( "LE", x1 + 20, y1 + 20 );
sx1 = x2;
sy1 = y1;
sx2 = sx1 + 60;
sy2 = sy1 + 60;
GfxSelectSolidBrush( ColorRGB( 255, 204, 204 ) );//sell
GfxRoundRect( sx1, sy1, sx2, sy2 , 7, 7 ) ;
GfxSetTextColor( ColorRGB( 153, 0, 0 ) );
GfxTextOut( "SE", sx1 + 20, sy1 + 20 );

ex1 = x1;
ey1 = y1+60;
ex2 = ex1 + 60;
ey2 = ey1 + 60;
GfxSelectSolidBrush( ColorRGB( 255, 204, 204 ) );//sell
GfxRoundRect( ex1, ey1, ex2, ey2 , 7, 7 ) ;
GfxSetTextColor( ColorRGB( 153, 0, 0 ) );
GfxTextOut( "LX", ex1 + 20, ey1 + 20 );

GfxSelectSolidBrush( ColorRGB( 0, 102, 0 ) );//sell


GfxRoundRect( ex2, ey1, ex2+60, ey2 , 7, 7 ) ;
GfxSetTextColor( colorWhite );
GfxTextOut( "SX", ex2 + 20, ey1 + 20 );

if ( px > x1 AND px<x2 AND py>y1 AND py < y2 AND Click )


{
_TRACE( "# ," + NumToStr(Nz(StaticVarGet("counter")),0,False) + ", BUY
triggered from button, " );
AlertIf( 1, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 1, 2,
1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
PopupWindowEx( "ID:1", "BUY", "Buy Triggered from Button "+Name(), 1, -1,
-1 );
AlgoJi_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",sym,"M","",sp,qty,instr,stag);
}
//https://algoji.com/
if ( px > sx1 AND px<sx2 AND py>sy1 AND py < sy2 AND Click )
{
_TRACE( "# ," + NumToStr( DateTime(), formatDateTime ) + ", SHORT triggered
from button, " );
AlertIf( 2, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2, 2,
1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
PopupWindowEx( "ID:3", "SHORT", "Short Triggered from Button "+Name(), 1, -1,
-1 );
AlgoJi_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"SE",sym,"M","",sp,qty,instr,stag);
}
//https://algoji.com/
if ( px > ex1 AND px<ex2 AND py>ey1 AND py<ey2 AND Click )
{
_TRACE( "# ," + NumToStr( DateTime(), formatDateTime ) + ", SELL triggered
from button, " );
AlertIf( 3, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2, 2,
1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
PopupWindowEx( "ID:3", "SELL", "Sell Triggered from Button "+Name(), 1, -1,
-1 );
AlgoJi_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",sym,"M","",sp,qty,instr,stag);
}
//https://algoji.com/
if ( px > ex2 AND px<(ex2+60) AND py>ey1 AND py < ey2 AND Click )
{
_TRACE( "# ," + NumToStr( DateTime(), formatDateTime ) + ", Cover triggered
from button, " );
AlertIf( 4, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2, 2,
1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
PopupWindowEx( "ID:3", "Cover", "Cover Triggered from Button "+Name(), 1,
-1, -1 );
AlgoJi_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"SX",sym,"M","",sp,qty,instr,stag);
}

_SECTION_BEGIN("Magnified Close Price");


FS=Param("Font Size",20,20,50,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlack ) );
Hor=Param("Horizontal Position",150,50,800,50);
Ver=Param("Vertical Position",10,10,500,20);
GfxTextOut(" "+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 15, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorblack) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+10, Ver+60 );
_SECTION_END();

_SECTION_BEGIN("Background text");
//C11=ParamColor("up panel",colorBlack );
C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
//C14=Param("left-right",2.1,1.0,5.0,0.1 );
C14=Param("left-right",3,5,5.0,0.1 );
C15=Param("up-down",8,1,30,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSelectFont("Tahoma", 12, 500, False, False, 0);
GfxSetTextColor(colorCustom12);
GfxSetTextAlign( 6 );
GfxSelectFont("Tahoma", 15, 600, False, False, 0);
GfxSetTextColor(colorBlack);
GfxSetTextAlign( 6 );
//GfxTextOut( "LTP "+WriteVal(C,1.2), Status("pxwidth")/C15,
Status("pxheight")/C15);
GfxSelectFont("Tahoma", 10, 400, False, False, 0);
/*GfxSetTextColor(colorBrightGreen);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorRed);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorYellow);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorGreen);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorGreen);
*/

pricechange=(C-Ref(C,-1))*100/Ref(C,-1);
changeponit=C-Ref(C,-1);
Vlp=Param("Volume lookback period",15,10,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;

x=Param("xposn",1,0,1000,1);
y=Param("yposn",1,0,1000,1);

//GfxGradientRect( 1, 1, 1400, 40, colorGrey50, colorDarkGrey);


GfxSetBkMode(0);
GfxSelectFont( "Georgia", 18, 800, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "The Scalper_DX ", x+600, y+5);
GfxSelectFont( "Georgia", 16, 800, False );
GfxSetTextColor( colorBlack );
//GfxTextOut( Name(), x+100, y+10 );
GfxSelectFont( "Georgia", 15, 100, False );
GfxSetTextColor( colorWhite );
GfxTextOut( Date(), x+1000, y+10 );
GfxSelectFont( "Georgia", 15, 500, False );
GfxSetTextColor( colorBlack );
//GfxTextOut( Interval(2), x+275, y+10 );
//------------------------------------------------------------ H, L, O,
C----------------------
/*GfxGradientRect( 1, 40, 1400, 65, colorGrey50, colorDarkGrey );
GfxSetBkMode(0);
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "High:"+WriteVal(H,1.2), x+100, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Low:"+WriteVal(L,1.2), x+200, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Open:"+WriteVal(O,1.2), x+300, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Close:"+WriteVal(C,1.2), x+400, y+40 );
GfxSelectFont( "Script MT Bold", 12, 100, False );
GfxSetTextColor( colorWhite );
//GfxTextOut( "ALL Rights Reserved To great Ghumketu ", x+990, y+39 );
//-----------------------------------------------------------
Valume-------------------------------
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Volume="+WriteVal(V,1.2), x+500, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vp2,"Very High",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vp1," High",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vrg,"Above Average",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf(V<Vrg AND V>Vn1,"Less than Average",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf(V<Vn1,"Low",""), x+600, y+40 );
*/

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods",20, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color,
Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color,
Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.8 ),
styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

You might also like