EMARSICCI-system
_SECTION_BEGIN("EMARSICCI");
trailstop=0; strailstop=0;
trailARRAY=Null; strailARRAY=Null;
refL1=0; refL2=0; refH1=0; refH2=0;
perc = Param("% Stop",0.295,0.0001,100,0.0001);
A1 = Optimize("A1",3,1,10,1);
A2 = Optimize("A2",13,5,30,1);
z1 = Ref(L,-1)<Ref(L,0) AND Ref(L,-1)<Ref(L,-2);
z2 = Ref(L,-1);
z3 = Ref(H,-1)>Ref(H,0) AND Ref(H,-1)>Ref(H,-2);
z4 = Ref(H,-1);
refL1 = LLV(L,5) * ((100-perc)/100); //static SL.
refL2 = IIf(z1, z2, 0); //trailing SL
refH1 = HHV(H,5)* ((100+perc)/100);//static SL.
refH2 = IIf(z3, z4, 0); //trailing SL
crossEMA1 = Cross(C,EMA(C,A2));
crossRSI1 = Cross(RSI(13),50);
cross2EMA1 = Cross(CCI(13),0);
crossEMA2 = Cross(EMA(C,A2),C);
crossRSI2 = Cross(50,RSI(13));
cross2EMA2 = Cross(0,CCI(13));
Buy = crossEMA1 AND crossRSI1 AND cross2EMA1;
Sell = 0;
Short = crossEMA2 AND crossRSI2 AND cross2EMA2;
Cover = 0;
for(i=0; i<BarCount; i++)
{
/*fh = fopen( "D:/myfile.txt", "a");
if( fh )
{
fputs("i"+i+"__t"+trailstop+"___"+Buy+"__P"+C+"\n", fh );
fclose( fh );
}*/
//_TRACE("i"+i+"__t"+trailstop+"___"+Buy+"__P"+C);
if( trailstop == 0 AND Buy[ i ] )
{
BuyPrice = O;
trailstop= refL1;
//BuyToFuse(BuyPrice,0);
}
else Buy[ i ] = 0; // remove excess buy signals
if( strailstop == 0 AND Short[ i ] )
{
ShortPrice = O;
strailstop= refH1;
/*if(i == (BarCount-2))
{
ShortToFuse(ShortPrice,0);
}*/
}
else Short[ i ] = 0; // remove excess short signals
if( trailstop > 0 )
{
trailstop= Max( refL2[ i ] * ((100-perc)/100), trailstop);
trailARRAY[ i ] = trailstop;
}
if( strailstop > 0 )
{
if(refH2 == 0) {y = strailstop;} else y = refH2;
strailstop= Min( y * ((100+perc)/100), strailstop);
strailARRAY[ i ] = strailstop;
}
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop=0;
/*if(i==(BarCount -2))
{
SellToFuse(SellPrice[ i ],0);
}*/
}
if( strailstop > 0 AND High[ i ] > strailstop )
{
Cover[ i ] = 1;
CoverPrice[ i ] = strailstop;
strailstop=0;
/*if(i==(BarCount -2))
{
CoverToFuse(CoverPrice[ i ],0);
}*/
}
if( trailstop > 0 AND Short)
{
Sell[ i ] = 1;
SellPrice[ i ] = O;
trailstop=0;
/*if(i==(BarCount -2))
{
SellToFuse(SellPrice[ i ],0);
}*/
}
if( strailstop > 0 AND Buy )
{
Cover[ i ] = 1;
CoverPrice[ i ] = O;
strailstop=0;
/*if(i==(BarCount -2))
{
CoverToFuse(CoverPrice[ i ],0);
}*/
}
}
/*fh = fopen( "D:/myfile.txt", "a");
if( fh )
{
fputs("EndFor\n", fh );
fclose( fh );
} */
Plot( Close,"Price",colorBlack,styleCandle);
Plot( trailARRAY,"Buy Stoploss", colorRed, shapeStar );
Plot( strailARRAY,"Short Stoploss", colorBlue, shapeStar );
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorBlack, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-30);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorBlack, 0,L, Offset=-25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorBlue, 0,H, Offset=-25);
_SECTION_END();
RequestTimedRefresh( 1,onlyvisible=False );
_SECTION_BEGIN("EMARSICCI-1");
a5=(Sell);
a4=(Cover);
a1=(Buy);
a2=(Short);
a3= Ref(C,-1);
a7=Ref(L,-1);
a6= 0;
tb= Nz(trailArray, -1);
ts= Nz(strailArray, -1);
_SECTION_END();
ClientID = ParamStr("ClientId","000000");
Symbol= ParamStr("Symbol","NIFTY13APRFUT");
Price=NumToStr(C,8.3,True);
Quantity=Param("Quantity",1,1,100,1);
OE = ParamList("Order Execution","Immediate,On Candle Completion",1);
AT = ParamToggle("AutoTrade","No,Yes");
if(OE=="On Candle Completion")
{
Buy=Ref(Buy,-1);
Short=Ref(Short,-1);
Sell=Ref(Sell,-1);
Cover=Ref(Cover,-1);
}
AplliedQuantity=IIf(LastValue(Buy) AND LastValue(Cover) OR LastValue(Short) AND LastValue(Sell),Quantity*2,Quantity);
RefNumber = Nz(StaticVarGet("RefNumber"));
Checkdt=Nz(StaticVarGet("lastdt"));
dt = LastValue( DateTime() );
Cond=LastValue(Buy) OR LastValue(Short) OR LastValue(Sell) OR LastValue(Cover);
if(AT)
{
plus = CreateStaticObject("Nest.PlusApi");
if(plus)
{
plus.SetObjectName(ClientID);
if(Cond AND Checkdt != dt )
{
if(LastValue(Buy) OR LastValue(Cover)){plus.PlaceOrder("BUY",RefNumber,"NFO",Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,"NRML",ClientID);}
if(LastValue(Short) OR LastValue(Sell)){plus.PlaceOrder("SELL",RefNumber,"NFO",Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,"NRML",ClientID);}
StaticVarSet("RefNumber",RefNumber+1);
StaticVarSet("lastdt",dt );
}
}
}