Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

///section begines for options

bsym= ParamStr("Base Symbol", "BANKNIFTY");


expiry= ParamStr("Expiry","25Apr2019");
pstrike= ParamStr("Put Strike","30000");
cstrike= ParamStr("Call Strike","30000");

instr= ParamList("Instrument Name","OPTIDX|OPTSTK");


delay= ParamToggle("Trade Intrabar?", "YES|Candle Completion");
qt= Param("Quantity", 20, 1, 10000);
stag= ParamStr("Strategy Tag", "STG1");

csym= bsym + "|" + expiry + "|" + cstrike + "|" + "CE";


psym= bsym + "|" + expiry + "|" + pstrike + "|" + "PE";

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;
}

Checkdt=Nz(aStaticVarGet("lastdt"));
dt = LastValue( DateTime() );
Checkdts=Nz(aStaticVarGet("lastdts"));
dts = LastValue( DateTime() );
RTBuy = LastValue( Buy) AND Checkdt != dt;
RTShort = LastValue( Short) AND Checkdts != dts;
bp= sp= "0";
qty= NumToStr(qt, 1.0, False);

//https://algoji.com/
if ( RTBuy )
{
aStaticVarSet("lastdt",dt );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LE,"+csym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",csym,"M","",bp,qty,instr,stag);
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+psym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",psym,"M","",bp,qty,instr,stag);
}
//https://algoji.com/
if ( RTShort )
{
aStaticVarSet("lastdts",dts );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LE,"+psym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",psym,"M","",sp,qty,instr,stag);
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+csym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",csym,"M","",sp,qty,instr,stag);
}

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

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( "Buy", x1 + 14, 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( "Sell", sx1 + 14, sy1 + 20 );

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


{
AlertIf( 1, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 1, 2,
1 );
PopupWindowEx( "ID:1", "BUY", "Buy Triggered from Button "+Name(), 1, -1,
-1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LE,"+csym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",csym,"M","",bp,qty,instr,stag);
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+psym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",psym,"M","",bp,qty,instr,stag);
}
//https://algoji.com/
if ( px > sx1 AND px<sx2 AND py>sy1 AND py < sy2 AND Click )
{
AlertIf( 2, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2, 2,
1 );
PopupWindowEx( "ID:3", "SHORT", "Short Triggered from Button "+Name(), 1, -1,
-1 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LE,"+psym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LE",psym,"M","",sp,qty,instr,stag);
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+csym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",csym,"M","",sp,qty,instr,stag);
}

You might also like