Help me to create Amibroker AFL use with my formula

#13
Smarttrade,

Can you please check the following?

_SECTION_BEGIN("Stochastic EMA %D");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( EMA(StochD( periods , Ksmooth, DSmooth ),3), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Stochastic EMA %K");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Plot( EMA(StochK( periods , Ksmooth),3), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

thank you
nagarjuna
 
#14
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?
Please check this

// Logic for uptrend or downtrend
uptrend= IIf( StochK(39,3) > StochD(39,3,3), 1, 0 );
downtrend=IIf( StochK(39,3)<StochD(39,3,3), 1, 0 );

// The current bar should be more than previous bar value + 5 points for buy in uptrend
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1) + 5));
// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L > ( Ref(L, -1) - 5));

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1));
SellSB= BarsSince(Ref(SellV,-1));

// Check the time interval between bars
TInterval = 15 ; // In minutes
TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0);

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB;
// We can signal sell only if previous signal was a buy.
Sell = SellV AND BuySB < SellSB ;
//Cover = Buy ;
//Short = Sell ;

_SECTION_BEGIN("Smart Trader");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

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

_SECTION_END();

thank you
nagarjuna
 
#15
Dear Nagarjuna,

Thankyou for your help. You Have Explained Step by Step very well. It Could help to Understand how its work. Now I modified this code with your Help. see this:

k = EMA(StochK(39,3),3);
d = EMA(StochD(39,3,3),3);

uptrend= IIf( k > d, 1, 0 );
downtrend=IIf( k < d, 1, 0 );

// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L > ( Ref(L, -1) - 5));
I think Above the line we should use Lessthan Symbol (<) Am I Correct?


Please check this
// Check the time interval between bars
TInterval = 15 ; // In minutes
TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0);
thank you
nagarjuna
Why we should use this time interval Line. I Applied this in AFL, But I couldnt find any Change. So I ask.


Dear Nagarjuna,
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.
I want to get Fresh Signal in Morning. Dont follow Yesterday's Signal.

Example :-

i) If Today Morning 9.15 Candle is Red and it also Break pre.Candle [Yesterday Last candle] Low - 5 Points (Assume Yesterday Trend was changed to Down @ 3.15-3.30 Candle[3.15 is green and 3.30 candle is red) then we dont get Sell Signal at Today's First Candle(10.15). Today 2nd Candle (10.30) also Break 10.15 Candle low - 5 Points Here only we get Sell Signal .

kindly help me to add this condition in AFL. Once again I Like to say Thankyou for Helping me.
:clapping: :clap: :thumb:
 
#16
Hi Smarttrade,

TInterval = 15 ; // In minutes
TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0);

The above condition is to check the time interval between current and previous candle to be less than 30 minutes. I assumed that if it is more than 30 minutes, then the previous candle data was got from previous day. So, we should ignore that.

thank you
nagarjuna
 
#17
Hi Smarttrade,

TInterval = 15 ; // In minutes
TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0);

The above condition is to check the time interval between current and previous candle to be less than 30 minutes. I assumed that if it is more than 30 minutes, then the previous candle data was got from previous day. So, we should ignore that.

thank you
nagarjuna
Dear Nagarjuna,

Thankyou for your Reply. Again I checked. But First Bar also showing Signal in some places .

Tinterval = 15 ; //Here We Assign the value
TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0); //Here we Check the time interval between bars
WHERE WE SHOULD USE THIS TimeFine ?
 
#18
I am an idiot. I did not use it in the final condition.

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB;
// We can signal sell only if previous signal was a buy.
Sell = SellV AND BuySB < SellSB ;

The above should be

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND TimeFine;
// We can signal sell only if previous signal was a buy.
Sell = SellV AND BuySB < SellSB AND TimeFine;
 
#19
:thanx: for your quick reply.

But didnt solve that problem. showing Signal in First Bar also. My Request, may we check Date instead of Minutes?

Sorry Nagarjuna, I think I am giving more Distrubance to you..
 
#20
I think I got the bug in the code.

Can you replace the following

TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2,1,0);

with

TimeFine = iif( timenum() - ref(timenum(),-1) < TInterval* 100 * 2 and timenum() - ref(timenum(),-1) > 0 ,1,0);

?

thank you
nagarjuna
 

Similar threads