Profit and Loss

casoni

Well-Known Member
#2
While Back-testing We are getting like this



i want the Profit area list shown inside the chart
if it is possible pls help me out(casoni)
For reference :

http://www.amibroker.com/guide/a_custombacktest.html
Hello ,
not good idea to Displying Profit inside chart , as it will slower the formula .
best way is to get result via exploration...


_SECTION_BEGIN( "Exploration" );

BuyProfit= (SellPrice- BuyPrice);
ShortProfit =(ShortPrice-CoverPrice);
a1=IIf(Sell,BuyPROFIT,Null);
b1=IIf(Cover,ShortProfit,Null);
a3=IIf(Sell,a1,IIf( Cover,b1 ,Null)); // tell me the points of every trade
Mycolor = IIf( a3 > 0 , colorGreen, colorRed);

Filter = Buy OR Sell OR Short OR Cover;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, 1, colorDefault, 70);
AddColumn(DateTime(), "Date", formatDateTime, 1, colorDefault, 120);
AddColumn(IIf(Buy, Asc("Buy",0), Asc("Sell")), "PosL", formatChar);
AddColumn( Buy, "Buy", 1 );
AddColumn(IIf( Buy, BuyPrice, Null ) ,"BUY_P",1.2,colorDefault,colorDefault,60);
AddColumn(IIf(Sell,SellPrice,Null),"SELL_P",1.2, colorDefault,colorDefault,60);
AddColumn(a1,"Long-P/L",1.4,colorDefault,13 ,60);
AddColumn(IIf(Short, Asc("Short",0), Asc("Cover")), "PosS", formatChar);
AddColumn( Short, "Short", 1 );
AddColumn(IIf( Short, ShortPrice, Null ) ,"Short_P",1.2,colorDefault,colorDefault,70);
AddColumn(IIf(Cover,CoverPrice,Null),"Cover_P",1.2,colorDefault,colorDefault,70);
AddColumn(b1,"Short-P/L",1.4,colorDefault, 13 ,60);
AddColumn(a3,"Gain/Loss",1.2,1,Mycolor ,80);
// contains wining trades of every 2 lines
AddSummaryRows( 1, 1.2, 4,7,9, 12,13,15 );

_SECTION_END();

Hope this helps
 
Last edited:
#3
Hello ,
not good idea to Displying Profit inside chart , as it will slower the formula .
best way is to get result via exploration...


_SECTION_BEGIN( "Exploration" );

BuyProfit= (SellPrice- BuyPrice);
ShortProfit =(ShortPrice-CoverPrice);
a1=IIf(Sell,BuyPROFIT,Null);
b1=IIf(Cover,ShortProfit,Null);
a3=IIf(Sell,a1,IIf( Cover,b1 ,Null)); // tell me the points of every trade
Mycolor = IIf( a3 > 0 , colorGreen, colorRed);

Filter = Buy OR Sell OR Short OR Cover;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, 1, colorDefault, 70);
AddColumn(DateTime(), "Date", formatDateTime, 1, colorDefault, 120);
AddColumn(IIf(Buy, Asc("Buy",0), Asc("Sell")), "PosL", formatChar);
AddColumn( Buy, "Buy", 1 );
AddColumn(IIf( Buy, BuyPrice, Null ) ,"BUY_P",1.2,colorDefault,colorDefault,60);
AddColumn(IIf(Sell,SellPrice,Null),"SELL_P",1.2, colorDefault,colorDefault,60);
AddColumn(a1,"Long-P/L",1.4,colorDefault,13 ,60);
AddColumn(IIf(Short, Asc("Short",0), Asc("Cover")), "PosS", formatChar);
AddColumn( Short, "Short", 1 );
AddColumn(IIf( Short, ShortPrice, Null ) ,"Short_P",1.2,colorDefault,colorDefault,70);
AddColumn(IIf(Cover,CoverPrice,Null),"Cover_P",1.2,colorDefault,colorDefault,70);
AddColumn(b1,"Short-P/L",1.4,colorDefault, 13 ,60);
AddColumn(a3,"Gain/Loss",1.2,1,Mycolor ,80);
// contains wining trades of every 2 lines
AddSummaryRows( 1, 1.2, 4,7,9, 12,13,15 );

_SECTION_END();

Hope this helps

thankyou for your clean work but really dont know what it does, i need to explore and let me ask if i have any doubts
thankyou very much for your clean code
 

casoni

Well-Known Member
#4

thankyou for your clean work but really dont know what it does, i need to explore and let me ask if i have any doubts
thankyou very much for your clean code
Yes just you need explore .
and to test any susyem , you need to do the following
1] defines buy-sell-short -cover rules
2] optimize on different time frames and find the best result [ % profit]
then use those settings [ parametes ] in AA and run explorer . it will give you profit/loss per trade excluding other taxes [ i.e brokrage-stt-turnover tax] etc

here's the expample code



SetChartBkColor(ColorRGB(100,100,100));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);

f=Optimize("fma",Param("fma",5,3,10,1),3,10,1);
s=Optimize("sma",Param("sma",10,6,20,1),6,20,1);

fMA=MA(C,f);
SMA=MA(C,s);
Plot(FMA,"",ColorRGB(0,0,100),1,Null,Null,0,-1,1);
Plot(SMA,"",ColorRGB(100,0,0),1,Null,Null,0,-1,1);

Buy=Cross(FMA,SMA);
Short=Cross(SMA,FMA);

Sell=Cross(sma,C);
Cover=Cross(C,sma);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


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

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),Colorgreen,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapehollowDownArrow,shapeNone),Colorlime,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapedownarrow,shapeNone),ColorRed,0,H,-30);
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapehollowuparrow,shapeNone),colororange,0,L,-30);
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);

_SECTION_BEGIN( "Exploration" );

BuyProfit= (SellPrice- BuyPrice);
ShortProfit =(ShortPrice-CoverPrice);
a1=IIf(Sell,BuyPROFIT,Null);
b1=IIf(Cover,ShortProfit,Null);
a3=IIf(Sell,a1,IIf( Cover,b1 ,Null)); // tell me the points of every trade
Mycolor = IIf( a3 > 0 , colorGreen, colorRed);

Filter = Buy OR Sell OR Short OR Cover;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, 1, colorDefault, 70);
AddColumn(DateTime(), "Date", formatDateTime, 1, colorDefault, 120);
AddColumn(IIf(Buy, Asc("Buy",0), Asc("Sell")), "PosL", formatChar);
AddColumn( Buy, "Buy", 1 );
AddColumn(IIf( Buy, BuyPrice, Null ) ,"BUY_P",1.2,colorDefault,colorDefault,60);
AddColumn(IIf(Sell,SellPrice,Null),"SELL_P",1.2, colorDefault,colorDefault,60);
AddColumn(a1,"Long-P/L",1.4,colorDefault,13 ,60);
AddColumn(IIf(Short, Asc("Short",0), Asc("Cover")), "PosS", formatChar);
AddColumn( Short, "Short", 1 );
AddColumn(IIf( Short, ShortPrice, Null ) ,"Short_P",1.2,colorDefault,colorDefault,70);
AddColumn(IIf(Cover,CoverPrice,Null),"Cover_P",1.2,colorDefault,colorDefault,70);
AddColumn(b1,"Short-P/L",1.4,colorDefault, 13 ,60);
AddColumn(a3,"Gain/Loss",1.2,1,Mycolor ,80);
// contains wining trades of every 2 lines
AddSummaryRows( 1, 1.2, 4,7,9, 12,13,15 );
// end actionExplore
_SECTION_END();
hope this helps
thank you

this is exploration result of above code

 
Last edited:

casoni

Well-Known Member
#8



is this right??

How about the Lotsize multiplication with profit
Yes looks allright ,
you have Buy=cover and sell=short... correct !!

add [ comm+stt+teunovertax etc..] to buy price
vice versa for short price

you will get the result ..
 
#9
buy=diff
sell=biff
short=gigg
cover=biig

all four conditions is different

How to add the Equity Curve in that with positionsizing and brokerage calculation
 

casoni

Well-Known Member
#10
buy=diff
sell=biff
short=gigg
cover=biig

all four conditions is different

How to add the Equity Curve in that with positionsizing and brokerage calculation
diff + buyprice that will be your total buy cost , same with sell,short,cover
for positionsizing you need to define target level

i.e trade 2 lots at a time , exit 1 lot when target is achived and exit when trailing stoploss hit's or trade reverses
 

Similar threads