Simple Coding Help - No Promise.

extremist

Well-Known Member
a=1;

_SECTION_BEGIN("HeikenAshiSmoothed");
GraphXSpace=5;
p=200; //DEFAULT 5 final50
Om=DEMA(O,p);
Hm=DEMA(H,p);
lm=DEMA(L,p);
Cm=DEMA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, 1), 1);
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

slope = Param("slope",2,2,100,1);
Color20= IIf(LinRegSlope(MA(HaClose,a),slope)>10,colorRed,colorGreen);

Plot(MA(HaClose,a),"", color20,styleThick);// for buy


Color=IIf(Haclose>MA(HaClose,a),colorGreen, colorRed);
_SECTION_END();


//Buy=Color==colorGreen;
//Sell=Color==colorRed;

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

//PlotShapes(IIf(Buy , shapeUpArrow, shapeNone),colorGreen);
//PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed);




b=1; //DEFAULT 20//CHANGED BY MOMIN//

_SECTION_BEGIN("HeikenAshiSmoothed");
GraphXSpace=5;
p=205; //DEFAULT 5 final50 //for red line
Om=DEMA(O,p);
hm=DEMA(H,p);
lm=DEMA(L,p);
Cm=DEMA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, 1), 1);
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

slope = Param("slope",2,2,100,1);
Color20= IIf(LinRegSlope(MA(HaClose,b),slope)<100,colorRed,colorGreen);

Plot(MA(HaClose,b),"", color20,styleThick);//for sale

Color=IIf(Haclose>MA(HaClose,b),colorGreen, colorRed);

_SECTION_END();


Buy=Color==colorGreen;
Sell=Color==colorRed;

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

PlotShapes(IIf(Buy , shapeUpArrow, shapeNone),colorGreen);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed);






//MOMIN//////////////////
_SECTION_BEGIN("Magfied Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",1480,1,1800,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor-690 , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor-690 , Ver+45 );



/////MOMIN///////

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
_SECTION_END();



Buy and Sell Signal is not generating when EMA Line is crossing each other .
Please help.
@ momin

I appreciate the effort u put in to code ur own strategy instead of directly asking it done readily.

But doing tht u got lost so much so tht it is not understandable right now the way u wanted it to be.

So i request u to simply write it down in plain english wht u want.
We will try to get it done as per your need.


once u get ur code done. compare it with ur one and try to understand where u goofed up the coding or the logic.

I would like u to start right frm the smoothing of HA.

For the starters :
1.
HaOpen = AMA( Ref( HACLOSE, 1), 1);

Here in Ref function u r using +1 tht will be referencing to the future quote.
No Trader would like his system to be looking in to the future.
2.

Plot(LinRegSlope(MA(HaClose,1),slope),"", color20,styleThick);//for sale
i cann't understand Wht u r achieving by takin MA by period 1.
it will return uthe same array which u r averaging.

Like few more...

So please correct ur logic and elaborate it in plain english.
then few might take a shot to it for coding.

I hope u wont mind it.
 
Last edited:
Dear sir I have made this afl for NIFTY long term trading not for short term trading. When the market volatile it does not effect to the buy/sell so you can be feel relaxed. This afl ignore market volatility and avoid frequent buy/sell signal. I have manual tested it will give you return in nifty.

Idea is only for backtesting and clarity of signal.

So please help me to generate Buy Sell Signal in that afl.

for current example in nifty Sell signal came at 19/02/2015 at [email protected] after that nifty slipped down and the price was on 24/02/2015 at 02:44pm @Rs8727 now you can book profit of Rs.103 but next day i.e. 25/02/2015 market recovered and nifty goes upside till Rs.8847.50 High but the buy siganal not came and again after noon market slipped to Rs.8768 at 3.30pm. so totally ignored market volatility.

So you are totally safe in volatile market. I have made this AFL for use only me if anybody likes he can also use it at own risk.
Momin

I think you should follow extremist's suggestion and write your needs in plain english and explain what is it that you've attempted. I am failing to see the trades that you are talking about.
 
@ momin

.....


For the starters :
1.
HaOpen = AMA( Ref( HACLOSE, 1), 1);

Here in Ref function u r using +1 tht will be referencing to the future quote.
No Trader would like his system to be looking in to the future.
2.
Very well spotted!!! I missed on this one...
 
I am getting error from the following AFL, Please Correct it


_SECTION_BEGIN("%Trailing Stoploss);
no1 = Param("Bars",2,2,100,1);
NO2 = Param("Trailing Loss %",0.1,0.01,100,0.1);
Loss = (Ref(C,-NO1)*(NO2/100));
Trail = IIf(C>Ref(C,-1) AND
Ref(C,-1)>Ref(C,-2),Max(Ref(C,-1),Ref(C,-no1)-Loss),
IIf(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2),Min(Ref(C,-1),Ref(C,-no1)+Loss),
IIf(C>Ref(C,-1),C-loss,C+loss)));
Plot(Trail, _DEFAULT_NAME(), colorLightGrey, styleLine);
_SECTION_END();

Showing Syntax Error...

ow Can I optimise this indicator/System..Please help..
 
Last edited:

extremist

Well-Known Member
I am getting error from the following AFL, Please Correct it


_SECTION_BEGIN("%Trailing Stoploss);
no1 = Param("Bars",2,2,100,1);
NO2 = Param("Trailing Loss %",0.1,0.01,100,0.1);
Loss = (Ref(C,-NO1)*(NO2/100));
Trail = IIf(C>Ref(C,-1) AND
Ref(C,-1)>Ref(C,-2),Max(Ref(C,-1),Ref(C,-no1)-Loss),
IIf(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2),Min(Ref(C,-1),Ref(C,-no1)+Loss),
IIf(C>Ref(C,-1),C-loss,C+loss)));
Plot(Trail, _DEFAULT_NAME(), colorLightGrey, styleLine);
_SECTION_END();

Showing Syntax Error...

ow Can I optimise this indicator/System..Please help..
Code:
_SECTION_BEGIN("Trailing Stop Loss");
no1 = Param("Bars",2,2,100,1);
NO2 = Param("Trailing Loss %",0.1,0.01,100,0.1);
Loss = (Ref(C,-NO1)*(NO2/100));
Trail = IIf(C>Ref(C,-1) AND 
Ref(C,-1)>Ref(C,-2),Max(Ref(C,-1),Ref(C,-no1)-Loss),
IIf(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2),Min(Ref(C,-1),Ref(C,-no1)+Loss),
IIf(C>Ref(C,-1),C-loss,C+loss))); 
Plot(Trail, _DEFAULT_NAME(), colorLightGrey, styleLine);
_SECTION_END();
Code seems fine to me.
There is no error.

For Optimization u need to define Some buy Sell Conditions.

Once u done with It u can optimize the code.
 
I need the following code to be converted into Amibroker Language...Help Please..

NO1:= Input("Periods:",1,100,1);
NO2:=Input("Trailing Loss % :",0.1,100,0.1);
loss:=Ref(C,-NO1)*NO2/100;
trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,Ref(C,-NO1)-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,Ref(C,-NO1)+loss),
If(C>PREV,C-loss,C+loss)));
Trail
 
I need the following code to be converted into Amibroker Language...Help Please..

NO1:= Input("Periods:",1,100,1);
NO2:=Input("Trailing Loss % :",0.1,100,0.1);
loss:=Ref(C,-NO1)*NO2/100;
trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,Ref(C,-NO1)-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,Ref(C,-NO1)+loss),
If(C>PREV,C-loss,C+loss)));
Trail
See post 2913 for answer
 

casoni

Well-Known Member
I need the following code to be converted into Amibroker Language...Help Please..

NO1:= Input("Periods:",1,100,1);
NO2:=Input("Trailing Loss % :",0.1,100,0.1);
loss:=Ref(C,-NO1)*NO2/100;
trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,Ref(C,-NO1)-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,Ref(C,-NO1)+loss),
If(C>PREV,C-loss,C+loss)));
Trail
Here'e the correct version/translation

http://www.traderji.com/amibroker/39509-volatility-stop-loss-need-code-metasa-amibroker.html

Thank you
 

Similar threads