I can Create AFL but Need Strategy

#51
Condition based on Opeing Price

Buy

Buyentry=Openprice+(openprice*0.382%)
tgt1=entryprice+(entryprice*0.618%)
tgt2=entryprice+(entryprice*1%)
If buy trigger stoploss starts days low and trailing

Sell

Sellentry=Openprice-(openprice*0.382%)
tgt1=entryprice-(entryprice*0.618%)
tgt2=entryprice-(entryprice*1%)
If sell trigger stoploss starts days high and trailing

Also need the Messageboard
Ok Sorry to waste your time

Hello Anand

This concept is very old and much discussed on traderji, just the seeding level you are using for the Line in the Sand is Days Open,
which in my opinion is as good as any other level or range anyone else is using :)

For getting the break-out and target levels it is better to experiment with behavior of the script we are trading, so i have parametarised them so you can adjust them.

Code:
SetChartBkColor(colorBlack) ;
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) \n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorDefault, styleNoTitle | styleCandle ); 
_SECTION_END();

_SECTION_BEGIN("DAY OPEN based Trading");

myOpen	=	TimeFrameGetPrice("O",inDaily,0);

BOPerc	=	Param("Break Out %",0.382,0.10,2,0.002)/100;		
T1Perc	=	Param("Target 01 %",0.618,0.20,2,0.002)/100;	
T2Perc	=	Param("Target 02 %",1.000,0.50,2,0.002)/100;	

LongBO	=	myOpen + myOpen * BOPerc;
LongT1	=	myOpen + myOpen * T1Perc;
LongT2	=	myOpen + myOpen * T2Perc;

ShortBO	=	myOpen - myOpen * BOPerc;
ShortT1	=	myOpen - myOpen * T1Perc;
ShortT2	=	myOpen - myOpen * T2Perc;

Buy	= 	Cross(H, LongBO);
Sell	=	Cross(H, LongT1)  OR Cross(ShortBO, L);
Short	=	Cross(ShortBO, L);
Cover	=	Cross(ShortT1, L) OR Cross(H, LongBO);

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

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

SetTradeDelays(0,0,0,0);
SetPositionSize(1,4);
SetOption("ReverseSignalForcesExit",True); 

Plot(LongBO,"LBO",colorBlue,styleThick);
Plot(LongT1,"LT1",colorRed,styleDashed);
Plot(LongT2,"LT2",colorBlueGrey,styleDashed);

Plot(ShortBO,"\nSBO",colorRed, styleThick);
Plot(ShortT1,"ST1",colorBlue, styleDashed);
Plot(ShortT2,"ST2",colorBlueGrey, styleDashed);

PlotShapes(Buy   * shapeUpArrow,          colorBlue, 0, L);
PlotShapes(Short * shapeDownArrow,        colorRed,  0, H);
PlotShapes(Cover * shapeSmallUpTriangle,  colorBlue, 0, L);
PlotShapes(Sell  * shapeSmallDownTriangle,colorRed,  0, H);

_SECTION_END();
 
#52
Thanks for you hope

I have facing some problem in this afl please modify and send me Sir

1. in this area selling arrow not displayed
2. my taget condition is
tgt1=breakoutprice+(breakoutprice*0.618%)
tgt2=breakoutprice+(breakoutprice*1%)
But here tgt1=openprice+(openprice*0.618%)
same as tgt2=openprice+(openprice*1%)
3. if possible stoploss value starts buy or sell arrow
like following afl or Atr or Parabolic sar stoploss
4.End of day should close our position new day again new signal only

_SECTION_BEGIN("buy_sell_display_engine_with_atr_stop");
// Trade simulation. Helps you to record your real trades and test new trading approaches without any programming skills.
// Copyright Abnash Singh 20th February 2012
// You can download and use this AFL, but do not make any changes in the copyright information, even if you make changes in the code
// Upto 9 trades can be plotted in any time frame.
// Once installed on Amibroker insert the vertical Study lines with labels b1, b2 etc for Buy signals AND s1, s2 etc for Short signals AND
// e1, e2 etc for the exit signals. The AFL automatically recognises the context of the exit for a Buy OR Sell Signal.
// Remember that the Buy AND Sell signals are generated one bar after the vertical position of the Study line.
// This has no practical impact on entering your trade signals.
// Next you can modify the trade entry AND exit values, if required in the parameter windows AND you have your trade journal ready!
// To re-use the AFL for another trading session, please remember to delete all the existing studies,
// by right clicking in the display area AND selecting delete al studies AND resetting the parameter window.
//Original work created by Abnash Singh [email protected]
SetBarsRequired(1000, 0 );

Choosesystem=ParamList("Signal from which System?","X|Y");
setbuy = ParamTrigger("Buy", "Buy" );
setsell = ParamTrigger("Sell", "Sell" );
setshort = ParamTrigger("Short", "Short" );
setcover = ParamTrigger("Cover", "Cover" );
clear = ParamTrigger("Clear", "Clear" );


clearall = ParamTrigger("Clear All", "Clear All" );
Yearabove=Param("From Year",2012,2000,2020,1);
Monthabove=Param("From Month",0,0,12,1);
Dateabove=Param("From Date",0,0,31,1);

showcandlechart=ParamList("Show Candle chart","YES|NO");

stylecndl=ParamList("Bar/Candle chart","BAR|CANDLE");
BarLum1 = Param("Bar Color Intensity", 8, 0, 10,01);
LineColor = ColorBlend(ColorRGB(50,60,60), ColorRGB(50,60,60), BarLum1);
UpBarColor = ColorBlend(ColorRGB(5,36,5), ColorRGB(10,75,10), BarLum1);
DnBarColor = ColorBlend(ColorRGB(36,5,5), ColorRGB(75,10,10), BarLum1);

bi = BarIndex();
qty = LastValue( bi );

y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
dnum=(m+10)*100+d;
tnum=TimeNum()+100000;

sby = SelectedValue( y );
sbm = SelectedValue( m );
sbd = SelectedValue( d );
sbr = SelectedValue( r );
sbe = SelectedValue( e );
sdnum = SelectedValue( dnum );
stnum = SelectedValue( tnum );


qty = LastValue( bi );


Varname = Name()+Choosesystem+sby+sdnum+stnum;


if( setbuy )
{
StaticVarSet( Varname, 1 );
}

if( setsell )
{
StaticVarSet( Varname, -1 );
}

if( setshort )
{
StaticVarSet( Varname, -2 );
}

if( setcover )
{
StaticVarSet( Varname, 2 );
}

if( clear )
{
StaticVarRemove( Varname );
}

if( clearall )
{
for( i = 0; i < qty; i++ )
{
StaticVarRemove( Name()+Choosesystem+y+dnum+tnum);
}
}

Buy = Sell = Short = Cover = exit =0;




profit=sessprofit=priceatbuy=priceatshort=priceatexit=tradecount=lastsig=pricetouse=maxprofit=lastmax=0;


shape=xp=ep=cp=0;
tradeline=Null;
BarColor = IIf(Close > Open, UpBarColor, DnBarColor);
SetBarFillColor(BarColor);
avp=(O+C)/2;//you can choose to have avp=c instead of average
if (stylecndl=="BAR")stylec=styleBar;
else stylec=styleCandle;
if (showcandlechart=="YES")
{

Plot(C, "Close", colorWhite, styleNoTitle | stylec);
}
avp=(O+C)/2;
//ATR Stop begin
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
Showtarget = ParamList ("Show Target Milestones ","Yes|No");
Step = Param( "Step for target milestones", 20, 0,50, 10 );// Step for profit progress, default is 20 points.

stopArray = Null;
atrArray = ATR( ATRPeriods );
HHArray = Null;
LLArray = Null;
exitArray = Null;
trendDirection = 0;
//ATr Stop end

dmy=ATR(10);
for (i=1;i<BarCount-1;i++)
{
if (y>=Yearabove AND (Monthabove==0 OR m>=Monthabove) AND (Dateabove==0 OR d>=Dateabove))
{
sig = StaticVarGet( Name()+Choosesystem+y+dnum+tnum);
if( sig == 1 ) Buy[ i ] = True;
if( sig == -2 ) Short[ i ] = True;
if (sig==-1 OR sig==2)exit=True;
}

if (Lastsig!=0 AND !Buy AND !Short)tradeline=tradeline[i-1];
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.


if (xp>0)priceatbuy=tradeline=xp;
else priceatbuy=tradeline=avp;//defaulting price to average price.
if (Lastsig==-1)
{
profit=priceatshort-priceatbuy;
sessprofit=sessprofit+profit;
PlotText(WriteVal(profit,1.0),i,H+10,colorYellow);


}
Lastsig=1;
}
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.

// PlotText("1",i,H+10,colorWhite);
if (xp>0)priceatshort=tradeline=xp;
else priceatshort=tradeline=avp;//defaulting price to average price.
if (Lastsig==1)
{
profit=priceatshort-priceatbuy;
sessprofit=sessprofit+profit;
PlotText(WriteVal(profit,1.0),i,H+2*dmy,colorYellow);
}
Lastsig=-1;
}
if (Lastsig==0)tradeline=Null;
if (exit)
{
if (ep>0)priceatexit=ep;
else priceatexit=avp;
if (Lastsig==1)
{
profit= priceatexit-priceatbuy;
Sell=1;
}
else if (Lastsig==-1)
{
profit= priceatshort-priceatexit;
Cover=1;
}
sessprofit=sessprofit+profit;
PlotText(WriteVal(profit,1.0),i,H+2*dmy,colorYellow);
Lastsig=profit=0;
}
if (Lastsig==1)Cp=avp-priceatbuy;
else if (Lastsig==-1)Cp=priceatshort-avp;

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] OR exit)
{
//stop got hit. Reset the trade.
trendDirection = 0; // OK. wait until we trigger another trade.
exitArray = 1;
if (Lastsig==1)
{
if (ep>0)pricetouse=ep;
else pricetouse=avp;
profit=pricetouse-priceatbuy;
sessprofit=sessprofit+profit;
PlotText(WriteVal(profit,1.0),i,H+2*dmy,colorYellow);
}
Lastsig=0;
}
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] OR exit )
{
// our stop got hit. Reset the trade.
trendDirection = 0;
exitArray = 0 - 1;
if (Lastsig==-1)
{
if (ep>0)pricetouse=ep;
else pricetouse=avp;
profit=priceatshort-pricetouse;
sessprofit=sessprofit+profit;
PlotText(WriteVal(profit,1.0),i,H+2*dmy,colorYellow);
}
Lastsig=0;
}
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;
}

if(Buy OR Short)Maxprofit=lastmax=0;
if (Cp>Maxprofit)Maxprofit=Cp;
//Profit milestones in steps of 20. Can be modified to be in steps of ATR's by replacing 20 with a variable ATR value
//Profits 2 contains the running profits. This can be used to devise a peak profit based exit.
if (exitarray==0 AND int(Maxprofit/step)*step>Lastmax AND Maxprofit>=step AND showtarget=="Yes")
{
Lastmax=int(Maxprofit/step)*step;
PlotText(WriteVal(int(Maxprofit/step)*step,1.0),i,H+2*ATRarray,colorYellow);
}





}


if (Lastsig!=0)sessprofit=sessprofit+Cp[i-1];

Plot(avp, "Mid", ColorRGB(120,120,120), styleNoTitle );
Plot(Tradeline, "Trade price", colorBlue );

shapebuy = IIf(Buy,shapeUpArrow,Null);
Shapesell= IIf(Sell,shapeHollowDownArrow,Null);
shapeshort = IIf(Short,shapeDownArrow,Null);
Shapecover= IIf(Cover,shapeHollowUpArrow,Null);

shape2= IIf(exit,shapeDownArrow,Null);
PlotShapes( shapeshort, colorRed, 0, High);
PlotShapes( shapebuy, colorGreen, 0, Low);
PlotShapes( shapesell, colorBlue, 0, High);
PlotShapes( shapecover, colorBlue, 0, Low);
PlotText(WriteVal(sessprofit,1.0)+"\n"+WriteVal(tradecount,1.0),i,H+2*dmy[BarCount-1],colorYellow);
PlotShapes( abs( exitArray )*shapeHollowCircle, colorYellow, 0, ValueWhen( stopArray, stopArray, 1 ), 0 );
Plot( IIf(stopArray!=0,stoparray,Null), "StopLine", ParamColor( "Stopline Color:", colorYellow ), ParamStyle( "Stop Style", styleDashed ) );
Title = Date()+" Trade Plotter "+ Interval(format=2)+" "+Name()+" O "+WriteVal(O,1.2)+" H "+WriteVal(H,1.2)+" L "+WriteVal(L,1.2)+" C "+WriteVal(C,1.2)+" Mid price " +WriteVal(avp,1.2)+EncodeColor(colorYellow)+" Trade Price " +WriteVal(tradeline,1.2);
_SECTION_END();
 
Last edited:
#55
Hi Sunil,

I wanted to put one strategy in AMIBROKER. Since I do most trade in Bank Nifty Future.

Strategy - Automatic Buy Trigger "Open Price and Low Price is same then go long''

Plz some one help me.....
 
#56
Hello,
Very simple system. I would like to automate it and I have no programming skills.

Indicators: 3 exponential averages of 5, 7 and 12 periods.

Long entry rules:
The lower EMA (5) crosses the 7 periods and 12 periods (not both). As the average periods of 5 is greater than the other two and 7 is higher than 12.
The candle is called meet: Vela signal.
Entry: At the opening of the next candle to candle bullish signal if
Stop loss at the low of the signal candle or candle minimum input, the smaller of the two.
Output: At the end of the candle in which the crossing of exponential averages Contrary 5 and 7 periods.

Same for short entries, but in reverse.

The system should be running from 9:00 to 14:00 local.
If arriving 14:00 a warrant inside instead of closing at 14:00 will close as soon as you close the active order.

regards,
 
#57
Hi Sunil,

I wanted to put one strategy in AMIBROKER. Since I do most trade in Bank Nifty Future.

Strategy - Automatic Buy Trigger "Open Price and Low Price is same then go long''

Plz some one help me.....
Open is know at 9:15 AM but Low of the day is know only after the end of the days trading i.e 3:30 pm :)

so when you want to check for if the current Low = Open to initiate the trade?

Cheers
::thumb::
 
#58
Open is know at 9:15 AM but Low of the day is know only after the end of the days trading i.e 3:30 pm :)

so when you want to check for if the current Low = Open to initiate the trade?

Cheers
::thumb::
Yes you are right, it just at 9.15 Current Low and OPEN is the same, we will go long.

I would like to do in BANK Nifty ONLY....it gives 100 Point instantly...may be in next 1 hr...max
 
#59
Yes you are right, it just at 9.15 Current Low and OPEN is the same, we will go long.

I would like to do in BANK Nifty ONLY....it gives 100 Point instantly...may be in next 1 hr...max
Friend if you use that logic using a tick chart it will trigger every day.

The first trade of the day is open but then at that point it is also low of the day and high of the day, i.e. Open = High = Low = Close for the first tick every day.

So how long you wait to see if Open = Low, and take the trade?

Also if you trading only 1 counter bank nifty, it should be easy to visually see the chart and execute the trade.

Cheers
::thumb::
 
#60
Friend if you use that logic using a tick chart it will trigger every day.

The first trade of the day is open but then at that point it is also low of the day and high of the day, i.e. Open = High = Low = Close for the first tick every day.

So how long you wait to see if Open = Low, and take the trade?

Also if you trading only 1 counter bank nifty, it should be easy to visually see the chart and execute the trade.

Cheers
::thumb::
well, the highly traded counter like BANK NIFTY, with 9:15:25 u might seen Open=Low but high is different, and it keep on making new highs....

This kind of situation happen 4-5 times in a months....This kind of trade ensure min 500 Point profit in a month...with Lowest SL...

In this tarde SL will be just lower than days OPEN=LOW....

Just to give you a Example......check IGL counter on Friday, 10% Up....Open and Low is the same.....

So it Mean IF BANK NIFTY Open at 11100 and Low 11100 with LTP 11109 and high 11110...then system should initiate a long with SL as 11097/99


Kundan
 

Similar threads