////////////////////////////////////////////////chart & back ground color//////////////////////////////////////////////////
SetChartBkGradientFill(colorBlack,colorBlack,colorBlack);
//Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( Close, "C", colorWhite, styleCandle);
separator = Day() != Ref( Day(), -1 );
Plot( separator, "", colorDarkBlue, styleHistogram | styleOwnScale | styleNoLabel | styleNoRescale, 0, 1, 0, -2, 5 );
GraphXSpace=85;
//////////////////////////////////////////////////////////////////
Plot(EMA(Close,5),"",colorGreen,styleThick);
Plot(EMA(Close,13),"",colorRed,styleThick);
Buyst = EMA(Close,5) > EMA(Close,13);
Shortst = EMA(Close,5) < EMA(Close,13);
Session= (TimeNum() > 093000) AND (TimeNum() < 151500);
Buy = Buyst AND Session;
Short = Shortst AND Session;
Sell =Shortst OR (TimeNum() > 151500);
Cover = Buyst OR(TimeNum() > 151500);
BUY=ExRem(BUY,SELL);
SELL=ExRem(SELL,BUY);
COVER=ExRem(COVER,SHORT);
SHORT=ExRem(SHORT,COVER);
BuyPrice=ValueWhen(Buy,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
SellPrice=ValueWhen(Sell,C);
////////////////////////////////////////////////////////////////////////////////////////////////
Signalshape=Buy*shapeUpArrow + Short*shapeDownArrow;
PlotShapes( Signalshape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
pos = 2*ATR(15);
for( i = 0; i < BarCount; i++ ) {
if( Buy[i] ) PlotText( "" + Close[i], i, Low[i] - pos[i], colorGreen );
if( Short[i] ) PlotText( "" + Close[i], i, Low[i] + pos[i], colorRed );
}
Signalshape=Cover*shapeHollowUpArrow + Sell*shapeHollowDownArrow;
PlotShapes( Signalshape, IIf( Cover, colorGreen, colorRed ),0, IIf( Cover, Low, High ) );
pos = 2*ATR(15);
for( i = 0; i < BarCount; i++ ) {
if( Cover[i] ) PlotText( "" + Close[i], i, Low[i] - pos[i], colorGreen );
if( Sell[i] ) PlotText( "" + Close[i], i, Low[i] + pos[i], colorRed );
}
////////////////////////////////////////////////////////////////////////////////////////////////
isStartOfDay = Day() != Ref(Day(),-1) ;
longProfit = IIf(Sell, SellPrice - ValueWhen(Buy, BuyPrice), 0);
shortProfit = IIf(Cover, ValueWhen(Short, ShortPrice) - CoverPrice, 0);
MAXPROFITTRADE = HighestSince (isStartOfDay, longProfit + shortProfit);
MAXLOSSTRADE = LowestSince (isStartOfDay, longProfit + shortProfit);
TOTALPL = SumSince(isStartOfDay, longProfit + shortProfit) ;
//NEEDS CORECTION //
TOTALLOSS = Sum(isStartOfDay, (Sell AND longProfit < 3) + (Cover AND shortProfit < 3) ) ;
TOTALPROFIT = Sum(isStartOfDay, (longProfit > 3) + (shortProfit > 3)) ;
MINPROFITTRADE = LowestSince(isStartOfDay, (Sell AND longProfit > 3) OR (Cover AND shortProfit > 3));
MINLOSSTRADE = LowestSince(isStartOfDay, (Sell AND longProfit < 3) OR (Cover AND shortProfit < 3)) ;
/////////////////////
GfxSelectSolidBrush( colorBlack );
GfxSetBkMode( 1 );
GfxSelectFont( "Tahoma", 7, 100 );
y = Status( "pxchartheight" ) ;
GfxSelectPen ( colorLightBlue, 1); // border color
GfxRoundRect ( 5, y- 60, 500, y-36 , 7, 7 ) ;
GfxSetTextColor ( colorRed );
GfxTextOut("MAX LOSS = " + Prec( MAXLOSSTRADE , 2) , 13,y-60);
GfxSetTextColor ( colorBrightGreen );
GfxTextOut(" MAX PROFIT = " + Prec( MAXPROFITTRADE , 2) , 120,y-60);
GfxSetTextColor ( colorRed );
GfxTextOut(" MIN LOSS = " + Prec( MINLOSSTRADE , 2) , 220,y-60);
GfxSetTextColor ( colorBrightGreen );
GfxTextOut(" MIN PROFIT = " + Prec( MINPROFITTRADE , 2) , 320,y-60);
GfxSetTextColor ( colorRed );
GfxTextOut(" TOTAL LOSS = " + Prec( TOTALLOSS , 2) , 13,y-47);
GfxSetTextColor ( colorBrightGreen );
GfxTextOut(" TOTAL PROFIT = " + Prec( TOTALPROFIT , 2) , 113,y-47);
GfxSetTextColor ( colorWhite );
GfxTextOut(" TOTAL P/L = " + Prec( TOTALPL , 2) , 213,y-47);
////////////////////////////////////
if you plot the above chart , you can see they are not giving proper output for the below part of the code.
//NEEDS CORECTION //
TOTALLOSS = Sum(isStartOfDay, (Sell AND longProfit < 3) + (Cover AND shortProfit < 3) ) ;
TOTALPROFIT = Sum(isStartOfDay, (longProfit > 3) + (shortProfit > 3)) ;
MINPROFITTRADE = LowestSince(isStartOfDay, (Sell AND longProfit > 3) OR (Cover AND shortProfit > 3));
MINLOSSTRADE = LowestSince(isStartOfDay, (Sell AND longProfit < 3) OR (Cover AND shortProfit < 3)) ;
/////////////////////
Though I successfully coded to catch the other out puts (like: TOTALPL, MAXPROFIT & MAXLOSS)---I am struggling for last 3 months to get these 4 lines corrected to get the desired output.
I need TOTALLOSS , TOTALPROFIT , MINPROFIT & MINLOSS to make the back test report more clear-indepth-robust and more information on loss/profit trades to enhance the strategy in future.
To clarify more about the problematic codes:
-
TOTALLOSS means the aggregate of all the loss making trades in a day and the same way for TOTALPROFIT .
-
The number 3 means: a trade giving less than +3 points as profit is a loss only (considering brokerage and other stuffs)
-
Similarly, MINPROFITTRADE means the trade making profit just above +3 points and the same way for MINLOSSTRADE .
Please help.