Sell and Cover conditions

Gandhar.

Well-Known Member
#1
hi
i just want to use sell and cover when in a trade and not at the condition everytime.

i.e.
to sell if i am having a long position and cover if i am having short position
the conditions for sell and short are different so cant use
sell=short and buy=cover

Thanks :thumb:
 
#2
Yes we can have different conditions for sell/short and cover/buy . . . Amibroker supports this . . .

Just use different statements for all 4 . . .

Can't really get what is your problem ?


:) Happy
 

Gandhar.

Well-Known Member
#3
sry didnt post the whole thing above
i have the afl but one thing confusing its below as shown

Buy = Cross(EMA( P, Periods1 ),EMA( P, Periods2 ) );
Short = Cross(EMA( P,Periods2 ), EMA( P, Periods1 ) );
Sell = Cross(EMA( P,Periods1 ), EMA( P, Periods0 ) );
Cover = Cross(EMA( P,Periods0 ), EMA( P, Periods1 ) );

periods 0,1,2 are 3,9,30 respectively
but i want the sell condition triggered only when i am having a long position not every time there is crossover
and cover only when having short position

hope you get it now :) if written properly
 

Gandhar.

Well-Known Member
#5
_SECTION_BEGIN("BACK COLR");

GfxSetOverlayMode(1);

GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/20 ); /* Up down name*/
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ParamColor("Text Color", ColorHSB( 42, 42, 42 ) ));
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/7);
GfxSelectFont("Tahoma", Status("pxheight")/30 );
GfxTextOut( IndustryID(1), Status("pxwidth")/2, Status("pxheight")/5 ); /* Up Down Sector*/

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

_SECTION_BEGIN("MA");


P = ParamField("Price field",-1);
Periods1 = Param("Periods1", 9, 1, 500, 1, 10 );
Periods2 = Param("Periods2", 30, 1, 500, 1, 10 );
Periods0 = Param("Periods0", 3, 1, 500, 1, 10 );

Plot( EMA( P, Periods1 ), StrFormat(_SECTION_NAME()+"(%g)", Periods1), ParamColor( "Color1", colorRed ), ParamStyle("Style") );
Plot( EMA( P, Periods2 ), StrFormat(_SECTION_NAME()+"(%g)", Periods2), ParamColor( "Color2", colorBlue ), ParamStyle("Style") );
Plot( EMA( P, Periods0 ), StrFormat(_SECTION_NAME()+"(%g)", Periods0), ParamColor( "Color0", colorWhite ), ParamStyle("Style") );

Buy = Cross(EMA( P, Periods1 ),EMA( P, Periods2 ) );
Short = Cross(EMA( P,Periods2 ), EMA( P, Periods1 ) );
Cover = Cross(EMA( P,Periods0 ), EMA( P, Periods1 ) ); BarsSince(Short)<Min(Min(BarsSince(Buy),BarsSince(Sell)),BarsSince(Cover));
Sell = Cross(EMA( P,Periods1 ), EMA( P, Periods0 ) ); BarsSince(Buy)<Min(Min(BarsSince(Sell),BarsSince(Short)),BarsSince(Cover));



PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
PlotShapes(IIf(Sell==1, shapeDownArrow , shapeNone), colorBlack, 0,Low, Offset=-15);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(Cover==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-15);

PlotOHLC( Null,EMA( P, Periods1 ),EMA( P, Periods2 ),Null, "", IIf(EMA( P, Periods1 )>EMA( P, Periods2 ) ,colorLime,colorRose), styleCloud);

Color = IIf( EMA(p,periods1) > EMA(p,periods2) , colorLime, IIf( EMA(p,periods2) > EMA(p,periods1), colorPink, colorGrey50 ));
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 30 );

_SECTION_END();

gives error line 34 sell used w/o being initialized :confused:
 
#6
Code:
_SECTION_BEGIN("BACK COLR");

GfxSetOverlayMode(1); 

GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/20 ); /* Up down name*/
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ParamColor("Text Color", ColorHSB( 42, 42, 42 ) ));
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/7);
GfxSelectFont("Tahoma", Status("pxheight")/30 );
GfxTextOut( IndustryID(1), Status("pxwidth")/2, Status("pxheight")/5 ); /* Up Down Sector*/

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

_SECTION_BEGIN("MA");


P = ParamField("Price field",-1);
Periods1 = Param("Periods1", 9, 1, 500, 1, 10 );
Periods2 = Param("Periods2", 30, 1, 500, 1, 10 );
Periods0 = Param("Periods0", 3, 1, 500, 1, 10 );

Plot( EMA( P, Periods1 ), StrFormat(_SECTION_NAME()+"(%g)", Periods1), ParamColor( "Color1", colorRed ), ParamStyle("Style") ); 
Plot( EMA( P, Periods2 ), StrFormat(_SECTION_NAME()+"(%g)", Periods2), ParamColor( "Color2", colorBlue ), ParamStyle("Style") ); 
Plot( EMA( P, Periods0 ), StrFormat(_SECTION_NAME()+"(%g)", Periods0), ParamColor( "Color0", colorWhite ), ParamStyle("Style") ); 

Sellx	=	Cross(EMA( P,Periods1 ), EMA( P, Periods0 ) ); 
Coverx	=	Cross(EMA( P,Periods0 ), EMA( P, Periods1 ) ); 

Buy 	=	Cross(EMA( P, Periods1 ),EMA( P, Periods2 ) );
Short	=	Cross(EMA( P,Periods2 ), EMA( P, Periods1 ) );
Sell	=	Sellx  AND BarsSince(Buy) < BarsSince(Sellx);
Cover	=	Coverx AND BarsSince(Short) < BarsSince(Coverx);


PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);	
PlotShapes(IIf(Sell==1, shapeDownArrow , shapeNone), colorBlack, 0,Low, Offset=-15);	
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(Cover==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-15);	

PlotOHLC( Null,EMA( P, Periods1 ),EMA( P, Periods2 ),Null, "", IIf(EMA( P, Periods1 )>EMA( P, Periods2 ) ,colorLime,colorRose), styleCloud);

Color = IIf( EMA(p,periods1) > EMA(p,periods2) , colorLime, IIf( EMA(p,periods2) > EMA(p,periods1), colorPink, colorGrey50 )); 
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 30 );

_SECTION_END();


Try this just a minor modification, original idea was from augubhai


:) Happy
 

boarders

Well-Known Member
#7
Buy = Cross(EMA( P, Periods1 ),EMA( P, Periods2 ) );
Short = Cross(EMA( P,Periods2 ), EMA( P, Periods1 ) );
Sell = Cross(EMA( P,Periods1 ), EMA( P, Periods0 ) );
Cover = Cross(EMA( P,Periods0 ), EMA( P, Periods1 ) );
long = flip(buy,short);
shrt= flip (short,buy);
sell= ref(long,-1) and sell;
cover= ref (shrt,-1) and cover;
 
#8
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", colorDefault, styleNoTitle | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods1 = Param("Periods1", 9, 1, 500, 1, 10 );
Periods2 = Param("Periods2", 30, 1, 500, 1, 10 );
Periods0 = Param("Periods0", 3, 1, 500, 1, 10 );

Plot(e1 = EMA( P, Periods1 ), StrFormat(_SECTION_NAME()+"(%g)", Periods1), ParamColor( "Color1", colorRed ), ParamStyle("Style") ); 
Plot(e2 = EMA( P, Periods2 ), StrFormat(_SECTION_NAME()+"(%g)", Periods2), ParamColor( "Color2", colorBlue ), ParamStyle("Style") ); 
Plot(e0 = EMA( P, Periods0 ), StrFormat(_SECTION_NAME()+"(%g)", Periods0), ParamColor( "Color0", colorWhite ), ParamStyle("Style") ); 

Buy 	=	e1  > e2 AND e0 > e1; //check that Sell  condition is not operational
Sell	=	e1  > e0; 
Buy 	=	ExRem(Buy,Sell);		Sell	=	ExRem(Sell,Buy);

Short	=	e2  > e1 AND e1 > e0; //check that Cover condition is not operational
Cover	=	e0  > e1;
Short 	=	ExRem(Short,Cover);	Cover	=	ExRem(Cover,Short);


PlotShapes(Buy+2*Short, colorWhite, 0,IIf(Buy OR Cover,L,H));	
PlotShapes(3*Cover+4*Sell, colorWhite, 0,IIf(Buy OR Cover,L,H),-24);	

Color1 = IIf( EMA(p,periods1) > EMA(p,periods2), colorGreen, colorYellow);
Color2 = IIf( EMA(p,periods0) > EMA(p,periods1), colorBlue, colorRed); 

Plot(1, "", Color1, styleArea | styleOwnScale | styleNoLabel, -0.1, 30 );
Plot(1, "", Color2, styleArea | styleOwnScale | styleNoLabel, -2.1, 28 );

_SECTION_END();
one more version :D


:) Happy
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?