Simple Coding Help - No Promise.

Sir ,
I need a afl for following conditions

buy rules : price close above previous day high
sell rules : price close below previous day low

all position should close by intraday.

also i need a exploration ...
and signal shld come after only completion of that candle

i had tried bt it didn't give me desired result ...
here is the afl
Code:
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 


_SECTION_BEGIN("HI LO");

//Previous Days HI LO //

DayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (DayL,1); // yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1); // yesterdays close
DayO = TimeFrameGetPrice("O", inDaily); // current day open

numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;

YHL = ParamToggle("Yesterday HI LO","Show|Hide",0);
if(YHL==1) {
Plot(DayL,"YL",colorRed,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH,"YH",colorGreen,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
// PlotText("-" , LastValue(BarIndex()-1), DayHI, colorTurquoise);
PlotText(" YH " , LastValue(BarIndex())-(numbars/Hts), DayHI, colorBlue);
PlotText(" YL " , LastValue(BarIndex())-(numbars/Hts), DayLI, colorRed);
}

_SECTION_BEGIN("BUY SELL");
TimeRange = ParamToggle("Time","NO|YES");
Starttime = Param("Starttime",091500,090000,235500,0);
Closetime = Param("Closetime",150500,153000,235500,0);
ExitToday = (Ref(DateNum(),1) > DateNum());
//-----AD COND----///
B1 = C > DayH ; // AND ADX() < 40; //"Buy condition"
S1 = C < DayL ; // AND ADX() < 40; //"Sell condition"
Sh1 = C < DayL ; // "Short Condition"
Co1 = C > DayH ;//"Cover Condition"


Buy = IIf(TimeRange==False,B1,B1 AND TimeNum() > Starttime AND TimeNum() < Closetime);
Sell = IIf(Timerange==False,S1,S1 AND TimeNum() > Starttime AND TimeNum() < Closetime);

se = IIf(TimeRange==False,Sh1,Sh1 OR TimeNum() > Closetime OR ExitToday) ;
be = IIf(Timerange==False,Co1,Co1 OR TimeNum() > Closetime OR ExitToday) ;

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

PlotShapes(IIf(Buy==1, shapeUpTriangle , shapeNone), colorBlue, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeDownTriangle, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(SE==1, shapeDownArrow, shapeNone), colorRed, 0,Low, Offset=-80);
//PlotShapes(IIf(SE==1, shapeSmallCircle, shapeNone), colorGreen, 0,Low, Offset=60);
PlotShapes(IIf(BE==1, shapeUpArrow, shapeNone), colorGreen, 0,High, Offset=-80);
//PlotShapes(IIf(BE==1, shapeSmallCircle, shapeNone), colorBlue, 0,High, Offset=25);
_SECTION_END();

//alert and scan 
Filter=Buy OR Sell;
//Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);

//alerts

AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1,1+2+4+8);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\notify.wav", "Short",2,1+2+4+8);
AlertIf( Buy, "", "BUY @ " + H, 1 );
AlertIf( Sell, "", "SELL @ " + L, 2 );
_SECTION_END();

_SECTION_BEGIN("Wilders");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( Wilders( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
 

amitrandive

Well-Known Member
Sir ,
I need a afl for following conditions

buy rules : price close above previous day high
sell rules : price close below previous day low

all position should close by intraday.

also i need a exploration ...
and signal shld come after only completion of that candle

i had tried bt it didn't give me desired result ...
here is the afl
Code:
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 


_SECTION_BEGIN("HI LO");
.
.
.


AAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
Here is something similar.Please modify per your requirement

http://www.traderji.com/amibroker/94458-help-needed-plz-add-buy-sell-urgent.html#post978610
 
MA1 = EMA(C,5);
MA2 = MA(C,25);

ApplyStop(0,stopModePercent, 10, 2,0,0 );
Buy = Cross(MA1, MA2);
Sell = Cross(MA2,MA1);

hello, please help me i program from moving cross strategy and backtest but i want to drop drawdown with stoploss 10% with above code but data report same as no stoploss test

thank you
 
Plotting should work by using this code

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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

TimeFrameSet( inHourly*4 ); // switch now to hourly
P0 = Param("4 Hr P", 21, 3, 250,1);
mah_4Hr = MA( C, P0); //  moving average from hourly data
Plot( TimeFrameExpand( mah_4Hr, inHourly*4), " EMA 4Hrly",ParamColor( "4Hr EMA", colorCycle ), ParamStyle("4Hr style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original
 
TimeFrameSet( inHourly ); // switch now to hourly
P1 = Param("Hr P", 21, 3, 250,1);
mah_Hr = MA( C, P1 ); //  moving average from hourly data
Plot( TimeFrameExpand( mah_Hr, inHourly), " EMA Hrly",ParamColor( "Hr EMA", colorCycle ), ParamStyle("Hr style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original

TimeFrameSet( inDaily ); // switch now to hourly
P2 = Param("Daily P", 21, 3, 250,1);
mah_13D = MA( C, p2 ); // moving average from daily data
Plot( TimeFrameExpand( mah_13D, inDaily), " EMA Daily",ParamColor( "Daily EMA", colorCycle ), ParamStyle("Daily style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original
Thanks a lot Amitji .
But i want to plot 200EMA for all periods on price close basis , but the above AFL plots a little bit different values .Please rectify the same .
Thanks a lot.
 

amitrandive

Well-Known Member
Thanks a lot Amitji .
But i want to plot 200EMA for all periods on price close basis , but the above AFL plots a little bit different values .Please rectify the same .
Thanks a lot.
k3325

Can you post some screen shots of the error values along with the correct values?
I do not have enough data to verify this.
 
Hi all,
Today i found Counter Trend reversal system which developed by Rajendran(Market calls).. But Its developed for Daily time frame. Im not getting any signals with 5 or 15 mins.

Plz any one change this afl to Intraday (5 mins time frame).

Thanks in advance...

PHP:
_SECTION_BEGIN("Counter Trend Reversal System");
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 ) ) ));

z=(High+Low+(Close)*(2))/(4);
EMAavg=((21*EMA(z,2))+(13*EMA(z,3))+(8*EMA(z,5))+(5*EMA(z,8))+(3*EMA(z,13))+(2*EMA(z,21)))/(53);
Plot(EMAavg,"EMAavg=",colorRed);



Buy =C>EMAavg AND C>EMA(C,10);
ex =C<EMAavg;



Buy = ExRem( Buy, ex );
ex = ExRem( ex, Buy ); 



Filter =  Buy ;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( C, "Close", 1.3 );


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(ex, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(ex, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(ex, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

_SECTION_END();
 

Similar threads