Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - singhboy

Pages: [1] 2
1
Amibroker Help / *Trading System Backtesting*
« on: October 02, 2011, 12:04:35 pm »
Hello Traders, I am trying to make a Trading system for NIFTY. It has simple conditions but impressive results. I have written Half part of the System AFL. Need your help to complete AFL and run backtesting. The AFL is as follows




SetChartOptions(0,chartShowArrows|chartShowDates,c olorRed);


Plot(C,"Price",IIf(C>O,colorBrightGreen,colorBrown ),styleCandle);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L,C, SelectedValue( ROC( C, 1 )) ));

_SECTION_END();



Plot(EMA(Close,200),"Fast",colorCustom11,style=sty leThick|styleNoLabel);



_SECTION_BEGIN("15 mint MACD");
TimeFrameSet( in15Minute=15*60);
m = MACD(12, 26 ); // MACD from 15 minute data
s= Signal(12,26,9);
TimeFrameRestore();

m1 = TimeFrameExpand( m, in15Minute=15*60 );
s1 = TimeFrameExpand(s,in15Minute=15*60) ;


MM1= m1>s1 ;
MM2= m1<s1;

_SECTION_END();
Cond2= EMA(C,200);
Cond1= C ;


B1 = (Cond1>Cond2) ;
S1 = (Cond1<Cond2);
B2 = (MACD()>Signal()) AND MM1;
S2= (MACD()<Signal()) AND MM2;

EMAUP = Flip(B1,S1);
MACDUP = Flip(B2,S2);

BSig = EMAUP AND MACDUP;
SSig = (NOT EMAUP) AND (NOT MACDUP);

BSig = ExRem(Bsig,Ssig);
SSig = ExRem(Ssig,Bsig);



EMADOWN= Flip (S1,B1) ;
MACDDOWN = Flip (S2,B2);
Asig = EMADOWN AND MACDDOWN ;
SSSig = (NOT EMADOWN) AND (NOT MACDDOWN );
Asig = ExRem (Asig,sssig) ;
sssig = ExRem(sssig,Asig);



LongBookProfit = H> BSig+50 ;
ShortBookProfit= L<ASig-50 ;

Sell1= (C< Cond2 AND MACD()<Signal()) OR C<Bsig-25 ;
Buy1= ( C>Cond2 AND MACD() > Signal() ) OR C>Asig+25 ;

Buy = Bsig ;
Sell= Sell1 OR LongBookProfit;
Short= Asig;
Cover= Buy1 OR ShortBookProfit;

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







PlotShapes(IIf(BSig, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-20);
PlotShapes(IIf(BSig, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-30);
PlotShapes(IIf(BSig, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);
PlotShapes(IIf(ASig, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(ASig, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(ASig, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);


_SECTION_END();


Conditions are Buy when price cross above 200 EMA, and macd is above signal line on both 5 mint and 15 mint time frame. Opposite for shorts.

Stop loss, for longs, either 25 points down the buy price, or if macd on 5 mint crosses down and price cross below 200 EMA, whichever happens 1st.
Opposite for shorts.

Profit booking for Longs, 1st LOT book at 50 points profit and book 2nd at 100 points profit.


Now there needs many modifications in my AFL.
1.) I think book profit conditions are wrong LongBookProfit = H> BSig+50
How to add 50 points to Buy price? similar with 25 pts SL condition.

2.) Suppose 200 EMA is at 5200, price cross up 5200 but macd is below
signal line on 5 and 15 mint charts. After few time price is at 5210 and
macd is above signal line on 5 mint but below Signal line on 15 mint.
Then price at 5235 and MACD is above signal line on both 5 and 15 mint
charts. So now a buy signal will appear at 5235. But I want that Buy
should trigger only within 20 pts range from 200 ema, i.e between
5200-5220. If all the conditions are fullfilled at 5235, then the system
should wait for 5220. If it reverse back to 5220 and all the conditions
for going long are still valid then BUY should trigger (note we will see
LOW of candle to see whether it comes to 20 points range from 200
EMA, we will not wait for close). And if price doesnt reverse back, it
should ignore the Buy Signal. Opposite for shorts.

3.) In the above AFL profit booking conditions are for 1 Lot only. I dont Know
How to write profit booking conditions for 2nd LOT.

4.) Suppose we are long and our SL is hit ( either 25 Pts SL or macd down on
5 mint and price<200 EMA). We will trade long again when long conditions
are met again.

5.) For trailing SL, when we book 1st Lot at 50 Pts profit and price goes 70
Pts in our favor, we will revise SL to 10 Pts below 1st Tgt ( for Longs).

6.) We will hold only half Qty for next day if price closes in our favor but
doesnt hit even 1st Tgt ( 50 pts profit). We will exit 1 Lot at close price
and will hold 2nd for next day. And on next day If hit Tgt, we will exit
100% qty i.e only 1 LOT at 1st Tgt.


So pls help me to complete this AFL and also backtesting it. BIG THANKS in Advance

2
Amibroker Help / Re: Avg Trade Price (vwap)+Crossover AFL help
« on: August 07, 2011, 02:14:56 am »
Admin help please

3
Amibroker Help / Re: Avg Trade Price (vwap)+Crossover AFL help
« on: August 05, 2011, 06:27:28 am »
Forgot to tell that in this example, the same levels 5205 and 5180 will be used for buy sell for whole day.  And we will use 5 mint chart, as the avg trade price is different on 5 mint and 15 mint chart so we will take 9.30 am time on 5 mint candle, regardless of the condition that we trade 5 mint chart, 15 mint or 1 hour chart

4
Amibroker Help / Avg Trade Price (vwap)+Crossover AFL help
« on: August 05, 2011, 06:19:42 am »
Dear Readers I have an startegy in my mind. Can you please help in making that afl. I have an afl of avg trade price i.e vwap. Now we will take the avg trade price of 9.30 am or you can even say we will take avg trade price of 3rd candle on the 5 mint chart. Once the avg trade price of 9.30 am on 5 mint chart is decided, we will use this avg trade price for whole day.

Now We will put some Price levels in the afl, which could be edited anytime we want. For example , suppose I have some Fibonananci, gann, pivots or other important support resistance levels of nifty
A= 5180
B=5205
C= 5222
D= 5241
E= 5258 and so on

suppose avg trade price at 9.30 comes 5196. Now the first level above avg trade price is 5205 , so the long call will be initiated above 5205 ( not closing above 5205, even just on break). The stop loss and reverse call be initiated below the fisrt level that comes below avg tarde price i.e 5180.

The avg trade price AFL is

//
// NOTE: the code is SLOOOOWWWW...can someone help speed it up?
// I tried my best, but can't really do much with the two for-loops...
//
// LarryJR - ljr500@hotmail.com


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates,c olorRed);


Plot(C,"Price",IIf(C>O,colorBrightGreen,colorBrown ),styleCandle);
SetBarsRequired( 10000, 0 );

// this stores true/false based on a new day...
newday=Day() != Ref(Day(), -1);

SumPriceVolume=0;
totVolume=0;
Vwap2=0;
stddev=0;
newdayindex=0;
Variance =0;

for( i= 0; i < BarCount; i++ )
{
// only want to reset our values at the start of a new day
if (newday==True)
{
SumPriceVolume=0;
totVolume=0;
newdayindex=i; // this is the index at the start of a new day
Variance=0;
//Vwap2=0;
}
AvgPrice=(O + H + L + C)/4;

// Sum of Volume*price for each bar
sumPriceVolume += AvgPrice * (Volume);

// running total of volume each bar
totVolume += (Volume);

if (totVolume >0)
{
Vwap2=Sumpricevolume / totVolume ;
Vwap2temp=Vwap2;
}



Variance=0;
for (j=newdayindex; j < i; j++)
{
AvgPrice=(O[j] + H[j] + L[j] + C[j])/4;
Variance += (Volume[j]/totVolume) *
(Avgprice-Vwap2temp)*(Avgprice-Vwap2temp);
}

}
Plot (Vwap2,"VWAP2",colorWhite, styleLine);


I will be very thankful if some1 helps me

5
Amibroker Help / Re: Need help with Simple EMA+MACD AFL-Admin Help
« on: July 17, 2011, 02:23:09 am »
No Admin Please you still didnt get it . I have given time values just to simplify my example . It doesnt matter how many bars. Please look again .

Price cross up 50 EMA at 1.00 PM and MACD is grater than signal line then buy signal will appear. Or Price cross up 50 EMA at 1.00 PM and Macd Cross up Signal Line at 1.30 PM , then a buy signal would appear.
Now suppose price remains above 50 EMA but at 1.45 PM Macd cross Down Signal Line , and then at 2 PM, it again cross up Signal Line. Because price is already above 50 ema , then a double buy signal will appear at 2 PM. Now there will be two buy signals, one which generated at 1.30 PM, 2nd which generated at 2 PM.

What I want that there should be only one buy signal for the fresh cross of macd above signal line, after the price crossed above 50 ema.

6
Amibroker Help / Re: Need help with Simple EMA+MACD AFL-Admin Help
« on: July 16, 2011, 12:23:34 pm »
Dear Admin this is the AFL

Code: [Select]
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates,colorRed);


Plot(C,"Price",IIf(C>O,colorSeaGreen,colorBrown),styleCandle);





 
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 5, 2, 200, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Mid EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods",20, 2, 300, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCustom9 ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Long EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 50, 2, 400, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCustom11 ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style") | styleNoRescale | styleNoRescale;
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
_SECTION_END();



_SECTION_END();

x= EMA(C,50);

Buy = Cross (C, x) AND MACD() > Signal() ;




   
Sell = Cross ( x,C) AND MACD() < Signal() ;


 
;


AddColumn(Close,"Close",1.4);
AddColumn(Buy,"buy",1.2);
AddColumn(Sell,"sell",1.2);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-30);                     
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);                     
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);





_SECTION_END();

In this AFL, as I have written, Buy signal appear on charts when price cross up 50 EMA and MACD line is above SIGNAL line. But suppose price cross up 50 EMA but MACD is below SIGNAL line  then no buy signal appear on charts. I want that if price cross up 50 EMA  at 1.30 PM and but MACD cross up SIGNAL line at 1.40 PM ( Take 5 mint chart example) then a buy signal should appear at 1.40 PM. Means after crossing up 50 EMA whenver later MACD cross up SIGNAL line, a buy signal should appear on chart. Now you may write this conditon

Buy1 = Cross (C, x) AND MACD() > Signal() ;
Buy2 = C > x AND Cross(MACD(), Signal() );

Buy = Buy1 OR Buy2;

In the above condition , a buy signal will appear at 1.40 PM , because now as in Buy2 condition , price is above 50 EMA and MACD cross up Signal line. But suppose at 1.50 PM MACD cross down SIGNAL line, but price remains above 50 EMA. so now when at 2.00 PM once again MACD cross up SIGNAL line , another buy signal will appear. I dont want that . What I want is that after price cross up 50 EMA and later when MACD cross up MCAD line , a buy signal should appear. This should be only once , there should not be any buy signal after the 1st signal while  MACD keeps on crossing SIGNAL line up and down. Buy signal should appaer once only for fresh cross up of price above 50 EMA and then whenever MACD cross up signal line. I hope you got what I want to say. Thanks for replying

7
Amibroker Help / Need help with Simple EMA+MACD AFL-Admin Help
« on: July 15, 2011, 12:50:48 am »
Hi Every1, I need help with this buy sell conditions signals on chart.
When price cross 50 EMA up side and MACD line is above Signal Line , buy signal should appear.
this can be like 
Buy = cross (c, ema(c,50),) and macd() > signal() ;

But this generate signal only when two conditions are met on same candle. While I want that if price crossed 50 ema on this candle and macd cross up after 1 or 2 candles buy signal should appear later, means after crossing 50 EMA whenever the MACD cross signal line up, the buy signal should appaer.
And it should not be like that if price is already above 50 EMA and then MACD cross above signal line, then there should be no signal. Buy signal should be for fresh price cross above 50 EMA and then whenever MACD cross signal line upside. Thanks bros

8
Amibroker Help / Re: Combining AFLs into single AFL
« on: June 26, 2010, 04:51:38 am »
Thanks a million times admin, U r very kind n generous   ;)
After the afl is made, it looks simple but everytime it sucks lots of my energy n then I laugh at myself that I couldnt get the simple mistake in afls. Thnx

9
Amibroker Help / Combining AFLs into single AFL
« on: June 25, 2010, 06:22:00 am »
Hi every1. I want to combine many exploration afls in one afl so that when i run

exploration, every afl included in this single afl will explore stocks on their

own time frame n conditions. Here is an example, pls tell if this is possible n

if yes then pls modify as the afl below doesnt work as required


Code: [Select]
_SECTION_BEGIN("bollinger");

TimeFrameSet(inHourly);

A= BBandTop(Close, 20, 2 );

B= BBandBot( Close, 20, 2 );



Bollinger1= (A-B< .02*C AND Close<400) OR (A-B< .015*C AND Close>400);

TimeFrameRestore();

_SECTION_END();



_SECTION_BEGIN("5 day high low");

TimeFrameSet(inDaily);

H = HHV(H, 4) ;

L= LLV(L,4) ;



High1= (Ref(H,-1)-C<.01*H AND Ref(H,-1)-C>.005 AND H< Ref(H,-1) AND C<400) OR

(Ref(H,-1)-C<.005*H AND Ref(H,-1)-C>0.005 AND C>400) ;

Low1= (C-Ref(L,-1)<.01*L AND C-Ref(L,-1)>.005 AND L>Ref(L,-1) AND C<400) OR

(C-Ref(L,-1)<.005*H AND C-Ref(L,-1)>0.005 AND C>400);



TimeFrameRestore();

_SECTION_END();

SetOption("NoDefaultColumns", True);



AddTextColumn(Name(), "Symbol");

AddColumn(C, "CMP", 1.2);

AddColumn(DateTime(), "Date", formatDateTime);

AddColumn(Bollinger1,"Bollinger1",1.2);

AddColumn(High1, "high1", 1.2);

AddColumn(low1, "low1", 1.2);

Filter = (Bollinger1 AND V>10000) OR ((High1 OR Low1) AND V>10000) ;

When i run exploration on 5 mint, it  explores stocks on

5 mint. But I want exploration on the given timeframe conditions  in each afl
regardless  of the periodicity I choose for scanning

10
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 23, 2010, 02:45:53 am »
thnx. @pkgmtnl, yes I knw we r replied quickly here. Thats why I posted my queries here. Thnx to admin for provding his time to help users

11
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 21, 2010, 05:57:19 am »
thnx sir, well here is the right one made with the help of pkgmtnl bro

Code: [Select]
TimeFrameSet(inDaily);
H = HHV(H, 4) ;
L= LLV(L,4) ;

High1=  (Ref(H,-1)-C<.01*H AND Ref(H,-1)-C>.005 AND H< Ref(H,-1) AND C<400) OR  (Ref(H,-1)-C<.005*H AND Ref(H,-1)-C>0.005  AND C>400) ;
Low1=  (C-Ref(L,-1)<.01*L AND C-Ref(L,-1)>.005 AND L>Ref(L,-1) AND C<400) OR  (C-Ref(L,-1)<.005*H AND C-Ref(L,-1)>0.005  AND C>400);

Filter= V>30000 AND  (High1 OR Low1);
TimeFrameRestore();

SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol");
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn(C, "CMP", 1.2);
AddColumn(High1, "high1", 1.2);
AddColumn(low1, "low1", 1.2);

12
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 20, 2010, 10:04:50 am »
 :(  no

13
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 20, 2010, 05:32:10 am »
Sir pls modify it according to ur timeframegetprice method

14
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 19, 2010, 11:03:36 am »
Yes sir, No particlar time frame though, but i will select periodicty 5 mint or 15 mint and want the afl to explore stocks on daily time frame. In fact I want to combine may afls in single afl, I use those afls on 5 n 15 mint. So I want that I include this afl too, while I will run exploration of all afls at same time, all afls will give their results on their own timeframes, But I will run exploration selecting periodicty same i.e 5mint or 15 mint.

15
Amibroker Help / Re: Exploration on Multi Time frame
« on: June 19, 2010, 02:38:56 am »
Now Im up again with new problem ::)  Hope u guys wont mind to help once again  ;)

I use this afl on periodicity Daily for exploration.

Code: [Select]
H = HHV(H, 4) ;
L= LLV(L,4) ;

High1=  (Ref(H,-1)-C<.01*H AND Ref(H,-1)-C>.005 AND H< Ref(H,-1) AND C<400) OR  (Ref(H,-1)-C<.005*H AND Ref(H,-1)-C>0.005  AND C>400) ;
Low1=  (C-Ref(L,-1)<.01*L AND C-Ref(L,-1)>.005 AND L>Ref(L,-1) AND C<400) OR  (C-Ref(L,-1)<.005*H AND C-Ref(L,-1)>0.005  AND C>400);

Filter= V>30000 AND  (High1 OR Low1);

SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol");
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn(C, "CMP", 1.2);
AddColumn(High1, "high1", 1.2);
AddColumn(low1, "low1", 1.2);

Now I want this afl to explore stocks on daily timeframe but by selecting periodicity as 5-15 mint timeframe or any other timeframe lower than daily. I made this afl for this but it doesn't work. Please modify it

Code: [Select]
H = HHV(H, 4) ;
L= LLV(L,4) ;

TimeFrameSet(inDaily);

High1=  (Ref(H,-1)-C<.01*H AND Ref(H,-1)-C>.005 AND H< Ref(H,-1) AND C<400) OR  (Ref(H,-1)-C<.005*H AND Ref(H,-1)-C>0.005  AND C>400) AND V>30000;
Low1=  (C-Ref(L,-1)<.01*L AND C-Ref(L,-1)>.005 AND L>Ref(L,-1) AND C<400) OR  (C-Ref(L,-1)<.005*H AND C-Ref(L,-1)>0.005  AND C>400) AND V>30000;
TimeFrameRestore();
High2= TimeFrameExpand(High1,inDaily);
Low2= TimeFrameExpand(Low1,inDaily);

Filter=   (High2 OR Low2);

SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol");
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn(C, "CMP", 1.2);
AddColumn(High2, "high2", 1.2);
AddColumn(Low2, "low2", 1.2);

Hope i get reply soon. Thanks

Pages: [1] 2