Simple Coding Help - No Promise.

john302928

Well-Known Member
hi
below is the code for golden and death crossover
Could any one help me with my requirement?
I want to findout which crossover it is currently in and when it happened
Say below code will produce lot of golden crossover signals and lot of death crossover signals for a single stock. But what i want is that it should show only one signal either it is gold or death whatever it is currently in and when it happened

Your help is really appreciated. Thanks

MA50=MA(Close,50);
MA200=MA(Close,200);
Buy=Cross(MA50,MA200);
Sell=Cross(MA200,MA50);
Filter =Buy OR Sell;
AddColumn (Buy,"Golden crossover");
AddColumn (Sell,"Death Crossover");
AddColumn (Close,"Close");
 
hello

I want to create an amibroker AFL code as per the below requirements.

1. The rectangle should automatically extend to the right side when drawn on the chart.

2. The rectangle should display the price values on the upper and lower line of the rectangle [Right Side extend].

3. The color of the rectangle should be auto set to Red if it drawn above the LTP and should be set to Green if it is drawn below LTP.
 

john302928

Well-Known Member
Can anyone help me with this please? Thanks

hi
below is the code for golden and death crossover
Could any one help me with my requirement?
I want to findout which crossover it is currently in and when it happened
Say below code will produce lot of golden crossover signals and lot of death crossover signals for a single stock. But what i want is that it should show only one signal either it is gold or death whatever it is currently in and when it happened

Your help is really appreciated. Thanks

MA50=MA(Close,50);
MA200=MA(Close,200);
Buy=Cross(MA50,MA200);
Sell=Cross(MA200,MA50);
Filter =Buy OR Sell;
AddColumn (Buy,"Golden crossover");
AddColumn (Sell,"Death Crossover");
AddColumn (Close,"Close");
 

john302928

Well-Known Member
_SECTION_BEGIN("Chart Display");
GraphXSpace = 10;
SetBarsRequired( 1,1);
Param_systemTitle = ParamStr("System Title?","Golden and Dead Cross");
if(ParamToggle("Show System Title?","No|Yes",1))
{
GfxSelectFont("Arial",10,600);
GfxSetTextColor(colorBlue);
GfxSetBkMode(1);
GfxTextOut(Param_systemTitle,15,25);
}
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(colorLightGrey);
SetBarFillColor( IIf( C>O, colorWhite, colorBlack ) );
Plot( C, "Close", ParamColor("Candle Color", colorBlack), styleCandle|styleNoTitle);
_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 tool tip
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}


_SECTION_END();
_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorGrey50), ParamStyle( "Style", styleHistogram | styleOwnScale, maskHistogram), 2 );
_SECTION_END();


_SECTION_BEGIN("Trading System");

///Defining Trend with Moving Average///



x=Param("Short EMA",50,1,200,1);
y=Param("Long EMA", 200,1,200,1);
EMA1= EMA(C,x);
EMA2=EMA(C,y);


goldencross= Cross(EMA1, EMA2); //moving average bullish
deadcross= Cross(EMA2, EMA1); //moving average bearish

_SECTION_END();


//////Defining Buy or Sell Conditions/////////
//BuyCondition = ValueWhen(PL,C)<=ValueWhen(PL,L,2) AND C>ValueWhen(PL,L,2) AND BarsSince(PL)<BarsSince(PH) AND BarsSince(PL)<=Param_buyDelay AND ValueWhen(PL,C)>=LLV(C,Param_lookbackBuy) AND IIf(MH_Buy,MH>ValueWhen(PL,MH,2),True) AND IIf(SD_Buy,SD<20,True) AND IIf(BB_Buy,BB_BuyValue,True) AND IIf(SMA_Buy,SMA_BuyValue,True) AND IIf(EMA_Buy,EMA_BuyValue,True) AND IIf(Price_Buy,C<=Price_UpperBuyValue AND C>=Price_LowerBuyValue,True) AND IIf(Volume_Buy,V>=Volume_BuyValue,True) AND IIf(RS_Buy,RS_BuyValue,True);
BuyCondition = goldencross ;
//SellCondition = ValueWhen(PH,C)>=ValueWhen(PH,H,2) AND C<=ValueWhen(PH,H,2) AND BarsSince(PH)<BarsSince(PL) AND BarsSince(PH)<=Param_sellDelay AND ValueWhen(PH,C)<=HHV(C,Param_lookbackSell) AND IIf(MH_Sell,MH<ValueWhen(PH,MH,2),True) AND IIf(SD_Sell,SD>80,True) AND IIf(BB_Sell,BB_SellValue,True) AND IIf(SMA_Sell,SMA_SellValue,True) AND IIf(EMA_Buy,EMA_SellValue,True) AND IIf(Price_Sell,C<=Price_UpperSellValue AND C>=Price_LowerSellValue,True) AND IIf(Volume_Sell,V>=Volume_SellValue,True) AND IIf(RS_Sell,RS_SellValue,True);
SellCondition = deadcross ;


Buy = BuyCondition;
Short = SellCondition;

_SECTION_END();

_SECTION_BEGIN("Exploration");
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),colorBlue,0,L,-25);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),colorOrange,0,H,-25);

SetOption("NoDefaultColumns",True);
bkColour = IIf(BuyCondition ,colorGreen,colorRed);
//bkColour = IIf(BuyCondition OR Cover,colorGreen,colorRed);
txtColour = colorWhite;
AddTextColumn(Name() ," Ticker ",1.2,txtColour,bkColour,75);
AddTextColumn(FullName() ," Full Name ",1.2,txtColour,bkColour,100);
AddColumn(DateTime()," Date / Time ",formatDateTime,txtColour,bkColour,125);
AddColumn(C," Close ",1.2,txtColour,bkColour,75);
AddColumn(ROC( C,1)," % Change ",1.2,txtColour,bkColour,50);
AddColumn(V," Volume ",1.0,txtColour,bkColour,100);

Filter = Buy OR Short;
AddColumn( IIf( BuyCondition, 66, 83 ), "Buy/Sell?", formatChar,txtColour,bkColour,40);

Var = WriteIf(goldencross,"GoldenCross",WriteIf(deadcross,"DeadCross",""));
AddTextColumn( Var , "Remark", 1.2 , colorBlack, IIf( goldencross, colorLime,IIf(deadcross,colorOrange,colorWhite)),60);

_SECTION_END();
 

john302928

Well-Known Member
Jayakumar bro,
Thank you for the efforts, i really appreciate that.
Unfortunately it still produces lot of results,
My requirement is that, for a single stock I should see the latest crossover happening date and which crossover.
 

TracerBullet

Well-Known Member
Jayakumar bro,
Thank you for the efforts, i really appreciate that.
Unfortunately it still produces lot of results,
My requirement is that, for a single stock I should see the latest crossover happening date and which crossover.
Best thing to do is to try and learn yourself, This way you can keep changing as per needs.

A simple way may be to just loop from last bar towards left and find the first Filter array index (or check your cross arrays) that is set to true. This is simple code so there should be no slowdown.
 

john302928

Well-Known Member
Jayakumar bro,
Thank you for the efforts, i really appreciate that.
Unfortunately it still produces lot of results,
My requirement is that, for a single stock I should see the latest crossover happening date and which crossover.
Hello Jayakumar bro, Please look in to it. Can i contact you via mail? I am not able to send PM to you because I dont find an option on your name
 

john302928

Well-Known Member
Last edited:

Similar threads