Simple Coding Help - No Promise.

toughard

Well-Known Member
thanks

it is plotting yellow lines but not exact at high and low of yesterday (previous trading day )

oh phew... i am using the same code and getting it right!!! can you show your chart which you clime it giving wrong plots.. it will help me in rectifying
 

toughard

Well-Known Member
Tried this... ummmmm but no use... can some one kindly stitch it for me...

Q = Param( "% Change", 0.05, 0.01, 10, 0.01 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );
rightfig = Param( "rightfig ", 7, 1, 10, 1 );
xspace = Param( "GraphXSpace ", 10, 1, 20, 1 );


for ( i = 0; i < BarCount; i++ )
{

if ( HH )
p = StrRight( NumToStr( HH, 4.1 ), rightfig );
PlotText( "HH"+p ,i, HH[ i ] + dist, colorRed );


if ( LH )
PlotText( "LH", i, H[ i ] + dist, colorRed );

if ( HL )
PlotText( "HL", i, L[ i ] - dist, colorBrightGreen );

if ( LL )
PlotText( "LL", i, L[ i ] - dist, colorBrightGreen );
}



Happy ji, KH, Amit and others can you look in to this...

all i was seeking the convenience of price getting plotted next to those HH HL, now I got curious to know how it can be done as I tried all my options...
 

amitrandive

Well-Known Member
Happy ji, KH, Amit and others can you look in to this...

all i was seeking the convenience of price getting plotted next to those HH HL, now I got curious to know how it can be done as I tried all my options...
This should work.

Code:
_SECTION_BEGIN("Price");
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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 


tchoice=Param("Title Selection ",2,1,2,1);

Q=Param("% Change",0.2,0.1,10,0.1);
Z= Zig(C ,q ) ;
HH=((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(z,q,1 ) >Peak(Z,q,2)));LH=((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(Z,q,1 ) <Peak(Z,q,2)));
HL=((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) >Trough(Z,q,2)));
LL=((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) <Trough(Z,q,2)));
GraphXSpace = 5;
dist = 0.5*ATR(20); 

for( i = 0; i < BarCount; i++ ) 
{ 
if( HH[i] ) PlotText( "HH  \n"+H[i], i, H[ i ]+dist[i], colorGreen );
if( LH[i] ) PlotText( "LH \n"+H[i], i, H[ i ]+dist[i], colorRed ); 
if( HL[i] ) PlotText( "HL \n"+L[i], i, L[ i ]-dist[i], colorGreen );
if( LL[i] ) PlotText( "LL  \n"+L[i], i, L[ i ]-dist[i], colorRed );

}
 

toughard

Well-Known Member
This should work.

Code:
_SECTION_BEGIN("Price");
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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 


tchoice=Param("Title Selection ",2,1,2,1);

Q=Param("% Change",0.2,0.1,10,0.1);
Z= Zig(C ,q ) ;
HH=((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(z,q,1 ) >Peak(Z,q,2)));LH=((Z<Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2)) AND (Peak(Z,q,1 ) <Peak(Z,q,2)));
HL=((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) >Trough(Z,q,2)));
LL=((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) <Trough(Z,q,2)));
GraphXSpace = 5;
dist = 0.5*ATR(20); 

for( i = 0; i < BarCount; i++ ) 
{ 
if( HH[i] ) PlotText( "HH  \n"+H[i], i, H[ i ]+dist[i], colorGreen );
if( LH[i] ) PlotText( "LH \n"+H[i], i, H[ i ]+dist[i], colorRed ); 
if( HL[i] ) PlotText( "HL \n"+L[i], i, L[ i ]-dist[i], colorGreen );
if( LL[i] ) PlotText( "LL  \n"+L[i], i, L[ i ]-dist[i], colorRed );

}

Amit thanks a ton!! I been waiting for this help!! thanks again!!

All the best...
 

toughard

Well-Known Member
See If you can take some clue from this AFL.

Leonid Thanks for you too, just to inform you that amit helped me with his work like above! thanks for being their to help me!
 
Respected All Seniors,Members & Expert's
Above afl is TURTLE SYSTEM,
in this afl i want Buy sell signal's whitout CHANDELIAR EXIT, I DONT WATNT TRALING STOPLOSS and remove extra buy sell signals.

Sir is it possible ?

Warm Regards
Chinmay


/*
Formula Name: Turtle trading system
Collector/Uploader: www.stockbangladesh.com
E-mail: [email protected]
Origin: Turtle trading experimemnt Chandelier exit based on Chuck Lebeau's work
Keywords: Trend trading
Level: Basic
Flags: System
*/
//=============================SETUP================ ======================

pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );

DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last 20 periods
DonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20 periods
DonchianMiddle = ( DonchianUpper + DonchianLower ) / 2;

UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 );
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 );
Color = IIf( UpTrend, colorBlue, IIf( DnTrend, colorOrange, colorCustom11 ) );

// Plots a 20 period Donchian channel
Plot( C, "Price", Color, styleCandle | styleThick );
Plot( DonchianUpper, "Donchian U", ParamColor( "DU Color", colorBlue ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianMiddle, "Donchian M", ParamColor( "DM Color", colorBrightGreen ), ParamStyle( "DM Style", styleNoLine ) );
Plot( DonchianLower, "Donchian L", ParamColor( "DL Color", colorRed ), ParamStyle( "DL Style", styleLine ) );

Title = WriteVal( DonchianUpper, 1.2 ) + WriteVal( DonchianLower, 1.2 ) + WriteVal( DonchianMiddle, 1.2 );
//=============================TRIGGERS AND ENTRIES=======================
Buy = High > Ref( HHV( High, 20 ), -1 ) AND MAFAST > MASLOW; // Enters long trade

Short = Low < Ref( LLV( Low, 20 ), -1 ) AND MAFAST < MASLOW; // Enters short trade



//=============================EXITS================ ======================
_SECTION_BEGIN( "Chandelier Exit" );

SetBarsRequired( 50, 50 );

Multiple = Param( "Multiple", 3, 0.5, 10, 0.1 ); // How many ATR's to be allowed below the highest high since latest "buy" bar
ATRPeriods = Param( "ATR Periods", 20, 1, 50, 1 ); // How many periods to use for the ATR

stopArray = Null;
atrArray = ATR( ATRPeriods );
HHArray = Null;
LLArray = Null;
exitArray = Null;
trendDirection = 0;

for ( i = 0; i < BarCount; i++ )
{
if ( Short )
{
// we just triggered a short trade. Set up starting values
stopArray = Low + ( Multiple * atrArray );
LLArray = Low; // initialize the lowest low array
trendDirection = 0 - 1; // going short. Base bar.
}

if ( Buy )
{
// we just triggered a long trade. Set up starting values
stopArray = High - ( Multiple * atrArray );
HHArray = High; // initialize the highest high array
trendDirection = 1; // going long. Base bar flag is now set.
}

exitArray = 0;

if ( trendDirection > 0 )
{
// keep track of the highest high, highest close, highest low, etc..
if ( trendDirection > 1 )
{
// We are in the trade (2nd day or later)
if ( Low < stopArray[i-1] )
{
//stop got hit. Reset the trade.
trendDirection = 0; // OK. wait until we trigger another trade.
exitArray = 1;
}
else
{
// keep track of the HHV since trade was entered.
if ( High > HHArray[i-1] )
HHArray = High;
else
HHArray = HHArray[i-1];

// Compute the stop based on the HHV.
stopArray = HHArray - ( Multiple * atrArray );
}
}

trendDirection = trendDirection + 1;
}

if ( trendDirection < 0 )
{
// keep track of the lowest low, lowest close, lowest high, etc..
if ( trendDirection < 0 - 1 )
{
// We are in the trade (2nd day or later)
if ( High > stopArray[i-1] )
{
// our stop got hit. Reset the trade.
trendDirection = 0;
exitArray = 0 - 1;
}
else
{
// keep track of the LLV since trade was entered.
if ( Low < LLArray[i-1] )
LLArray = Low;
else
LLArray = LLArray[i-1];

// Compute the stop based on the LLV.
stopArray = LLArray + ( Multiple * atrArray );
}
}

trendDirection = trendDirection - 1;
}

if ( trendDirection == 0 )
{
stopArray = 0;
LLArray = 0;
HHArray = 0;
}
}

Sell = Cover = exitarray;

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

PlotShapes( Buy*shapeUpArrow, colorBrightGreen, 0, Low );
PlotShapes( Short*shapeDownArrow, colorRed, 0, High );
PlotShapes( abs( exitArray )*shapeHollowCircle, colorYellow, 0, ValueWhen( stopArray, stopArray, 1 ), 0 );
Plot( stopArray, "Chand", ParamColor( "Chand Color:", colorYellow ), ParamStyle( "Chand Style", styleDashed ) );

_N( Title = EncodeColor( colorYellow ) + StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}}--Turtle_System_Rev_A \n OP= %g Hi= %g Lo= %g CL= %g (%.1f%%) \n Vol= " + WriteVal( V, 1.0 ) + "\n" + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );//=cnb

//_N(Title = "LLArray: " + LLArray + ", HHArray:" + HHArray +", stopArray"+stopArray);

//PlotShapes(shapeCircle * Sell, colorRed);
//PlotShapes(shapeCircle * Cover, colorGreen);
_SECTION_END();


// Plots a 20 period Donchian channel

pds=20;
DonchianUpper =HHV(Ref(H,-1),pds);
DonchianLower = LLV(Ref(L,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorBlue,styleDashed);
Plot(DonchianMiddle,"DM",colorBlue,styleHidden);
Plot(DonchianLower,"DL",colorBlue,styleDashed);

_SECTION_BEGIN("Moving Average");

x=Param("EMA 1",20,1,200,1);
y=Param("EMA 2", 50,1,200,1);
z=Param("EMA 3",100,1,200,1);
zz=Param("EMA 4",200,1,200,1);
EMA20= EMA(C,x);
EMA50=EMA(C,y);
EMA100= EMA(C,z);
EMA200=EMA(C,zz);

SUT=EMA(C,5)>EMA20;
SDT=EMA20>EMA(C,5);
mut= EMA20>EMA50;
mdt=EMA20<EMA50;
LUT=EMA50>EMA200;
LDT=EMA200>EMA50;
_SECTION_END();
_SECTION_BEGIN("Mid Term Price Trend");


MPT = IIf( mut, colorGreen, IIf( mdt, colorRed, colorYellow));
Plot( 3, "", MPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();

_SECTION_BEGIN("Short Term Price Trend");

SPT = IIf( EMA(C,5)>EMA20, colorBrightGreen, IIf( EMA20>EMA(C,5), colorPink, colorYellow));
Plot( 6, "", SPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();

_SECTION_BEGIN("Long Term Price Trend");

LPT = IIf( EMA(C,50)>EMA200, colorBlue, IIf( EMA200>EMA(C,50), colorOrange, colorYellow));
Plot( 9, "", LPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();
 
hallo to all,
I am wondering if anyone can help translate the "Counter-Trend Trading with Simple Range Exhaustion System" from Neoticker to Amibroker.

Simple Range Exhaustion System
1. Calculate the daily 20 period average range.
2. Today’s range must expand to exceed #1.
3. The 2-day combined range must expand to exceed 2.2 times of #1.
4. Go long at market if the market is trading in the lower portion of the 2-day range.
5. Protective stop is placed at 0.35 times #1 from the entry price.
6. If not stopped out, exit by 16:00 Eastern Time. i.e. a day trading system
To understand what the system does, just think about a rubber band that stretched thin. Once the force that hold up the stretched rubber band is gone, the rubber band will snap back to its normal self. Similarly, when the market moves in a particular direction too fast too soon, it will then snap back to a more sustainable level.

The formula for neoticker is the below:

# NEOTICKER DATA BEGIN
ScriptType=Indicator
Description=Simple Range Exhaustion System
Name=SimpleRangeExhaustionSys
Language=Formula
Links=1
MinBars=0
TimerInterval=100
EarlyBinding=0
MetaStyle=Normal
ValueRange=Same as Source
Placement=Smart
Multiplot_num_plots=1
Multiplot_color_0=255
Multiplot_style_0=Line
Multiplot_width_0=1
Multiplot_enabled_0=1
Multiplot_breakstyle_0=0
UpdateByTick=0
TradingSystemUI=1
PrimaryLinkOnly=0
NotifyOnRemoval=0
Param_count=4
Param_name_0=Avg Range Period
Param_inuse_0=1
Param_type_0=integer.gt.0
Param_default_0=20
Param_name_1=1D Range
Param_inuse_1=1
Param_type_1=real
Param_default_1=1
Param_name_2=2D Range Min
Param_inuse_2=1
Param_type_2=real
Param_default_2=2.2
Param_name_3=Range Stop
Param_inuse_3=1
Param_type_3=real
Param_default_3=0.35
Explanation_Lines=0
# NEOTICKER DATA END

' Simple Range Exhaustion System
' written by Lawrence Chan
' Copyright (c) 2006 TickQuest Inc.
' All Rights Reserved

' Links
' 1 - Data Series (Emini S&P)

' Original Setup
' 1. 10 minute bars
' 2. 9:30 - 16:00 EasternTime

compressseries (mydaily, data1, ppDaily, 1);
makeindicator (dailyRangeAvg, avgrange, mydaily, param1);

$d1range := mydaily.h - mydaily.l; ' current day range

$d2high := maxlist (mydaily.h, mydaily.h (1)); ' 2 day highest hi
$d2low := minList (mydaily.l, mydaily.l (1)); ' 2 day lowest lo
$d2range := $d2high - $d2low; ' 2 day range

$prevavg := dailyRangeAvg (1); ' shorthand for the average range
$longrange := $prevavg * param2; ' current day threshold
$d2refrange := $prevavg * param3; ' 2 day threshold
$stop := $prevavg * param4; ' stop based on average range

plot1 := currentequity;

$long_trigger :=
choose (
date <> date (1), 0, ' reset trigger on a new trading day
$long_trigger <> 0, $long_trigger, ' once triggered, stay triggered
$d1range <= 0 or $d2refrange <= 0, 0, ' no range information, no trade
$d1range < $longrange, 0, ' current day range must exceed our spec
$d2range < $d2refrange, 0, ' 2 day range must exceed our spec

' add your filters here to improve the signal
' the following line is a good example
' mydaily.o >= (mydaily.h (1) + mydaily.l (1)) / 2, 0,

1);

$time_off :=
time >= maketime (15, 0, 0); ' no trading at the last trading hour

$traded :=
choose (
date <> date (1), 0,
openpositionflat = 0, 1,
$traded);

longatmarket (
$time_off = 0
and $traded = 0
and $long_trigger > 0
and $d2high - c > c - $d2low,
defaultordersize);

longexitstop (
openpositionlong,
openpositionaverageentryprice - $stop,
openpositionabssize);
This seems a very promising counter trend system as you can see in the picture:

The equity curve of the system covering 1997 until end of 2005:



Can anyone help convert it to amibroker code? thanks in advance
 
I need help with when selecting a stock that was purchased in the past will show a dotted vertical line at the date of purchase and a dotted horizontal line starting at date of purchase and extending out to the right on the chart.
Would be nice to show on the chart purchase date/price/shares

Thnx

Marty
 

humble

Well-Known Member
Hi,

Can anyone help me with the following:

I am trying to backtest an afl and for debugging, I am printing the Buy and Sell value in the interpretation window. I want to print the Date & Time of the candle with the Buy and Sell also. Unfortunately, I am unable to get the correct method to do so.

Regards,
 

Similar threads