indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Tools > Software > Amibroker

Dhavin
Reply
 
Bookmark and Share LinkBack (3) Thread Tools Display Modes
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 25-06-2010, 01:35 PM
smarttrade smarttrade is offline
Regular
 
Join Date: Jun 2010
Posts: 97
Thanks: 119
Thanked 94 Times in 45 Posts
smarttrade will become famous soon enoughsmarttrade will become famous soon enough
Default 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));
Buy = Cross(uptrend,downtrend);
PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 25-06-2010, 01:47 PM
Prashanth Prashanth is offline
Regular
 
Join Date: Mar 2009
Posts: 35
Thanks: 2
Thanked 109 Times in 32 Posts
Prashanth will become famous soon enoughPrashanth will become famous soon enough
Default

Something like this?

// Simple Stoch System

uptrend= (StochK(39,3)>StochD(39,1,3));
downtrend=(StochK(39,3)<StochD(39,1,3));
Cond1 = Cross(uptrend,downtrend);
Cond2 = Cross(downtrend,uptrend);

AA = ValueWhen(Cond1=1, H);
AB = ValueWhen(Cond2=1, L);

AC = Ref(AA,-1) + 5;
AD = Ref(AB,-1) - 5;

Buy = Cond1 AND Cross(C,AC);
Sell = Cond2 AND Cross(C,AD);

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

Plot(C,"Close", colorBlack, styleCandle);
PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 5 Users Say Thank You to Prashanth For This Useful Post:
  #3 (permalink)  
Old 25-06-2010, 06:43 PM
smarttrade smarttrade is offline
Regular
 
Join Date: Jun 2010
Posts: 97
Thanks: 119
Thanked 94 Times in 45 Posts
smarttrade will become famous soon enoughsmarttrade will become famous soon enough
Default

Originally Posted by Prashanth View Post
Something like this?

// Simple Stoch System

uptrend= (StochK(39,3)>StochD(39,1,3));
downtrend=(StochK(39,3)<StochD(39,1,3));
Cond1 = Cross(uptrend,downtrend);
Cond2 = Cross(downtrend,uptrend);

AA = ValueWhen(Cond1=1, H);
AB = ValueWhen(Cond2=1, L);

AC = Ref(AA,-1) + 5;
AD = Ref(AB,-1) - 5;

Buy = Cond1 AND Cross(C,AC);
Sell = Cond2 AND Cross(C,AD);

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

Plot(C,"Close", colorBlack, styleCandle);
PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);

Dear Prasanth Sir,
Thank you for Your Reply. I added your Code in AFL. But Its showing More Wrong Signal. Here I attached AFL Code and Chart. Kindly Help me Where i do mistake?


AFL Code :-

_SECTION_BEGIN("Trail");
Title = EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorWhite) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V);
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C) + "\n" + "\n" ;

uptrend= (StochK(39,3)>StochD(39,3,3));
downtrend=(StochK(39,3)<StochD(39,3,3));
Cond1 = Cross(uptrend,downtrend);
Cond2 = Cross(downtrend,uptrend);

AA = ValueWhen(Cond1=1, H);
AB = ValueWhen(Cond2=1, L);

AC = Ref(AA,-1) + 5;
AD = Ref(AB,-1) - 5;

Buy = Cond1 AND Cross(C,AC);
Sell = Cond2 AND Cross(C,AD);

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

PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);

Plot( 2, /* defines the height of the ribbon in percent of pane width*/ "ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();


_SECTION_BEGIN("Chart");
Vcolor=IIf(uptrend, colorGreen, IIf( downtrend, colorRed, 0 ));
GraphXSpace = 5;
PlotOHLC( Open, High, Low, Close, "", vcolor, styleCandle | styleThick );
_SECTION_END();

Nifty Chart :-




Kindly Help Me...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 26-06-2010, 12:07 AM
Prashanth Prashanth is offline
Regular
 
Join Date: Mar 2009
Posts: 35
Thanks: 2
Thanked 109 Times in 32 Posts
Prashanth will become famous soon enoughPrashanth will become famous soon enough
Default

Sorry! Shall get back
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to Prashanth For This Useful Post:
  #5 (permalink)  
Old 26-06-2010, 03:31 AM
vidyasagar vidyasagar is offline
Regular
 
Join Date: Jun 2009
Location: Vijayawada (Andhra Pradesh)
Posts: 28
Thanks: 136
Thanked 70 Times in 24 Posts
vidyasagar is on a distinguished roadvidyasagar is on a distinguished road
Default

smarttrade

Try this code

SetChartOptions(0,chartShowDates|chartShowArrows|c hartLogarithmic|chartWrapTitle);
GraphXSpace = 5;
Plot(C,"",colorBlack,styleCandle);
x = Ref(H,-1);
Y = Ref(L,-1);
a=x+5;
b=y-5;
aa=StochK(39,3);
bb=StochD(39,3,3);
Buy = Cover = C>a AND aa>bb;
Sell = Short = C<b AND aa<bb;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBl ue,0,L,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);

vidyasagar
Attached Files
File Type: afl Smarttrade trading system.afl (462 Bytes, 326 views)

Last edited by vidyasagar; 26-06-2010 at 03:38 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 4 Users Say Thank You to vidyasagar For This Useful Post:
  #6 (permalink)  
Old 27-06-2010, 01:24 AM
tradingideas tradingideas is offline
Regular
 
Join Date: Oct 2009
Posts: 35
Thanks: 2
Thanked 57 Times in 23 Posts
tradingideas is on a distinguished road
Default

I have a similar code solution:

threshold = 5;
uptrend = StochK(39,3) > StochD(39,3,3);
downtrend =StochK(39,3) < StochD(39,3,3);

Buy = uptrend AND H >= Ref(H,-1) + threshold; BuyPrice = Max(O,Ref(H,-1) + threshold);
Sell = downtrend AND L <= Ref(L,-1) - threshold; SellPrice = Min(O,Ref(L,-1) - threshold);

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

SetChartOptions(0, chartShowDates);
Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGr een,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),c olorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNon e),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone ),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNo ne),colorWhite,0,SellPrice,0);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to tradingideas For This Useful Post:
  #7 (permalink)  
Old 27-06-2010, 10:31 PM
smarttrade smarttrade is offline
Regular
 
Join Date: Jun 2010
Posts: 97
Thanks: 119
Thanked 94 Times in 45 Posts
smarttrade will become famous soon enoughsmarttrade will become famous soon enough
Thumbs up

Originally Posted by vidyasagar View Post
smarttrade

Try this code

SetChartOptions(0,chartShowDates|chartShowArrows|c hartLogarithmic|chartWrapTitle);
GraphXSpace = 5;
Plot(C,"",colorBlack,styleCandle);
x = Ref(H,-1);
Y = Ref(L,-1);
a=x+5;
b=y-5;
aa=StochK(39,3);
bb=StochD(39,3,3);
Buy = Cover = C>a AND aa>bb;
Sell = Short = C<b AND aa<bb;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBl ue,0,L,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);

vidyasagar




Dear Vidyasagar,
Thankyou for yours Code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 27-06-2010, 11:24 PM
smarttrade smarttrade is offline
Regular
 
Join Date: Jun 2010
Posts: 97
Thanks: 119
Thanked 94 Times in 45 Posts
smarttrade will become famous soon enoughsmarttrade will become famous soon enough
Thumbs up

Originally Posted by tradingideas View Post
I have a similar code solution:

threshold = 5;
uptrend = StochK(39,3) > StochD(39,3,3);
downtrend =StochK(39,3) < StochD(39,3,3);

Buy = uptrend AND H >= Ref(H,-1) + threshold; BuyPrice = Max(O,Ref(H,-1) + threshold);
Sell = downtrend AND L <= Ref(L,-1) - threshold; SellPrice = Min(O,Ref(L,-1) - threshold);

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

SetChartOptions(0, chartShowDates);
Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGr een,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),c olorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNon e),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone ),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNo ne),colorWhite,0,SellPrice,0);

Dear Tradingideas,

Thank you for yours Help. I was Expecting this. I applied this Code. Some Places shows Correct Signal and Some Places Show Buy and Sell Arrow in First Candle. we want Buy and Sell Arrow when Breakout pre.High + 5 AND it should be in Up Trend for Buy or Breakout Pre.Low - 5 AND it should be in Down Trend for Sell.

Here doing Correctly Breakout Compare with 1st Candle High + 5 Point its showing Buy Signal, But someplaces it take Last downtrend (Red Candle) Pre.Candel High + 5 for Breakout. Thats why here Showing Buy Signal in First Candle . (same Problem in Sell Signal Also).

Here I attached Nifty Chart for Example.





In this above chart I market wrong signal in white arrow mark. Kindly Help Me to correct this problem.

I used this AFL Code :-

_SECTION_BEGIN("Unnamed 1");
Title = EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorWhite) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V);
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C) + "\n" + "\n" ;
threshold = 5;
uptrend = StochK(39,3) > StochD(39,3,3);
downtrend =StochK(39,3) < StochD(39,3,3);

Buy = uptrend AND H >= Ref(H,-1) + threshold; BuyPrice = Max(O,Ref(H,-1) + threshold);
Sell = downtrend AND L <= Ref(L,-1) - threshold; SellPrice = Min(O,Ref(L,-1) - threshold);

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

SetChartOptions(0, chartShowDates);
//Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGr een,0,L,-15);
//PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),c olorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNon e),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);
//PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone ),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNo ne),colorWhite,0,SellPrice,0);


MYcolor = IIf( uptrend, colorBrightGreen, IIf(downtrend , colorRed, colorBlue));
PlotOHLC( Open, High, Low, Close, "", Mycolor, styleCandle );
_SECTION_END();

I have some Doubts in AMIBROKER:-

1. I am using Metastock Datas in Amibroker. 5 min and 10 min Charts are showing correctly. But 15 min Charts are Showing wrongly. First Candel Time is Showing 9.10 and 2nd Candle Time is 9.25,3rd is showing 9.40,..9.55..,10.10. Here Should show Time From Ist Candle = 9.15,..9.30..,9.45..,10..,10.15.

2. I want Show Full Candel color Green(fillup the candle Body Color) in Uptrend and Full Color Red in Downtrend for my Condition (see the above chart and AFL).


Kindly help me to solve this Problems..
(Really thanks to Mr.Prashanth, Mr.Vidyasagar and mr.Tradingideas)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to smarttrade For This Useful Post:
  #9 (permalink)  
Old 28-06-2010, 01:26 AM
vidyasagar vidyasagar is offline
Regular
 
Join Date: Jun 2009
Location: Vijayawada (Andhra Pradesh)
Posts: 28
Thanks: 136
Thanked 70 Times in 24 Posts
vidyasagar is on a distinguished roadvidyasagar is on a distinguished road
Default

smarttrade

See the following AFL for color bars

vidyasagar
Attached Files
File Type: afl Smarttrade trading system 1.afl (1.1 KB, 244 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to vidyasagar For This Useful Post:
  #10 (permalink)  
Old 28-06-2010, 02:17 PM
tradingideas tradingideas is offline
Regular
 
Join Date: Oct 2009
Posts: 35
Thanks: 2
Thanked 57 Times in 23 Posts
tradingideas is on a distinguished road
Default

hi,

I think I know what you mean. Indeed the definition of the uptrend and downtrend is based on the close price of the bar. So actually you will need:

uptrend = Ref(StochK(39,3) > StochD(39,3,3),-1);
downtrend = Ref(StochK(39,3) < StochD(39,3,3),-1);

code will then become:

threshold = 5;
uptrend = Ref(StochK(39,3) > StochD(39,3,3),-1);
downtrend = Ref(StochK(39,3) < StochD(39,3,3),-1);
"uptrend: " + WriteVal(uptrend);
"downtrend: "+ WriteVal(downtrend);

Buy = uptrend AND H >= Ref(H,-1) + threshold; BuyPrice = Max(O,Ref(H,-1) + threshold);
Sell = downtrend AND L <= Ref(L,-1) - threshold; SellPrice = Min(O,Ref(L,-1) - threshold);

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

SetChartOptions(0, chartShowDates);
Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGr een,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),c olorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNon e),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone ),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNo ne),colorWhite,0,SellPrice,0);

let me know if this is what you meant
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to tradingideas For This Useful Post:
Reply

indiTraders - Forum for the Active Indian Trader > Tools > Software > Amibroker


Thread Tools
Display Modes

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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.inditraders.com/amibroker/3434-help-me-create-amibroker-afl-use-my-formula.html
Posted By For Type Date
Help Me To Create Amibroker AFL Use With My Formula - IndiTraders ... : Amibroker Afl Images, Pics, Photos, Wallpapers, Photogallery - 1544524936491 This thread Refback 14-01-2012 11:01 PM
Help Me To Create Amibroker AFL Use With My Formula - IndiTraders ... : Amibroker Afl Images, Pics, Photos, Wallpapers, Photogallery - 1544524936491 This thread Refback 03-01-2012 11:22 PM
Help Me To Create Amibroker AFL Use With My Formula - IndiTraders ... : Amibroker Afl Images, Pics, Photos, Wallpapers, Photogallery - 1014380761024 This thread Refback 26-07-2011 10:34 AM

Dhavin

All times are GMT +5.5. The time now is 05:30 PM.


iT
vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2