_SECTION_BEGIN("Last Five Trades Dashboard");
//set initial values
SetOption( "InitialEquity", 100000);
SetOption("FuturesMode" ,false);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",0);
SetOption("AccountMargin",100);
SetOption("RefreshWhenCompleted",True);
SetTradeDelays(0,0,0,0);
SetPositionSize(1,spsShares);
//set trading rules
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );
Short = Sell;
Cover = Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
//plot buy or sell arrows
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),colorWhite, 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),colorWhite, 0,H, Offset=-45);
// Calculate Equity Curve
eq = Equity( 1, 0 );
//////////////////////////////////////////////////
// Calculate the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
tradesback = 5;
Signum = Cum( Buy ) + Cum( Short );
Signumstart1 = LastValue( SigNum ) - ( tradesback - 1 );
Signumstart2 = LastValue( SigNum ) - ( tradesback - 2 );
Signumstart3 = LastValue( SigNum ) - ( tradesback - 3 );
Signumstart4 = LastValue( SigNum ) - ( tradesback - 4 );
Signumstart5 = LastValue( SigNum ) - ( tradesback - 5 );
bi = BarIndex();
bistart = ValueWhen( signum == signumstart1, bi );
bicond = bi >= bistart AND bi <= LastValue( bi );
SellPL = IIf( Sell AND bicond, C-buyprice, 0 );
CovPL = IIf( Cover AND bicond, ShortPrice - C,0 );
cumPL = SellPL + CovPL;
//Plot (SellPL,"Sell",colorGreen,styleHistogram,maskhistogram);
///Plot (CovPL,"Cover", colorRed,styleHistogram,maskhistogram);
lsince = lowestSince(Sell OR Cover, cumPL, 0);
hsince = highestSince(Sell OR cover, CumPL, 0);
vs= IIf(lsince==0,hsince,lsince);
PL1 = ValueWhen( signum == signumstart1 , vs,1 );
PL2 = ValueWhen( signum == signumstart2 , vs,1 );
PL3 = ValueWhen( signum == signumstart3 , vs,1 );
PL4 = ValueWhen( signum == signumstart4 , vs,1 );
PL5 = ValueWhen( signum == signumstart5, vs ,1 );
//////////////////////////////////////////////////
// Plot the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
Title = EncodeColor(colorWhite)+ "Backtest Results from www.marketcalls.in" + "
- " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) +
EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+"
"+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ EncodeColor(colorYellow)+ "\n\n\nLast 5
Trade Results\n" +
"\nTrade1= " + PL1
+"\n"+ "Trade2= " + PL2
+"\n"+ "Trade3= " + PL3
+"\n"+ "Trade4= " + PL4
+"\n"+ "Trade5= " + PL5;
_SECTION_BEGIN("Last Five Trades Dashboard");
//set initial values
SetOption( "InitialEquity", 100000);
SetOption("FuturesMode" ,false);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",0);
SetOption("AccountMargin",100);
SetOption("RefreshWhenCompleted",True);
SetTradeDelays(0,0,0,0);
SetPositionSize(1,spsShares);
//set trading rules
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );
Short = Sell;
Cover = Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
//plot buy or sell arrows
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),colorWhite, 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),colorWhite, 0,H, Offset=-45);
// Calculate Equity Curve
eq = Equity( 1, 0 );
//////////////////////////////////////////////////
// Calculate the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
tradesback = 5;
Signum = Cum( Buy ) + Cum( Short );
Signumstart1 = LastValue( SigNum ) - ( tradesback - 1 );
Signumstart2 = LastValue( SigNum ) - ( tradesback - 2 );
Signumstart3 = LastValue( SigNum ) - ( tradesback - 3 );
Signumstart4 = LastValue( SigNum ) - ( tradesback - 4 );
Signumstart5 = LastValue( SigNum ) - ( tradesback - 5 );
bi = BarIndex();
bistart = ValueWhen( signum == signumstart1, bi );
bicond = bi >= bistart AND bi <= LastValue( bi );
SellPL = IIf( Sell AND bicond, C-buyprice, 0 );
CovPL = IIf( Cover AND bicond, ShortPrice - C,0 );
cumPL = SellPL + CovPL;
//Plot (SellPL,"Sell",colorGreen,styleHistogram,maskhistogram);
///Plot (CovPL,"Cover", colorRed,styleHistogram,maskhistogram);
lsince = lowestSince(Sell OR Cover, cumPL, 0);
hsince = highestSince(Sell OR cover, CumPL, 0);
vs= IIf(lsince==0,hsince,lsince);
PL1 = ValueWhen( signum == signumstart1 , vs,1 );
PL2 = ValueWhen( signum == signumstart2 , vs,1 );
PL3 = ValueWhen( signum == signumstart3 , vs,1 );
PL4 = ValueWhen( signum == signumstart4 , vs,1 );
PL5 = ValueWhen( signum == signumstart5, vs ,1 );
//////////////////////////////////////////////////
// Plot the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
Title = EncodeColor(colorWhite)+ "Backtest Results from www.marketcalls.in" + "
- " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) +
EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+"
"+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ EncodeColor(colorYellow)+ "\n\n\nLast 5
Trade Results\n" +
"\nTrade1= " + PL1
+"\n"+ "Trade2= " + PL2
+"\n"+ "Trade3= " + PL3
+"\n"+ "Trade4= " + PL4
+"\n"+ "Trade5= " + PL5;
function Cbl(bars)
{
cblArr = Null;
if (bars > 0)
{
for (i = 1; i < BarCount; i++)
{
steps = bars - 1;
mostLow = Low[i];
for (j = i-1; j >= 0 && steps > 0; j--)
{
if (Low[j] < mostLow)
{
mostLow = Low[j];
steps--;
}
}
cblArr[i] = mostLow;
}
}
return cblArr;
}
function TrailingStop(data)
{
stop[0] = data[0];
for (i = 1; i < BarCount; i++)
{
if (Close[i] >= stop[i-1])
stop[i] = Max(data[i], stop[i-1]);
else
stop[i] = data[i];
}
return stop;
}
cblStop = TrailingStop (Cbl(3));
function Cbl(bars)
{
cblArr = Null;
if (bars > 0)
{
for (i = 1; i < BarCount; i++)
{
steps = bars - 1;
mostLow = Low[i];
for (j = i-1; j >= 0 && steps > 0; j--)
{
if (Low[j] < mostLow)
{
mostLow = Low[j];
steps--;
}
}
cblArr[i] = mostLow;
}
}
return cblArr;
}
function TrailingStop(data)
{
stop[0] = data[0];
for (i = 1; i < BarCount; i++)
{
if (Close[i] >= stop[i-1])
stop[i] = Max(data[i], stop[i-1]);
else
stop[i] = data[i];
}
return stop;
}
cblStop = TrailingStop (Cbl(3));
_SECTION_BEGIN("trailstops");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorGold, styleThick | styleLine );
Plot( C, "Price", color, styleBar );
/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );