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

Algoji Intraday Afl

The document defines parameters for an intraday trading strategy including trade entry and exit times, instrument type, quantity, profit/loss targets, and more. It also includes logic to generate buy, sell, short, and cover signals during the specified intraday period and close out positions at the end of the day or when targets/stops are hit. A message board is configured to display strategy information.

Uploaded by

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

Algoji Intraday Afl

The document defines parameters for an intraday trading strategy including trade entry and exit times, instrument type, quantity, profit/loss targets, and more. It also includes logic to generate buy, sell, short, and cover signals during the specified intraday period and close out positions at the end of the day or when targets/stops are hit. A message board is configured to display strategy information.

Uploaded by

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

_SECTION_BEGIN( "Algoji.com intraday.

afl" );
intra = ParamToggle( "Activate Intraday Mode", "NO|YES" );
per10 = Param( "Trade Entry From(HHMM)", 920, 900, 2300, 1 );
per11 = Param( "Trade Entry Upto(HHMM)", 1445, 900, 2300, 1 );
per12 = Param( "Trade Exit(HHMM)", 1515, 900, 2300, 100 );
Col = ParamColor( "Color of Modified Signals", colorYellow );
instr= ParamList("Instrument Name","EQ|FUTIDX|FUTSTK|OPTIDX|OPTSTK|FUTCOM");
delay= ParamToggle("Trade Intrabar?", "YES|Candle Completion");
stag= ParamStr("Strategy Tag", "STG1");
dlong= ParamToggle("Disable Long?", "NO|YES");
dshort= ParamToggle("Disable Short?", "NO|YES");

if(dlong){Buy=Sell=0;}
if(dshort){Short=Cover=0;}

if(delay)
{Buy=Ref(Buy,-1); Sell=Ref(Sell,-1); Short= Ref(Short,-1); Cover= Ref(Cover,-
1);}
exposure= Param("Exposure", 0, 0, 1000000) ;
qt= Param("Trade Quantity", 0, 0, 1000000) ;
if(exposure>0)
qt= round(exposure/ValueWhen(Day()!=Ref(Day(),-1), C));

dp= Param("Day Profit", 0, 0, 100000, 1);


dl= Param("Day Loss", 0, -100000, 0, 1);
sl= abs(dl/qt);
tgt= dp/qt;
intraex = intra AND (TimeNum() > per12 * 100);
intraen = !intra OR ( TimeNum() <= per11 * 100 AND TimeNum() >= per10 * 100
);

Buy1 = Buy;
Sell1 = Sell;
Short1 = Short;
Cover1 = Cover;
bflag = sflag = 0;
slarr = tgtarr = Null;

for ( i = 10; i < BarCount; i++ )


{
if ( Buy1[i] AND intraen[i] AND bflag == 0 )
{
Buy[i] = 1;
bflag = 1;
BuyPrice[i]= C[i];
if(dl)
slarr[i] = BuyPrice[i]- sl;
if(dp)
tgtarr[i] = BuyPrice[i] + tgt;
}
else
Buy[i] = 0;

if ( bflag AND Buy[i] == 0 )


{
slarr[i] = slarr[i-1];
tgtarr[i] = tgtarr[i-1];
}

if ( ( Sell1[i] OR intraex[i] OR( L[i] < slarr[i-1] AND sl>0 ) OR ( H[i]


> tgtarr[i] AND tgt > 0 ) ) AND bflag AND !Buy[i])
{
Sell[i] = 1;
SellPrice[i]= C[i];
bflag = 0;
}
else
Sell[i] = 0;

if ( Short1[i] AND intraen[i] AND sflag == 0 )


{
Short[i] = 1;
sflag = 1;
ShortPrice[i]= C[i];
if ( dp )
slarr[i] = C[i] + sl;
if ( dl )
tgtarr[i] = C[i] - tgt;
}
else
Short[i] = 0;

if ( sflag AND Short[i] == 0 )


{
slarr[i] = slarr[i-1];
tgtarr[i] = tgtarr[i-1];
}

if ( ( Cover1[i] OR intraex[i]OR( H[i] > slarr[i-1] AND sl>0 ) OR ( L[i]


< tgtarr[i] AND tgt > 0 ) ) AND sflag AND !Short[i] )
{
Cover[i] = 1;
CoverPrice[i]= C[i];
sflag = 0;
}
else
Cover[i] = 0;
}

Plot( slarr, "SL", Col, styleThick );


Plot( tgtarr, "TGT", Col, styleThick );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), Col, 0, L, Offset = -45 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), Col, 0, H, Offset = -45
);
PlotShapes( IIf( Cover, shapeStar, shapeNone ), Col, 0, L, Offset = -55 );
PlotShapes( IIf( Sell, shapeStar, shapeNone ), Col, 0, H, Offset = -55 );

sig = IIf( BarsSince( Buy ) < BarsSince( Short ), 1, 0 );


messageboard = ParamToggle( "Message Board", "Show|Hide", 1 );

if ( messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

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 - 160, x2, y , 7, 7 ) ;
GfxTextOut( ""+WriteIf(intra, "Intraday Mode Activated", "Intraday Mode
Not Activated" ), 13, y-160 );
GfxTextOut( ( "Quantity "+qt ), 13, y-140 );
GfxTextOut( ( "Last" + " Signal came " + ( BarsSince( Buy OR Short ) ) *
Interval() / 60 + " mins ago" ), 13, y - 120 ) ; // The text format location
GfxTextOut( ( "" + WriteIf( sig == 1, "BUY @ " + ValueWhen(Buy,BuyPrice)
, "SHORT @ " + ValueWhen(Short,ShortPrice) ) ), 13, y - 100 );
GfxTextOut( "Stop Loss : " + WriteIf(sl==0, "Not Activated", ""+slarr),
13, y - 80 );
GfxTextOut( "Target : " + WriteIf(tgt==0, "Not Activated", ""+tgtarr),
13, y - 60 );
GfxTextOut( ( "Current P/L : " + WriteVal( IIf( sig == 1, (C-
ValueWhen(Buy,BuyPrice))*qt, (ValueWhen(Short,ShortPrice)-C)*qt ), 2.2 ) ),
13, y-40 );
// GfxTextOut( ( "jhjh " ), 13, y-20 );
}

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();
qty= NumToStr(qt, 1.0, False);
//_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 AND Nz(aStaticVarGet("IsShort")) )


{
aStaticVarSet("lastdtc",dtc );
aStaticVarSet("IsShort", 0 );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
bp= NumToStr(Close[BarCount-1],1.2, False);
_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 AND Nz(aStaticVarGet("IsLong")) )


{
aStaticVarSet("IsLong",0 );
aStaticVarSet("lastdts",dts );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
sp= NumToStr(Close[BarCount-1],1.2, False);
_TRACE( "#"+Nz(StaticVarGet("counter"))+",LX,"+sym+",,," +sp
+","+qty+",,,");
Algoji_Signal(NumToStr(Nz(StaticVarGet("counter")),0,False),
"LX",sym,"M","",bp,qty,instr,stag);
}

if ( RTBuy )
{
aStaticVarSet("IsLong",1 );
aStaticVarSet("lastdt",dt );
StaticVarSet("counter", Nz(StaticVarGet("counter"))+1 );
bp= NumToStr(Close[BarCount-1],1.2, False);
_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("IsShort",1 );
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);
}

_SECTION_END();

You might also like