Simple Coding Help - No Promise.

casoni

Well-Known Member
After modifying the code (as given below), the error is gone.
//------------ 2
Buy2 = C>xx AND C>trailarray;
Sell2 = C<xx AND C<trailarray;
buy2=ExRem(buy2,sell2);
sell2=ExRem(sell2,buy2);

Buy=Cover=Buy2;
Sell=Short=Sell2;

PlotShapes(Buy2*shapeUpArrow+Sell2*shapeDownArrow, IIf(Buy2,colorGreen,colorRed),0,IIf(Buy2,L-30,H+30)) ;


I backtested it for this week on Banknifty and getting only 2 trades in the result. But actually there has been around 13 trades as shown in the chart. Not sure why? Need your help on this please.
check Backtester settings .. [ inital capital,Lot size , etc..etc..i] i think problem is in the settings.. , if you scan this will show you all entries


* to avoid confusion use this
PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow, IIf(Buy,colorGreen,colorRed),0,IIf(Buy,L-10,H+10)) ;
 
check Backtester settings .. [ inital capital,Lot size , etc..etc..i] i think problem is in the settings.. , if you scan this will show you all entries


* to avoid confusion use this
PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow, IIf(Buy,colorGreen,colorRed),0,IIf(Buy,L-10,H+10)) ;
Anything i am missing here in this setting box? Also i changed code as per above to avoid any confusion. Yes, in scan all 13 trades are coming, but backtesting is showing only 2 trades.

 
Last edited:
Dear Friends,

I need a small coding help. I have generated buy sell signals bases Stochastic and want to compare "recent buy signal value" with "previous buy signal value". I am not able to get the values. Please let me know how to get these 2 values.

Regards...Dinesh
 

casoni

Well-Known Member
Hello Dinesh,
I hope , this is what you are looking for



Code:
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
st1=StochK( periods , Ksmooth);
st2=MA(st1,5);
Plot( st1, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
Plot(st2,"",3,1);
Buy=Cross(st1,st2);
sell=Cross(st2,st1);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
val1=ValueWhen(buy,st1,1);
val2=ValueWhen(buy,st1,2);
xx=BarIndex();x=xx;Lx=LastValue(x);
fvb=Status("firstvisiblebarindex"); 
lvb=Min(Lx,Status("lastvisiblebarindex")); 

for(i=fvb;i<lvb;i++)  
{ 
    if(buy[i]) PlotTextSetFont(""+st1[i],"Ariel",8,i,st2[i],colorGreen,colordefault,-15); 
    if(sell[i]) PlotTextSetFont(""+st1[i],"Ariel",8,i,st2[i],colorred,colordefault,15); 
    
}
Title=Name()+
"\n1st buy   : "+ val1+ "\n" +"2st buy   : "+ val2;
 
Anything i am missing here in this setting box? Also i changed code as per above to avoid any confusion. Yes, in scan all 13 trades are coming, but backtesting is showing only 2 trades.

BNFT bro,
Pls look at the 2nd trade on your BackTesting Results, it has taken 1150 contracts (more than ur Initial Capital 5 lac can chew) and suffered a huge loss more than ur Initial Capital can digest, meaning there is no positive capital left to take on the remaining trade signals on ur Chart /Scan list after that massive loss. HENCE only 2 trades.
Pls add the following line at the end of ur AFL to limit the number of Scrips/ contracts to be traded per signal.

setpositionsize(1,spsShares) ;// if u desire to trade only 1 contract per signal

setpositionsize(3,spsShares) ;// if u desire to trade 3 contracts per signal

Thank u
 
Hey casoni...thanks for such a quick response. The solution looks good and seems like what I am looking for however when I tried to use the code, it shows error on Ln:19, Col: 15 syntax error, unexpected "(" in following lines of code

if(Buy), PlotTextSetFont(""+st1,"Ariel",8,i,st2,colorGreen,colorDefault,-15);
if(Sell) PlotTextSetFont(""+st1,"Ariel",8,i,st2,colorRed,colorDefault,15);


Fyi, I am using Amibroker ver 5.6

Request if you could please look into it please.

Regards...Dinesh
 

sr114

Well-Known Member
Hey casoni...thanks for such a quick response. The solution looks good and seems like what I am looking for however when I tried to use the code, it shows error on Ln:19, Col: 15 syntax error, unexpected "(" in following lines of code

if(Buy), PlotTextSetFont(""+st1,"Ariel",8,i,st2,colorGreen,colorDefault,-15);
if(Sell) PlotTextSetFont(""+st1,"Ariel",8,i,st2,colorRed,colorDefault,15);


Fyi, I am using Amibroker ver 5.6

Request if you could please look into it please.

Regards...Dinesh


use Plottext in place of Plottextsetfont as ver 5.6 doesnot support this function

see function help for plottext and u will get the proper code

rgds
 
Last edited:
I could modify the text dear but now there is another point that I need help for 1) the values shown are of Stoch...I need for price (I even tried to replace st with Val1 and val2 but it still shows stoch values rather then price
2) This is not so important but I am getting the text plotted on left hand corner instead of where the stoch is crossing.

Could you please have one last look on the same.

Regards,
Dinesh
 
Last edited:

sr114

Well-Known Member
I could modify the text dear but now there is another point that I need help for 1) the values shown are of Stoch...I need for price (I even tried to replace st with Val1 and val2 but it still shows stoch values rather then price
2) This is not so important but I am getting the text plotted on left hand corner instead of where the stoch is crossing.

Could you please have one last look on the same.

Regards,
Dinesh
un case of val1 , replace
ValueWhen(Buy,st1,1)
with
ValueWhen(Buy,C,1)

and in plottext change st1 with val1 and u will get the price and not the stoch value
 

Similar threads