Need help from Amibroker Afl experts

New Member Hello Friend's
the above image shows a good trade on price break out with pyramid entry ..i request all Amibroker Afl experts to please help coding this method with Entry,exits and adding lots too ..which may help small trader's like us ..

ford7k

Banned
Hi
The 1-2-3 high break or low break formula is a part of metastock formulae.

------------------------------------------------------------
http://freexbooks.blogspot.in/2010/05/metastock-formula-1-2-3-ross-hook.html
-------------------------------------------------------------------------
Col A: Peak(1,H,10)<=1.1*Peak(2,H,10)
AND Peak(1,H,10)>=0.9*Peak(2,H,10)
AND Trough(1,L,10)>=1.1*Trough(2,H,10)
AND Trough(1,L,10)<=0.9*Trough(2,H,10)
AND LLV(L,25)

Col B: Peak(1,H,5)<=1.1*Peak(2,H,5)
AND Peak(1,H,5)>=0.9*Peak(2,H,5)
AND Trough(1,L,5)>=1.1*Trough(2,H,5)
AND Trough(1,L,5)<=0.9*Trough(2,H,5)
AND LLV(L,25)

Col C: Peak(1,H,1)<=1.1*Peak(2,H,1)
AND Peak(1,H,1)>=0.9*Peak(2,H,1)
AND Trough(1,L,1)>=1.1*Trough(2,H,1)
AND Trough(1,L,1)<=0.9*Trough(2,H,1)
AND LLV(L,25)

Filter colA=1 OR colB=1 OR colC=1
---------------------------------------------------------------
please Convert this into afl and try.

Caution The ms code uses peak & trough functions and you must get valid pk&tr for trading needs.

here is a thing from wisestocktrader-but it is a bit different.
this can be modified to suit needs.
HTML:
``````ref link=http://www.wisestocktrader.com/indicators/48-1-2-3-long-setups-exploration.txt

// Connor/Cooper 1-2-3 setup (long) for 1-2-3-4 trade send to watchlist # 16
//  Coded by Patrick Hargus -- Mar, 2001, updated for parameters and other improvements to ver 4.7

w = Param("Empty Watchlist First?  Yes = 1, No = 2" ,  2,  1,  2,  1);
w1 = Param("Autofill Watchlist? Yes = 1, No = 2" , 1, 1,  2, 1);
x = Param ( "Add Results to an Existing Watchlist? Yes = 1, No = 2" , 2 , 1 , 2 , 1 ) ;   // select whether to add results to watchlist or not
y = Param("Set Watchlist Number", 16, 2, 60, 1);     // sets the watchlist number, but reserves the first 2 and last 4 watchlists
Clear = IIf(w ==1, x==2, 0); if( LastValue(Clear) ) {CategoryRemoveSymbol("", categoryWatchlist, y); }

//  --------  Parameter Variables for Exploration  --------------------------------
TCH = Param("High close value ", 150, 5, 300, 0.5);
TCL	= Param("Low close value " , 5, 1, 10, 0.25);
AVP = Param("Period for Avg Vol " , 21, 10, 240, 1);
SV = Param("Stock minimum Avg Vol " , 125000, 50000, 1000000, 5000);
My_Conditions = Close >= tcl AND Close <= tch AND MA( Volume, avp ) > sv ;

Setup = Param("********** Run As Check for 1-2-3 Setup (1) or Day 4 Entry (2)  ************ ",  1, 1, 2, 1);

AP = 14;  	// ADX Period
A = Param("Filter by ADX above " , 30, 0, 60, 1) ; 					// C & C said stock must have an ADX value > 30, the higher the better
CL = Param(" Close below yesterday's High? Yes = 1, No=2"  ,2,1,2,1);		//  This is an optional filter I have devised
CU = Param("Close above Open Required? Yes = 1, No = 2" , 2,1,2,1);		//  This is an optional filter I have devised
z1 = Param("PDI > MDI Required Yes = 1, No = 2", 1,1,2,1);				//  C & C said +DI must be > -DI

PH1 =  Param(" Short Highest High Period", 5,  2, 21, 1);  // short period to check for recent high
PH2 =  Param(" Long Highest High Period" , 21, 5, 65,1);  // long period to check for recent high
z2 = Param("Optional: HHV(H) of short period  > HHV(H) of prior long period required? Yes = 1, No =2", 2,1,2,1);  //  an optional filter I have devised

My_Other_Conditions =
AND IIf( CL==1, C <= Ref(H,-1), C=C)
AND IIf( CU==1, C>O,  C=C)
AND UT = IIf(z1==1, PDI()>MDI(), C=C)
AND HH = IIf(z2==1,    HHV(H,PH1) >= Ref(HHV(H,PH1),-PH2) , C=C)  // look for stocks whose highest high in last __ days >= that of prior __ days
;

//  *****  THE BASIC 1-2-3 setup to go long *********

Long123 =
(
// 3 lower lows
( Ref(L,-2)<Ref(L,-3) AND Ref(L,-1)<Ref(L,-2) AND L <Ref(L,-1) )  OR
// Inside, Low, Low
(  	( Ref(H,-2) <= Ref(H,-3)  AND  Ref(L,-2) ) <= Ref(L,-3)  AND Ref(L,-1)<Ref(L,-2) AND L < Ref(L,-1) )   OR
// Low, Inside, Low
( Ref(L,-2) < Ref(L,-3)  AND ( Ref(H,-1) <= Ref(H,-2) AND Ref(L,-1) <= Ref(L,-2) ) AND L < Ref(L,-1)  ) OR
// Low, Low, Inside
( Ref(L,-2)< Ref(L,-3) AND Ref(L,-1)< Ref(L,-2) AND (  H <= Ref(H,-1) AND L <= Ref(L,-1) ) )
)
;
//  Day-4 condition
TE = Param("Recommended entry, Trade above high by __" , 0.05 , 0.01, 0.75, 0.005);   // enter trade above prior day high  -- C & C said  .125, in pre decimal days; I find .05 works well now
Entry_Day4 =	C > Ref(H,-1) + TE 	;

Filter = IIf(setup == 1, (Long123 AND My_Other_Conditions AND My_Conditions) , ( Ref( Long123 ,-1) AND ( My_Other_Conditions AND My_Conditions AND Entry_Day4) ) );

autoFILL = IIf( w1==1, Filter,0 ) ;
Add = IIf( x==1, Filter , 0 ) ;
if( LastValue( Add OR autoFill ) )
{  CategoryAddSymbol( "", categoryWatchlist, y ); }

//  --------------  Organize the exploration results ------------------------------------

MAP = Param("For Output Info: Close above the SMA of " , 9, 1, 55) ;  // moving average period for stocks to close above, optional info I find useful
TD = Param("Rec Entry and Stop  based on Today (1), Yesterday (2) ", 1,   1, 2, 1);  //  C & C said entry should be .125 > the day 3 High -- this setting allows to check during day 4
RecEnt =  	IIf( TD==1, H+TE, Ref(H,-1) +TE);
PStop = 	IIf( TD==1, L, Ref(L,-1) );

AddTextColumn(IndustryID(1) ,"Industry Sector  ", 30.0, colorBlue, colorYellow);

AddColumn(PStop, "Proctective Stop ~ ", 2.2, colorWhite, colorPlum);
AddColumn(IIf(TD ==1, HHV(H,3), Ref(HHV(H,3),-1) ) , "BO > HHV(H, 3)", 2.2, colorYellow, colorBlue);

AddColumn(V, "Today's Volume   ", 8.0, colorWhite,colorGreen  );
AddColumn((V/Ref(MA(V,21),-1)*100),"% Of Avg Vol", 2.2,colorGreen, colorGold );
AddColumn(Ref(MA(V,21),-1), "21 D AVG VOL",1.0, colorWhite, colorDarkGrey);

AddColumn( H-L, "Today's Range", 2.2, colorWhite, colorBlue);

AddTextColumn(Name(), "NAME", 5.0, colorYellow, colorBlue );``````

Last edited:

ford7k

Banned
hi
here is another from mt4 ,metatrader

HTML:
``````//+------------------------------------------------------------------+
//|                Hans Breakout.mq4                                 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue

extern int       Breakout_Pips=5;
extern int       Exit_Hour = 23;
extern int       From_Hour_1 = 6;
extern int       From_Minute_1 = 0;
extern int       To_Hour_1   = 9;
extern int       To_Minute_1 = 59;
extern int       From_Hour_2 = 10;
extern int       From_Minute_2 = 0;
extern int       To_Hour_2   = 13;
extern int       To_Minute_2 = 59;
extern int Bars_Count= 10000;

//---- buffers
double v1[];
double v2[];
double v3[];
double v4[];

int init()
{

IndicatorBuffers(4);

SetIndexArrow(0, 159);
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,Red);
SetIndexDrawBegin(0,-1);
SetIndexBuffer(0, v1);
SetIndexLabel(0,"High1");

SetIndexArrow(1, 159);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetIndexDrawBegin(1,-1);
SetIndexBuffer(1, v2);
SetIndexLabel(1,"Low1");

SetIndexArrow(2, 159);
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1,Red);
SetIndexDrawBegin(2,-1);
SetIndexBuffer(2, v3);
SetIndexLabel(2,"High2");

SetIndexArrow(3, 159);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetIndexDrawBegin(3,-1);
SetIndexBuffer(3, v4);
SetIndexLabel(3,"Low2");

watermark();

return(0);
}

int start()
{
int i;
int shift;
double price;
datetime calculated1, calculated2;
double pipsBreakout = Breakout_Pips * Point;
i = Bars_Count;
while(i>=0)
{
// High/Low 1
datetime today = StripTime(Time[i]);
int nowMins = TimeHour(Time[i]) * 60 + TimeMinute(Time[i]);
if (calculated1 < today && nowMins > (To_Hour_1 * 60) + To_Minute_1)
{
calculated1 = today;
double highest1 = High[GetHighest(Symbol(), Period(), MODE_HIGH, Time[i], From_Hour_1, From_Minute_1, To_Hour_1, To_Minute_1)];
double lowest1 = Low[GetLowest(Symbol(), Period(), MODE_LOW, Time[i], From_Hour_1, From_Minute_1, To_Hour_1, To_Minute_1)];
}
if (calculated1 == today && nowMins < Exit_Hour * 60)
{
v1[i] = highest1 + pipsBreakout;
v2[i] = lowest1 - pipsBreakout;
}

// High/Low 2
if (calculated2 < today && nowMins > (To_Hour_2 * 60) + To_Minute_2)
{
calculated2 = today;
double highest2 = High[GetHighest(Symbol(), Period(), MODE_HIGH, Time[i], From_Hour_2, From_Minute_2, To_Hour_2, To_Minute_2)];
double lowest2 = Low[GetLowest(Symbol(), Period(), MODE_LOW, Time[i], From_Hour_2, From_Minute_2, To_Hour_2, To_Minute_2)];
}
if (calculated2 == today && nowMins < Exit_Hour * 60)
{
v3[i] = highest2 + pipsBreakout;
v4[i] = lowest2 - pipsBreakout;
}

i--;
}
return(0);
}

//+------------------------------------------------------------------+

datetime StripTime(datetime dt)
{
return (dt - (TimeHour(dt)*3600) - (TimeMinute(dt)*60) - TimeSeconds(dt));
}

//+------------------------------------------------------------------+
//| Get highest/lowest bar between a time period.                    |
//+------------------------------------------------------------------+
int GetHighest(string symbol, int timeframe, int price_mode, datetime date, int from_hour, int from_minute, int to_hour, int to_minute)
{
date = StripTime(date);
datetime from_time = date + (from_hour * 3600) + (from_minute * 60);
datetime to_time = date + (to_hour * 3600) + (to_minute * 60);
int from_bar = iBarShift(symbol, timeframe, from_time, false);
int to_bar = iBarShift(symbol, timeframe, to_time, false);
int hh = Highest(symbol, timeframe, price_mode, from_bar - to_bar + 1, to_bar);
return(hh);
}

int GetLowest(string symbol, int timeframe, int price_mode, datetime date, int from_hour, int from_minute, int to_hour, int to_minute)
{
date = StripTime(date);
datetime from_time = date + (from_hour * 3600) + (from_minute * 60);
datetime to_time = date + (to_hour * 3600) + (to_minute * 60);
int from_bar = iBarShift(symbol, timeframe, from_time, false);
int to_bar = iBarShift(symbol, timeframe, to_time, false);
int ll = Lowest(symbol, timeframe, price_mode, from_bar - to_bar + 1, to_bar);
return(ll);
}

void watermark()
{
ObjectCreate("fxfisherman", OBJ_LABEL, 0, 0, 0);
ObjectSetText("fxfisherman", "fxfisherman.com", 11, "Lucida Handwriting", RoyalBlue);
ObjectSet("fxfisherman", OBJPROP_CORNER, 2);
ObjectSet("fxfisherman", OBJPROP_XDISTANCE, 5);
ObjectSet("fxfisherman", OBJPROP_YDISTANCE, 10);
return(0);
}`````` HTML:
``````This is the first indicator for Hans Simple Combined Breakout System ever coded. It features configurable sessions, breakout pips, and exit time.

This indicator is a must have if you want to follow Hans Breakout System. It gives all the visuals you ever needed.

Buy when price crosses up red dot (resistance). There can be two trades in a single day, because there're two string of red dots.
Sell when price crosses down blue dot (support).
Set stop loss 50 pips away (EURUSD) or 70 pips (GBPUSD). If the other end of breakout is closer, then set SL to the breakout.
Close all orders and trades when the dots end.``````

ford7k

Banned
hi

here is an afl
but you need to tweak it before using
WARNING
CANT TEST?NO TIME?NO ENERGY?TOO BUSY?
THEN DONT USE!!!!!!!!!!!!!
NOBODY TOLD YOU HOW TO TEST THOUGH YOU ARE READY?
1 DO 30 TESTS IN FUTURE ZONE JUST USING RULES YOU FORM.
2 FINE TUNE RULES AND TEST 100 TIMES TO GET CONFIDENCE-CONFIRMATION
IF THINGS ARE BELOW 60% SUCCESS-JUST LEAVE IT \$ GO ELSEWHERE!!!

HTML:
``````// 123 pattern
// mod from Patterns Wave.afl
// by reinsley

SetChartOptions( 0, chartShowArrows | chartShowDates );

_SECTION_BEGIN( "Zig Hi Lo" );
// ZIG hilo version by Joris Schuller
// from ZigZag Hi Lo.afl : simplified version
plt = ParamToggle( "Plot ZigHL ", "Off|On", 1 );
change = Param( "ZigZag-HL %", 0.22, 0.01, 3, 0.01 );
za2 = 0;

if ( plt == 1 )
{
Title = EncodeColor( 4 ) + _DEFAULT_NAME( ) + "; " + EncodeColor( 1
) + StrFormat( "{{NAME}} - {{INTERVAL}} ; {{DATE}}; \nO=%g, \nH=%g,
\nL=%g, \nC=%g (%.1f%%){{VALUES} }", O, H, L, C, SelectedValue( ROC( C, 1
) ) );
pk = PeakBars( H, change ) == 0;
tr = TroughBars( L, change ) == 0;
pkbars = PeakBars( H, change );
trbars = TroughBars( L, change );
zHi = Zig( H, change );
zLo = Zig( L, change );
HLAvg = ( zHi + zLo ) / 2;
zp2 = IIf( pk, zHi, IIf( tr, zLo, IIf( pkbars <= trbars, L, H ) )
);//Modified zp to reduce occasional erroneous Pk/Tr connections at very  small ZigPerc values
za2 = Zig( zp2, change );
Plot( za2, "\nZig Modified", 11, 5 | styleNoLabel );//Zig H-L Modified
}

_SECTION_END( );

// 123 Pattern
// shapedigit display

_SECTION_BEGIN( "123 Pattern" );

procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorWhite, 0, y,
shift );
}

bi = BarIndex();
sbi = SelectedValue( bi );
upshift = Param( "upshift ", 30, 1, 100, 1 );

if ( SelectedValue( PeakBars( za2 , Change ) < TroughBars( za2 , Change
) ) )
{
pt1 = PeakBars( za2 , Change, 1 ) == 0 ;
pt2 = TroughBars( za2 , Change, 1 ) == 0 ;
pt3 = PeakBars( za2 , Change, 1 ) == 0 ;

ydigit1 = H;
ydigit2 = L;
ydigit3 = H;
}
else
{
pt1 = TroughBars( za2 , change, 1 ) == 0 ;
pt2 = PeakBars( za2 , change, 1 ) == 0 ;
pt3 = TroughBars( za2 , change, 1 ) == 0 ;

ydigit1 = L;
ydigit2 = H;
ydigit3 = L;
upshift = -upshift;
}

bpt1 = SelectedValue( ValueWhen( pt1, bi, 2 ) ); // x axis

bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt3, bi ) );

pltdigit = ParamToggle( "Plot 123 Digit ", "Off|On", 1 );

if ( pltdigit == 1 )
{
PlotShapeAt( bpt1, ydigit1 , shapeDigit1, upshift );
PlotShapeAt( bpt2, ydigit2 , shapeDigit2, -upshift );
PlotShapeAt( bpt3, ydigit3 , shapeDigit3, upshift );
}

_SECTION_END( );
Plot( C, "", colorWhite, styleThick + styleCandle );

_SECTION_BEGIN( "Xspace" );
xspace = Param( "GraphXSpace ", 10, 1, 20, 1 );
GraphXSpace = xspace;
_SECTION_END( );``````

New Member
Hello ford,
thanks for your replay :thumb: but i need afl for amibroker as i am not at all good i formula writing so please help me jamit_05

Well-Known Member
Hi Ford...

I have a very simple request.

The following is the code for a version of turtle trading system. I wish to have it Analysed in Amibroker. For that I need code to set the exits.

I want Profit Exit to be at 700 points flat and
Stop Loss to be the Low of the day which triggered the Buy signal. (After Stop Hit, a fresh Buy signal can be generated)

Hh = Ref(HHV(H,10),-1);
Ll = Ref(LLV(L,10),-1);

Plot(Hh, "HH", colorBlue, styleThick);
Plot(Ll, "LL", colorRed, styleThick);

Short = Cross(Ll,C);

PlotShapes(shapeDownArrow*Short,colorRed);

SetPositionSize(1,4);

Happy_Singh

Happy
Hi Ford...

I have a very simple request.

The following is the code for a version of turtle trading system. I wish to have it Analysed in Amibroker. For that I need code to set the exits.

I want Profit Exit to be at 700 points flat and
Stop Loss to be the Low of the day which triggered the Buy signal. (After Stop Hit, a fresh Buy signal can be generated)
Let me try . . .

Code:
``````Sell  = Short OR C < Ref(L,-BarsSince(Buy))   OR H > Ref(C,-BarsSince(Buy));
Also use exrem in your code to suppress extra signals in the same direction Happy

guptak03

Well-Known Member Hello Friend's
the above image shows a good trade on price break out with pyramid entry ..i request all Amibroker Afl experts to please help coding this method with Entry,exits and adding lots too ..which may help small trader's like us ..

I am also waiting  mastermind007

Well-Known Member
Hi Ford...

I have a very simple request.

The following is the code for a version of turtle trading system. I wish to have it Analysed in Amibroker. For that I need code to set the exits.

I want Profit Exit to be at 700 points flat and
Stop Loss to be the Low of the day which triggered the Buy signal. (After Stop Hit, a fresh Buy signal can be generated)
IMHO, this isn't Turtle Trading System. Either you've been misinformed or spoof'd.

Now that we've moved past the "Ground Zero", can you name a scrip in NSE market that will continue in up-move after it has broken a high that was set 10 bars ago (2 week's High)?

Therefore, sorry to say, but this AFL would be more appropriately named as "Stop Loss Targeting System" (or SLTS). Then, as ford7k suggested somewhere, we can use money from his honey to get Priyanka Chopra (or even more glam babe) to recommend it to housewives at 25k a pop. That has better chance of making some money.

New Member
watinggggggggggggg :sos::console: