# Help me to create Amibroker AFL use with my formula

 Discuss Help me to create Amibroker AFL use with my formula at the AmiBroker within the Traderji.com; Dear all, I am using stochastic oscillator crossover system for trading. My parameter is Sto.Osci ...

 Traderji.com Help me to create Amibroker AFL use with my formula
 Register FAQ Calendar Search Today's Posts Mark Forums Read

#1
25th June 2010, 12:40 PM
 Member Join Date: Jun 2010 Posts: 111 Thanks: 78 Thanked 39 Times in 27 Posts
Help me to create Amibroker AFL use with my formula

Dear all,

I am using stochastic oscillator crossover system for trading. My parameter is Sto.Osci value 39,1 and moving average 3(E).

Here I have created AFL :-

uptrend= (StochK(39,3)>StochD(39,1,3));
downtrend=(StochK(39,3)<StochD(39,1,3));
Sell = Cross(downtrend,uptrend);
PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);

Above this code will show Buy & Sell Signal When Sto.Oscill Cross Above or Below Level. But I want buy and sell signal in below condition.

BUY CONDITION :- WHEN MARKET IS IN UPTREND [StochK(39,3) >StochD(39,1,3)] WE FIND WHICH CANDLE FIRST BREAK HIGH + 5 POINTS COMPARE WITH PRE.CANDLE HIGH THEN WANT SHOW HERE BUY SIGNAL.

SELL CONDITION :- WHEN MARKET IS IN DOWNTREND [StochK(39,3) <StochD(39,1,3)] WE FIND WHICH CANDLE FIRST BREAK LOW - 5 POINTS COMPARE WITH PRE.CANDLE LOW THEN WANT SHOW HERE SELL SIGNAL.

Here I attached Nifty Chart for Example.

Explanation :-

In this Above Chart, First 5 Candle is green . That means Sto.osci. (39,1) is Above The Moving Average (3) Line. But 4th Candle only (First) Breake Pre.Candle High + 5 Points.
So Here I want to get Buy Signal .

AND 6th & 7th Candle is Red. This means Sto.osci. (39,1) is Below The Moving Average (3) Line. But 7th Red Candle didnt Breake Pre.Candle Low. So Here is Continuing Our Long Trade.

8th and 9th Candle is Green and 9th Candle High also breake Pre.Candle High + 5. But Here we dont Get Buy Signal. Because Already we have Long Position. So we should wait only for Sell signal.

10th Candle is Red But 11th Candel didnt Breake 10th Candle Low. 12,15,18th also the same. [Compare the 17th red Candle low with 16th Candle low = 10 Points. But Pre.Candle 16 is Green] . So here also Contiuing our Long Position.

19th,20th,21st is green Candle and 21st candle is breake Pre.Candle High + 5. Here also we dont get Buy Signal . Because Already we have Long Position.

22nd and 23rd is red and 23rd Candle Breake Pre.Candle Low + 5 . So Here I want to get Sell signal.

24th Candle is Green But 25th Candle Didnt Breake High + 5 Points.

25th & 26th is Red Candle .------> Market closed.

This Day Total Trade : 1 Lot Long & 1 Lot Short.

Kindly Help Me to Create Buy & Sell Signal in My Condition.
 Sorry your browser does not support IFRAME

## Looking for a share broker?

#2
28th June 2010, 01:21 AM
 Member Join Date: May 2010 Posts: 65 Thanks: 8 Thanked 62 Times in 33 Posts
Re: Help me to create Amibroker AFL use with my formula

Can you check this?

uptrend= IIf( StochK(39,3) > StochD(39,3,3), 1, 0 );
downtrend=IIf( StochK(39,3)<StochD(39,3,3), 1, 0 );
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1) + 5));
SellV = downtrend AND Ref(downtrend,-1) AND (L > ( Ref(L, -1) - 5));

Sell = SellV AND BuySB < SellSB ;

It took couple of hours to get the logic of the last 2 lines.

I tried back testing of this and I did not get much from it. Is there another indicator that needs to be clubbed with this? or Any more theory that you can provide?

thank you
nagarjuna
 The Following 2 Users Say Thank You to nagarjuna13 For This Useful Post: singhboy (28th June 2010), smarttrade (28th June 2010)
#3
28th June 2010, 07:34 PM
 Member Join Date: Mar 2008 Posts: 81 Thanks: 34 Thanked 112 Times in 59 Posts
Re: Help me to create Amibroker AFL use with my formula

Try the attached code

vidyasagar
 The Following User Says Thank You to vkunisetty For This Useful Post: smarttrade (28th June 2010)
#4
28th June 2010, 08:02 PM
 Member Join Date: Jun 2010 Posts: 111 Thanks: 78 Thanked 39 Times in 27 Posts
Re: Help me to create Amibroker AFL use with my formula

Quote:
 Originally Posted by nagarjuna13 Can you check this? uptrend= IIf( StochK(39,3) > StochD(39,3,3), 1, 0 ); downtrend=IIf( StochK(39,3) ( Ref(H, -1) + 5)); SellV = downtrend AND Ref(downtrend,-1) AND (L > ( Ref(L, -1) - 5)); BuySB = BarsSince(Ref(BuyV,-1)); SellSB= BarsSince(Ref(SellV,-1)); Buy = BuyV AND BuySB > SellSB; Sell = SellV AND BuySB < SellSB ; It took couple of hours to get the logic of the last 2 lines. I tried back testing of this and I did not get much from it. Is there another indicator that needs to be clubbed with this? or Any more theory that you can provide? thank you nagarjuna
Dear Nagarjuna,
I dont know How to say Thanks to you. Exactly I was Expecting this. Thanks, Thanks, Thanks a lot.

#5
30th June 2010, 12:53 AM
 Member Join Date: May 2010 Posts: 65 Thanks: 8 Thanked 62 Times in 33 Posts
Re: Help me to create Amibroker AFL use with my formula

Quote:
 Originally Posted by smarttrade Dear Nagarjuna, I dont know How to say Thanks to you. Exactly I was Expecting this. Thanks, Thanks, Thanks a lot.
If possible, can you please respond to the following question? That will help me a lot.

Quote:
 Originally Posted by nagarjuna13 I tried back testing of this and I did not get much from it. Is there another indicator that needs to be clubbed with this? or Any more theory that you can provide?
 The Following User Says Thank You to nagarjuna13 For This Useful Post: smarttrade (30th June 2010)
#6
30th June 2010, 01:00 PM
 Member Join Date: Jun 2010 Posts: 111 Thanks: 78 Thanked 39 Times in 27 Posts
Re: Help me to create Amibroker AFL use with my formula

Dear Nagarjuna,

I am using this method for Trade Nifty Future in Intraday. Time Frame : 15 Min. If I get buy signal I will take 2 Lots in Nifty Future. I will Close 1 lot at Every 25 Points+ and Another 1 lot I will hold till 3.29 p.m.

Suppose I booked Ist lot in 25 points+. After that If I get sell signal I will Close that 1 lot Long Position & I will go Short 2 lots Nifty @ Sell Signal. Here also same first I will book one lot @ 25 Points Profit and another 1 Lot I will hold till 3.29 p.m..

Stop Loss :

For Buy : In Uptrend, Which Candle high Breake Pre.Candle High (Here We will get Buy Signal) I will put SL @ That Pre.Candle Low Value - 3 Points.

For Sell : In downtrend, Which Candle Low Break Pre. Candle Low (Here We will get Sell Signal) I will Put SL @ That Pre.Candle High Value + 3 Points .

In which Candle We get Buy or Sell Signal, I will use SL That Pre.Candle H/L value +/- 3 Points. I dont Modify this SL for Each Candle H/L .

One More Condition:

I will use this concept only for Intraday not for delivery. So everyday we should close all the position before market end. Another Day Morning We should get Fresh Signal. So we should add here one more condition If we get buy or Sell signal, We must check here Pre.Candle and Current Candle Date also Should be the Same Date. This will help to Avoid Continuing Yesterday's Signal.

One More Request Can You give your code with Add of this above Condition with SL? and I am trying to write this same concept for Metastock Expert. Can you help to this also?

Last edited by smarttrade; 30th June 2010 at 01:43 PM.
 The Following User Says Thank You to smarttrade For This Useful Post: nagarjuna13 (30th June 2010)
#7
30th June 2010, 01:18 PM
 Member Join Date: Jun 2010 Posts: 111 Thanks: 78 Thanked 39 Times in 27 Posts
Re: Help me to create Amibroker AFL use with my formula

One More Query :-

I am using this sto.Oscillator value in Metastock :

%K Parameters Time Periods:39,Slowing:3
%D Parameters Time Periods:3.

But there Using Exponential Method. How Should this Exponential Method add in Amibroker Code.
#8
30th June 2010, 11:33 PM
 Member Join Date: May 2010 Posts: 65 Thanks: 8 Thanked 62 Times in 33 Posts
Re: Help me to create Amibroker AFL use with my formula

Quote:
 Originally Posted by smarttrade One More Query :- I am using this sto.Oscillator value in Metastock : %K Parameters Time Periods:39,Slowing:3 %D Parameters Time Periods:3. But there Using Exponential Method. How Should this Exponential Method add in Amibroker Code.
are you looking out for this?

http://www.amibroker.com/guide/afl/afl_view.php?id=44

Thank you
nagarjuna
 The Following User Says Thank You to nagarjuna13 For This Useful Post: smarttrade (1st July 2010)
#9
30th June 2010, 11:34 PM
 Member Join Date: May 2010 Posts: 65 Thanks: 8 Thanked 62 Times in 33 Posts
Re: Help me to create Amibroker AFL use with my formula

Quote:
Thank you very much for taking time to explain this. I do not have live data flowing to my ami. So, I am not able to visualize this. I will work on this theoretically and let you know.

thank you
nagarjuna
 The Following User Says Thank You to nagarjuna13 For This Useful Post: smarttrade (1st July 2010)
#10
1st July 2010, 12:26 PM
 Member Join Date: Jun 2010 Posts: 111 Thanks: 78 Thanked 39 Times in 27 Posts
Re: Help me to create Amibroker AFL use with my formula

Quote:
 Originally Posted by nagarjuna13 are you looking out for this? http://www.amibroker.com/guide/afl/afl_view.php?id=44 Thank you nagarjuna

No Mr.Nagarjuna . I ask Method of use EMA in Sto.Osci. indicator.
Here I show example of Metastock Chart Option. Please see this Below Picture.
Here Method of moving average menu is available in Sto.Osci. Properties Window.
I am using 39,3,3 & Selected EMA Method.
How should add this EMA option in Amibroker Sto.Oscill ? .

I got this below Example AFL in Amibroker website. Here Using Sto.Osci. in EMA Method. Kindly see this .

************************************************** *
/*StochK/StochD Crossover for A single ticker.

Enters long on stochastic indicator when EMA StochD line crosses the EMA StochK
line. Exit on reversing signals only.

Sequence: To run optimisation remove // in front of lines with optimization
instructions (the 3 lines in the praragraph below) and place // in front of line
with specific STK, STD and pds per ticker (3 lines in 2nd paragraph below). Set
range, click apply to current stock and run optimisation.
Insert the optimized figures in ( STK=, STD= and pds=) statement of 2nd
paragraph below.
Once completed replace // in front of optimization instruction lines (1st
paragraph below), remove // in front of line with specific STK, STD and pds (2nd
paragraph below), save file and click on scan, explore or backtest. These
formulas can also be used as indicator.

Each optimisation requires 729 optimisation steps.*/

/*1st paragraph.*/
STK=Optimize ("StK" , 14, 2, 18, 2); //*Remove // before STK for optimization,
replace for scan, exploration & backtesting.
STD=Optimize ("StD" ,14, 2, 18, 2); //*Remove // before STD for optimization,
replace for scan, exploration & backtesting.
pds = Optimize("pds", 9,2,18,2); //*Remove // before pds for optimization,
replace for scan, exploration & backtesting.

/*2nd paragraph.*/

//STK= 14; //*Place // in front of STK before optimization, remove for scan,
exploration & backtesting.*//
//STD= 14; //*Place // in front of STD before optimization, remove for scan,
exploration & backtesting.*//
//pds= 14; //*Place // in front of pds before optimization, remove for scan,
exploration & backtesting.*//

STK=LastValue(STK);
STD=LastValue(STD);
pds = LastValue(pds);

Sell= Cross (EMA (StochD (STD),pds),EMA( StochK (STK),pds));
Buy= Cross (EMA(StochK (STK),pds),EMA( StochD (STD),pds));
Cover = Cross (EMA(StochK (STK),pds),EMA( StochD (STD),pds));
Short = Cross (EMA (StochD (STD),pds),EMA( StochK (STK),pds));

Filter=Buy OR Sell OR Short OR Cover;
Cover=ExRem(Cover,Short);
NumColumns = 2;
Column0 = EMA( StochK (STK),pds);
Column1 = EMA (StochD (STD),pds);

Graph0 = EMA( StochK (STK),pds);
Graph1 = EMA (StochD (STD),pds);
Graph2 = (EMA( StochK (STK),pds) - EMA (StochD (STD),pds))*2;
Graph2Style = 2;
Graph2Color =1;

Title=Name()+" " +"StD% Cross StK%" + " "
+"%K="+WriteVal(Graph0,FORMAT=1.1)+", %D="+
WriteVal(Graph1,FORMAT=1.1)+
WriteIf(Graph0>Graph1," LONG position"," ")+
WriteIf(Graph1>Graph0," SHORT position","")+"; "+ " Delta" + "
"+WriteVal((Graph2/2),FORMAT=1.1)+"%";
************************************************** *******

Can you help me to add this EMA Method ?

 Bookmarks

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are Off Refbacks are Off Forum Rules

All times are GMT +5.5. The time now is 05:50 AM.

Indemnity, Disclaimer & Disclosure Notice:
* By visiting Traderji.com you automatically indicate that you agree to our Forum Rules, Indemnity, Disclaimer & Disclosure Notice and General Content Disclaimer Notice and indemnify Traderji.com, its associates and related parties of all claims howsoever resulting from the usage of the forum/site.