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.


Topics - singhboy

Pages: [1]
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 / 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

3
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

4
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

5
Amibroker Help / Exploration on Multi Time frame
« on: May 22, 2010, 06:33:09 am »
Hi, I use this exploration afl on 5 mint time frame

Code: [Select]
x = EMA(Close,13);
y = EMA (Close,5);

Buy=Cross(y,x)

   AND  (
( StochK( 5, 3)>StochD( 5, 3, 3 ))
       
);

Short= Cross(x,y)
  AND (
 ( StochK( 5,3) < StochD(5,3,3))
   
);

Filter=(Volume>100000) AND (Buy OR Short) AND (Close>200);
AddColumn(Close,"Close",1.4);
AddColumn(Buy,"buy",1.2);
AddColumn(Short,"short",1.2);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );
AlertIf( Short, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );


Now I want to add an aditional condition. I want the buy signal when stoch is up on both 5 mint and 15 mint time frames. When I explore on 5 mint, stoch condition is met on 5 mint but sum1 pls modify this afl so that it fulfills stoch condition on 15 mint as well. Thnx alot in advance

Pages: [1]