0% found this document useful (0 votes)
59 views4 pages

Options-Advanced Afl

The document defines parameters and functions for an options trading strategy. It sets parameters like the base symbol, expiry date, and strike distance. It defines functions to get/set static variables to track signals. It checks for real-time buy/sell/short/cover signals and generates corresponding orders/alerts. It also includes logic for a button trading component to manually trigger orders.

Uploaded by

shailesh
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)
59 views4 pages

Options-Advanced Afl

The document defines parameters and functions for an options trading strategy. It sets parameters like the base symbol, expiry date, and strike distance. It defines functions to get/set static variables to track signals. It checks for real-time buy/sell/short/cover signals and generates corresponding orders/alerts. It also includes logic for a button trading component to manually trigger orders.

Uploaded by

shailesh
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/ 4

///section begins for options; apply strategy code above this section

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


expiry= ParamStr("Expiry(dd-mm-yy)","26-09-2019");
strikedist= Param("Strike Dist",0, -1000, 1000);

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


qt= Param("Quantity", 20, 1, 10000);
stag= ParamStr("Strategy Tag", "STG1");

Buy=Ref(Buy,-1); Sell=Ref(Sell,-1); Short= Ref(Short,-1); Cover= Ref(Cover,-1);

if(LastValue(BarsSince(Buy)<BarsSince(Short)))
oprice= ValueWhen(Buy, O);
else
oprice= ValueWhen(Short, O);

cstrike= round(oprice/100)*100 + strikedist;


pstrike= round(oprice/100)*100 - strikedist;

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


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

Title = Title + "\nTrading in "+ csym + "," + psym;

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() );
Checkdtc=Nz(aStaticVarGet("lastdtc"));
dtc = LastValue( DateTime() );
Checkdtss=Nz(aStaticVarGet("lastdtss"));
dtss = LastValue( DateTime() );

RTBuy = LastValue( Buy) AND Checkdt != dt;


RTShort = LastValue( Short) AND Checkdtss != dtss;
RTSell = LastValue( Sell) AND Checkdts != dts;
RTCover = LastValue( Cover) AND Checkdtc != dtc;
bp= sp= "0";
qty= NumToStr(qt, 1.0, False);

if ( RTSell )
{
aStaticVarSet("lastdts",dts );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+csym+",,," +bp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",csym,"M","",bp,qty,instr,stag);
}
//https://algoji.com/
if ( RTCover )
{
aStaticVarSet("lastdtc",dtc );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+psym+",,," +sp
+","+qty+","+instr+",,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",psym,"M","",sp,qty,instr,stag);
}
//https://algoji.com/
if ( RTBuy )
{
aStaticVarSet("lastdt",dt );
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("lastdtss",dtss );
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