My visual effect afl collection.

Re: The Non Repainting code

PHP:
COND1 = BUY_CONDITION;
COND2 = SELL_CONDITION;

COND1[BarCount-1]=Null;
COND2[BarCount-1]=Null;

Buy = Cross( COND1, COND2 );
Sell = Cross( COND2, COND1 );

Buy[BarCount-1]=Null;
Sell[BarCount-1]=Null;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
GraphXSpace = 5;
or at the end of the code:-

PHP:
Buy[BarCount-1]=Null;
Sell[BarCount-1]=Null;
Short[BarCount-1]=Null;
Cover[BarCount-1]=Null;
It is easier to use "ref" command, for me
 

revendar

Well-Known Member
I have a couple of questions:

1. Im looping on the bars in 15 minute candles and I want to get the datetime of that candle. I want to add some conditions to filter buy signal if time <09:45:00.
I kind of achieved this by below code. But I guess better way is there.
Code:
for ( i = lb+5;i < BarCount;i++ )
      {
	 noCandles = 1;
	 tc[i] = C[i];
	 time[i] =  LastValue(Ref(TimeNum(),-(BarCount-i-1)));
         .......
         .......
         mx[i] = H[i-1]*1.005;;
      }
2. I'm creating some arrays(mx) from 15Minute time frame as shown above. I'm then time compressing to 5minute and want to trade based on my 5min price crossing 15min array.

Code:
mx=TimeFrameCompress(mx,in5Minute);
      fc=TimeFrameCompress(C,in5Minute);
      b2 =  Cross(fc,mx);
      Buy = b1+b2;
Currently it buys (in 15min) after the new candle is created. But I want to do that as soon as price crosses that mx. So I'm trying to achieve that by going to lower time frame.

Thanks.
 
Last edited:
Hi Yasu222,

I'm new to AFL coding and I would like to make a system that identifies the candlestick patterns and set the buy n sell rules based on the patterns. I have scanned many of the websites and got the AFL that identifies the pattern, but I need it in a different manner. For ex. Lets say we have a Bullish Engulfing pattern formed i.e. this pattern involves two candles. All the current candlestick pattern indicators/ codes that I have found is, the Bullish engulfing pattern identified on the current candle, but I need as follows:

1. When the pattern is formed and two candles are involved, then I want to highlight the pattern say drawing a circle/ rectangle around the candles (in this case bullish engulfing involves two candles, so I want the rectangle to be around both the candles that forms the pattern.

2. Put an buy/ sell arrow near that pattern

3. Set the buy/ sell rules based on the pattern

Can we achieve my requirement using AFL? If yes, then please guide me.
 

yasu222

Active Member
Hull Moving Average

PHP:
_SECTION_BEGIN("Hull Moving Average");

Period = Param("Period",79,1,500,1);
Hull = WMA( 2*WMA(C,int(Period/2))- WMA(C,Period),int(sqrt(Period)));

for( i = 1 ; i < BarCount-2; i++ ) 
{
if (hull[i] <hull[i-1] && hull[i] <hull[i+1])
 Lpml[i]=1; 
else
Lpml[i] =0;

if (hull[i] >hull[i-1] && hull[i] >hull[i+1])
 Lpmh[i]=1;
else
Lpmh[i] =0;
}

GR =ExRem(LpmH,Lpmh);
RD =ExRem(Lpml,Lpml);

PlotShapes(IIf(GR!=0,shapeSmallCircle,shapeNone),colorRed,0,hull,0);
PlotShapes(IIf(RD!=0,shapeSmallCircle,shapeNone),colorBrightGreen,0,hull,0);
Plot(Hull,"Hull "+Period+" days",2,1);
_SECTION_END();
 

yasu222

Active Member
Deviation

PHP:
Lookback = Param("BackPds", 60, 30, 80, 1 );
Pds = Param("Periods", 14, 7, 21, 1 );

PerCent =95;
Osc=( ( C+2 * StDev( C,pds ) - WMA( C,pds ) ) / ( 4 * IIf(StDev( C,pds )==0,1,StDev(C,pds)) ) ) * 100;
b1=EMA(EMA(Osc,3),7);

Value1 = WMA(EMA(Osc,3),3);
Value2 = HHV(Value1,Lookback);
Value3 = LLV(Value1,Lookback);
Value4 = Value2 - Value3;
Value5 = Value4 * (PerCent / 100);
Value6 = Value3 + Value5;
Value7 = Value2 - Value5;
Plot(Value1,"Line",colorRed,1);
Plot(Value6,"Top",1,1);
Plot(Value7,"Bottom",1,1);
Plot(b1,"Signal" ,colorBlue,1);
 

mittens

Active Member
Re: Hull Moving Average

PHP:
_SECTION_BEGIN("Hull Moving Average");

Period = Param("Period",79,1,500,1);
Hull = WMA( 2*WMA(C,int(Period/2))- WMA(C,Period),int(sqrt(Period)));

for( i = 1 ; i < BarCount-2; i++ ) 
{
if (hull[i] <hull[i-1] && hull[i] <hull[i+1])
 Lpml[i]=1; 
else
Lpml[i] =0;

if (hull[i] >hull[i-1] && hull[i] >hull[i+1])
 Lpmh[i]=1;
else
Lpmh[i] =0;
}

GR =ExRem(LpmH,Lpmh);
RD =ExRem(Lpml,Lpml);

PlotShapes(IIf(GR!=0,shapeSmallCircle,shapeNone),colorRed,0,hull,0);
PlotShapes(IIf(RD!=0,shapeSmallCircle,shapeNone),colorBrightGreen,0,hull,0);
Plot(Hull,"Hull "+Period+" days",2,1);
_SECTION_END();

Hi Yasu,
This is good code.
Here we have a 79 period Hull average and we are looking for the turning points.

Also, you can achieve the same result without loop, using array which will be faster.
But as with every indicator, the signal is valid only after the close of current candle.

Also, HMA is a inbuilt function in Amibroker.
What do you think, simpler :)

_SECTION_BEGIN("Hull Moving Average");

Period = Param("Period",79,1,500,1);
Hull = HMA(Close, Period);

lpmh = Ref(hull,-1) > Ref(hull,-2) AND Ref(hull,-1) > hull;
lpml = Ref(hull,-1) < Ref(hull,-2) AND Ref(hull,-1) < hull;


GR =ExRem(LpmH,Lpmh);
RD =ExRem(Lpml,Lpml);

PlotShapes(IIf(GR!=0,shapeSmallCircle,shapeNone),colorRed,0,hull,0);
PlotShapes(IIf(RD!=0,shapeSmallCircle,shapeNone),colorBrightGreen,0,hull,0);
Plot(Hull,"Hull "+Period+" days",2,1);
_SECTION_END();

From amibroker help :
SYNTAX HMA( array, range )
RETURNS ARRAY
FUNCTION Implements Hull Moving Average. It is functionally equivalent to the following code:
function HMA_AFL( array, period )
{
fast = WMA( array, period / 2 );
slow = WMA( array, period );

return WMA( 2 * fast - slow, sqrt( period ) );
}
 

yasu222

Active Member
Metastock - Trailing Stoploss

PHP:
strata:=Input("Periods",1,50,10);
If(
C=PREV,
PREV,
If(
((Ref(C,-1)<PREV)AND (C<PREV)),
Min(PREV,C*(1+strata/100)),
If(
(Ref(C,-1)>PREV) AND (C>PREV),
Max(PREV,C*(1-strata/100)),
If(
C>PREV,
C*(1-strata/100),
C*(1+strata/100)))))
MRSI Indicator -

PHP:
A := Input("RSIPeriod",1,50,5);
B:= Input("MOVPeriod",1,200,9);
v1:= .1*(RSI(A)-50);
v2:= Mov(v1,B,W);
(Exp(2*v2)-1)/(Exp(2*v2)+1);
.5;
-.5;
0;
 
Last edited:

yasu222

Active Member
alert coding for 2% defference of gapup and gapdow when the market start.

PHP:
//-----------------------------------------------------------------------------------------------
//
//  Formula Name:    Percentage change exploration
//  Author/Uploader: Neotrade Analytics Pvt Ltd 
//  E-mail:          [email protected]
//  Website          www.neotradeanalytics.com/algobase.neotradeanalytics.com
//
//-------------------------Summary of AFL-------------------------------------------------------
//This AFL produces exploration results when stock opens more than +/- 2% 
//----------------------------------------------------------------------------------------------

_SECTION_BEGIN("Percentage change exploration");
Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
Pricediff = 0;

TimeFrameSet(inDaily);
//Get daily open
dailyOpen  = Open;
dailyhigh = High;
dailylow = Low;
//Get previous day close
prevclose = Ref(Close,-1);

Pricediff =  dailyOpen - prevclose;
//Calculate the percentage
Percentdiff = (Pricediff/prevclose) * 100;

tradingalert = IIf((Percentdiff>=2), 1, IIf((Percentdiff<=-2), 1,0) );

Filter = tradingalert;

AddColumn(prevclose, "prevclose",1.2); 
AddColumn(open, "close",1.2); 
AddColumn(Percentdiff, "Percentdiff",1.2); 

TimeFrameRestore();
_SECTION_END("");
 
Re: Sms from amibroker to mobile/desktop/laptop

Correct Code as follows -

_SECTION_BEGIN("PushBullet");

EnableScript("VBScript");

<%

Public Sub pushbullet(Message_Text)
Dim Message

'Your Message
Message = Message_Text

Dim objXmlHttpMain , URL

strJSONToSend = "{""type"": ""note"", ""title"": ""Alert"", ""body"":""" &Message_Text&"""}"

URL="https://api.pushbullet.com/v2/pushes"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
on error resume next
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing
set objResult = nothing

'Store response
'msgbox(objXmlHttpMain.responseText)
'response.Write (objXmlHttpMain.responseText)
alert("Hi")
End Sub

%>

pb = GetScriptObject();



if (LastValue(ValueWhen(Ref(Buy,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Buy Alert in " +Name() + " : BuyPrice Value is " + BuyPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "buyAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"buyAlertBar"))

StaticVarSet(Name()+GetChartID()+"buyAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"buyAlert",0); // new bar formed, and alerts can be trigered.



if (LastValue(ValueWhen(Ref(Sell,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"sellAlert")==0 )
{
pb.PushBullet("Sell Alert in " +Name() + " : SellPrice Value is " + SellPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "sellAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"sellAlertBar"))

StaticVarSet(Name()+GetChartID()+"sellAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"sellAlert",0); // new bar formed, and alerts can be trigered.

_SECTION_END();
I wants code for multiple pushbullet token , thanks
 
Hi guys,

Newbie here and I should say you guys are so helpful! I have tried some codes here and been successful in back testing. However, I noticed the behaviour in PSE and it seems the veterans are advanced in giving signals before it appears in our codes. And I was able to research that they are using the HAMMER TIME candle signal.

Here is their condition
1. Fibo plotting
2. 5 flucs/ticks within 38.2 or 61.8
3. When the tail touches 38.2 or 61.8, it signals HAMMER for a possible reversal
4. To be confirmed by RSI and STOCH indicator

I know this conditions best work in intraday and eod would be a day late. Both is highly appreciated :)

Hope to hear from you guys!

Salamat po!
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?