Please help me to get these 4 lines of code amended to get the desired results.

////////////////////////////////////////////////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:

  1. TOTALLOSS means the aggregate of all the loss making trades in a day and the same way for TOTALPROFIT .

  2. The number 3 means: a trade giving less than +3 points as profit is a loss only (considering brokerage and other stuffs)

  3. Similarly, MINPROFITTRADE means the trade making profit just above +3 points and the same way for MINLOSSTRADE .

Please help.

1 Like

have a look, Santy

////////////////////////////////////////////////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 = 5;
//////////////////////////////////////////////////////////////////
Plot( EMA( Close, 5 ), "", colorGreen, styleThick );
Plot( EMA( Close, 13 ), "", colorRed, styleThick );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

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 ) );
Signalshape = Cover * shapeHollowUpArrow + Sell * shapeHollowDownArrow;
PlotShapes( Signalshape, IIf( Cover, colorGreen, colorRed ), 0, IIf( Cover, Low, High ) );

////////////////////////////////////////////////////////////////////////////////////////////////
isStartOfDay = Day() != Ref( Day(), -1 ) ;

longResult = IIf( Sell, SellPrice - ValueWhen( Buy, BuyPrice ), 0 );
shortResult = IIf( Cover, ValueWhen( Short, ShortPrice ) - CoverPrice, 0 );

MAXPROFITTRADE = HighestSince( isStartOfDay, longResult + shortResult );
MAXLOSSTRADE = LowestSince( isStartOfDay, longResult + shortResult );

TOTALPL = SumSince( isStartOfDay, longResult + shortResult ) ;

//NEEDS CORECTION //
threshold = 0;
SellatLoss = IIf( Sell && longResult < threshold, longResult, 0 );
CoveratLoss  = IIf( Cover && shortResult < threshold, shortResult, 0 );
SellatProfit = IIf( Sell && longResult > threshold, longResult, 0 );
CoveratProfit  = IIf( Cover && shortResult > threshold, shortResult, 0 );

TOTALLOSS =  SumSince( isStartOfDay, SellatLoss + CoveratLoss ) ;
TOTALPROFIT =  SumSince( isStartOfDay, SellatProfit + CoveratProfit ) ;

spp = IIf( SellatProfit, SellatProfit, IIf( CoveratProfit, CoveratProfit, 1e10 ) );
sll = IIf( SellatLoss, SellatLoss, IIf( CoveratLoss, CoveratLoss, -1e10 ) );
MINPROFITTRADE = LowestSince( isStartOfDay, spp );
MINLOSSTRADE = HighestSince( isStartOfDay, sll ) ;

/////////////////////
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 );
////////////////////////////////////


sz = 8;
bkcol = ColorRGB( 40, 40, 40 );

for( i = fvb; i <= lvb; i++ )
{
    if( Buy[i] && Cover[i] )
    {
        str = "Buy: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
        str = "Cover: " + C[i] + " (" + shortResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -50 );
    }

    if( !Buy[i] && Cover[i] )
    {
        str = "Cover: " + C[i] + " (" + shortResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
    }

    if( Buy[i] && !Cover[i] )
    {
        str = "Buy: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
    }

    if( Short[i] && Sell[i] )
    {
        str = "Short: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
        str = "Sell: " + C[i] + " (" + longResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 40 );
    }

    if( !Short[i] && Sell[i] )
    {
        str = "Sell: " + C[i] + " (" + longResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
    }

    if( Short[i] && !Sell[i] )
    {
        str = "Short: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
    }
}
1 Like

As I said:

2.The number 3 means: a trade giving less than +3 points as profit is a loss only (considering brokerage and other stuffs)

So, can I amend the value for threshold = 3 instead of 0 in your code?

I am in office now. once I go home I will test the whole code if it gives desired output. I am sure it will give as it is from a legend like you !!!

Thanks a lot for solving my problem.

yes, I put in a variable named "threshold" because I tested it on gold futures. But you can use threshold = 3;

in order to fine-tune the statergy (5 & 13 EMA crossover) can we use optimize or paramoptimize function (at some places I have seen paramoptimize also , of course they define a small function before using it).

I tried to understand from the optimization document on the site, but being a non tech guy ----I am a little non-confident like yet. what I understand from my readings is that if we give in any particular value to the optimize function it will give the best result from 0 to the given value, in stead of that particular given value.
if I am not correct in my understanding of the optimization concept , then is there any way we can implement the something like my above thought in the code given by you above.

in order to fine-tune the statergy (5 & 13 EMA crossover) can we use optimize or paramoptimize function (at some places I have seen paramoptimize also , of course they define a small function before using it).

I tried to understand from the optimization document on the site, but being a non tech guy ----I am a little non-confident like yet. what I understand from my readings is that if we give in any particular value to the optimize function it will give the best result from 0 to the given value, in stead of that particular given value.
if I am not correct in my understanding of the optimization concept , then is there any way we can implement the something like my above thought in the code given by you above.

maybe best try for yourself first. There are many examples. I am not really interested in this kind of system. When there is a good move you make money but on the chop you loose too much. So in my opinion optimization will not help.

ok, will try and get back ---in case if I stuck somewhere.

As discussed , i changed threshold = 3.

in this case the below line does not get desired result:
MINLOSSTRADE = HighestSince( isStartOfDay, sll ) ;

it gives output result as 0 only.

please advise further.

I do not have this problem. Maybe you noticed it does depend on where you place the cursor in the chart. So you need to place the cursor or click on the chart close to the end of the day.

I adjusted the code a little bit:

threshold = 0;
SellAtLoss = IIf( Sell && longResult < threshold, longResult, 0 );
CoverAtLoss = IIf( Cover && shortResult < threshold, shortResult, 0 );
SellAtProfit = IIf( Sell && longResult > threshold, longResult, 0 );
CoverAtProfit = IIf( Cover && shortResult > threshold, shortResult, 0 );

WinningTrades = IIf( SellAtProfit, SellAtProfit,
                     IIf( CoverAtProfit, CoverAtProfit, 0 ) );
LosingTrades = IIf( SellAtLoss, SellAtLoss,
                    IIf( CoverAtLoss, CoverAtLoss, 0 ) );
AllTrades = IIf( SellAtProfit, SellAtProfit,
                 IIf( CoverAtProfit, CoverAtProfit,
                      IIf( SellAtLoss, SellAtLoss,
                           IIf( CoverAtLoss, CoverAtLoss, 0 ) ) ) );

MAXPROFITTRADE = HighestSince( isStartOfDay, WinningTrades );
MAXLOSSTRADE = LowestSince( isStartOfDay, LosingTrades );
TOTALPL = SumSince( isStartOfDay, allTrades ) ;
TOTALLOSS = SumSince( isStartOfDay, LosingTrades ) ;
TOTALPROFIT = SumSince( isStartOfDay, WinningTrades ) ;
WinningTrades1 = IIf( SellAtProfit, SellAtProfit, IIf( CoverAtProfit, CoverAtProfit, 1e10 ) );
LosingTrades1 = IIf( SellAtLoss, SellAtLoss, IIf( CoverAtLoss, CoverAtLoss, -1e10 ) );
MINPROFITTRADE = LowestSince( isStartOfDay, WinningTrades1 );
MINLOSSTRADE = HighestSince( isStartOfDay, LosingTrades1 ) ;

I did put the cursor after the last candle as I know that otherwise it won't provide correct output.

I think probably the problem was :

it was not able to work for the trade results which are above zero and still regarded as loss as I changed the threshold value as 3 instead of zero.

I feel so, because it worked perfectly in case of MINPROFITTRADE as the min value will be above 3 which is positive value only.

Regarding your recent modified code, I will check and get back to you once I go home.

as far as I can see it is working correctly. I added N trades/ N Winners and N Losers

////////////////////////////////////////////////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 = 5;
//////////////////////////////////////////////////////////////////
Plot( EMA( Close, 5 ), "", colorGreen, styleThick );
Plot( EMA( Close, 13 ), "", colorRed, styleThick );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

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 ) OR Ref( separator, 1 ) );
Cover = Buyst OR( ( TimeNum() > 151500 ) OR Ref( separator, 1 ) );

BUY = ExRem( BUY, SELL );
SELL = ExRem( SELL, BUY );
SHORT = ExRem( SHORT, COVER );
COVER = ExRem( COVER, SHORT );

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 ) );
Signalshape = Cover * shapeHollowUpArrow + Sell * shapeHollowDownArrow;
PlotShapes( Signalshape, IIf( Cover, colorGreen, colorRed ), 0, IIf( Cover, Low, High ) );

////////////////////////////////////////////////////////////////////////////////////////////////
isStartOfDay = Day() != Ref( Day(), -1 ) ;
longResult = IIf( Sell, SellPrice - ValueWhen( Buy, BuyPrice ), 0 );
shortResult = IIf( Cover, ValueWhen( Short, ShortPrice ) - CoverPrice, 0 );

threshold = 0;
SellAtLoss = IIf( Sell && longResult < threshold, longResult, 0 );
CoverAtLoss = IIf( Cover && shortResult < threshold, shortResult, 0 );
SellAtProfit = IIf( Sell && longResult > threshold, longResult, 0 );
CoverAtProfit = IIf( Cover && shortResult > threshold, shortResult, 0 );

WinningTrades = IIf( SellAtProfit, SellAtProfit,
                     IIf( CoverAtProfit, CoverAtProfit, 0 ) );
LosingTrades = IIf( SellAtLoss, SellAtLoss,
                    IIf( CoverAtLoss, CoverAtLoss, 0 ) );
AllTrades = IIf( SellAtProfit, SellAtProfit,
                 IIf( CoverAtProfit, CoverAtProfit,
                      IIf( SellAtLoss, SellAtLoss,
                           IIf( CoverAtLoss, CoverAtLoss, 0 ) ) ) );

MAXPROFITTRADE = HighestSince( isStartOfDay, WinningTrades );
MAXLOSSTRADE = LowestSince( isStartOfDay, LosingTrades );
TOTALPL = SumSince( isStartOfDay, allTrades ) ;
TOTALLOSS = SumSince( isStartOfDay, LosingTrades ) ;
TOTALPROFIT = SumSince( isStartOfDay, WinningTrades ) ;
WinningTrades1 = IIf( SellAtProfit, SellAtProfit,
                      IIf( CoverAtProfit, CoverAtProfit, 5e10 ) );
LosingTrades1 = IIf( SellAtLoss, SellAtLoss,
                     IIf( CoverAtLoss, CoverAtLoss, -5e10 ) );
MINPROFITTRADE = LowestSince( isStartOfDay, WinningTrades1 );
MINLOSSTRADE = HighestSince( isStartOfDay, LosingTrades1 );
MINPROFITTRADE = IIf( MINPROFITTRADE == 5e10, 0, MINPROFITTRADE );
MINLOSSTRADE = IIf( MINLOSSTRADE == (-5e10), 0, MINLOSSTRADE ); 

NumberOfWinningTrades = SumSince( isStartOfDay, IIf( WinningTrades, 1, 0 ) );
NumberOfLosingTrades = SumSince( isStartOfDay, IIf( LosingTrades, 1, 0 ) );
NumberOfTrades = SumSince( isStartOfDay, IIf( AllTrades, 1, 0 ) );
/////////////////////

GfxSelectSolidBrush( colorBlack );
GfxSetBkMode( 1 );
GfxSelectFont( "Tahoma", 7, 100 );
x = Status( "pxchartwidth");
y = Status( "pxchartheight");
x0 = 10;
y0 = y * 0.8;
x1 = x/14;
y1 = y * 0.99;
dx = 10;
dy = 15;
GfxSelectPen( colorLightBlue, 1 ); // border color
GfxRoundRect( x0, y0, x1, y1 , 7, 7 ) ;
GfxSetTextColor( colorLightBlue );
GfxTextOut( "N TRADES  = " + Prec( NumberOfTrades , 2 ), x0 + dx, y0 + 5 + dy * 0 );
GfxSetTextColor( colorBrightGreen );
GfxTextOut( "N WINNERS  = " + Prec( NumberOfWinningTrades, 2 )  , x0 + dx, y0 + 5 + dy * 1 );
GfxSetTextColor( colorBrightGreen );
GfxTextOut( "N LOSERS  = " + Prec( NumberOfLosingTrades, 2 )  , x0 + dx, y0 + 5 + dy * 2 );
GfxSetTextColor( colorRed );
GfxTextOut( "MAX LOSER  = " + Prec( MAXLOSSTRADE, 2 ), x0 + dx, y0 + 5 + dy * 3 );
GfxSetTextColor( colorBrightGreen );
GfxTextOut( "MAX WINNER  = " + Prec( MAXPROFITTRADE, 2 ), x0 + dx, y0 + 5 + dy * 4 );
GfxSetTextColor( colorRed );
GfxTextOut( "MIN LOSER  = " + Prec( MINLOSSTRADE, 2 ), x0 + dx, y0 + 5 + dy * 5  );
GfxSetTextColor( colorBrightGreen );
GfxTextOut( "MIN WINNER  = " + Prec( MINPROFITTRADE, 2 ), x0 + dx, y0 + 5 + dy * 6 );
GfxSetTextColor( colorRed );
GfxTextOut( "TOTAL LOSS = " + Prec( TOTALLOSS, 2 ), x0 + dx, y0 + 5 + dy * 7 );
GfxSetTextColor( colorBrightGreen );
GfxTextOut( "TOTAL PROFIT = " + Prec( TOTALPROFIT, 2 ), x0 + dx, y0 + 5 + dy * 8 );
GfxSetTextColor( colorWhite );
GfxTextOut( "TOTAL P/L = " + Prec( TOTALPL, 2 ) , x0 + dx, y0 + 5 + dy * 9 );
////////////////////////////////////

sz = 8;
bkcol = ColorRGB( 40, 40, 40 );

for( i = fvb; i <= lvb; i++ )
{
    if( Buy[i] && Cover[i] )
    {
        str = "Buy: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
        str = "Cover: " + C[i] + " (" + shortResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -50 );
    }

    if( !Buy[i] && Cover[i] )
    {
        str = "Cover: " + C[i] + " (" + shortResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
    }

    if( Buy[i] && !Cover[i] )
    {
        str = "Buy: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), bkcol, -35 );
    }

    if( Short[i] && Sell[i] )
    {
        str = "Short: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
        str = "Sell: " + C[i] + " (" + longResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 40 );
    }

    if( !Short[i] && Sell[i] )
    {
        str = "Sell: " + C[i] + " (" + longResult[i] + ")";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
    }

    if( Short[i] && !Sell[i] )
    {
        str = "Short: " + C[i];
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), bkcol, 25 );
    }
}

could you please just check by changing the threshold value to 3 (or anything greater than zero).

Otherwise , once I go home ---I will check and get back to you, I am in office so I do not have amibroker here.

could you please just check by changing the threshold value to 3 (or anything greater than zero).

Otherwise , once I go home ---I will check and get back to you, I am in office so I do not have amibroker here.

in addition how can we catch the below values as the open value of the next candle:

BuyPrice = ValueWhen( Buy, C );
ShortPrice = ValueWhen( Short, C );
CoverPrice = ValueWhen( Cover, C );
SellPrice = ValueWhen( Sell, C );

Because I think , once the signal is generated at the close of a candle the next practical possible value to catch for live trading is the open of next candle only.

Am I correct in my thinking. If yes, then how can we amend these codes.

i checked. here is an example. In this day there is 1 trades that has a result of +2.

First chart shows threshold = 0, second chart shows threshold = 3. Notice the number of winners versus number of losers changes. Also MIN LOSER goes from -6 to 2. Because the trade with the result +2 in the first chart was the MIN WINNER, now becomes the MIN LOSER.

threshold = 0
c1

threshold = 3
c2

1 Like

that would just be:

BuyPrice = ValueWhen( ref( Buy, -1 ), Open );

etc.

Ok, if it worked for you---it should work for me as well.

Once I go home ---I will check and update you.

Thanks for your time and help.

I tested now and every thing is perfectly fine .
Once again, Hats Off to the Legend as always!!!

just as a last part to this code I want to add the applystop coding concept here to save the profit by using trailing stoploss when the trade is in profit and stoploss when the trade is in loss.

But , while doing this do we need to remove the code for sell and cover or how to implement it----I am totally in a bush and messed up.

could you please give me a correct start up.

once buy or sell is executed after 9:30am that means once we are either in long or short trade after 9:30am in stead of sell and cover statergy I want to implement the applystop coding concept to come out of the trade before 3:15 pm by using trailing stoploss when the trade is in profit and by using stoploss when the trade is in loss.

is the above idea possible?

I tried to code with applystop, but did not get success.

please advise.