Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
nehal ji , very thanks for giving solution .....
but they are not working , as in
in first solution .........when we explore , in date column .......date and time both comes together ......so how to import that one

ur second solution , it prints whole database irrespective of the range of date given by us ,
third one is for eod , so cannot do it for ieod ,
in fourth one , when we explore , in date column .......date and time both comes together ......so of no use ....

plz , if u check for a specific date range let say 6 month ......than how we do so ?
Amibroker store date and time in single column hence you need to separate it manually using excel or csv editor
 

mcxinvest

Well-Known Member
_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{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 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 25, 30, 100, 5);
ShortPer = Param("Short Period", 50, 30, 100, 5);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Buy = Cross(LongMA, ShortMA);
Short=SAR( acc, accm )>C;
Sell = Cross(ShortMA, LongMA);
Cover=SAR( acc, accm )<C;

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

PlotShapes(Buy*shapeSmallUpTriangle,colorBlue ,0,L,-51);
PlotShapes(Sell*shapeHollowDownTriangle,colorPink, 0,L,-45);
PlotShapes(Short*shapeSmallDownTriangle,colorRed,0,H,-51);
PlotShapes(Cover*shapeHollowUpTriangle,colorSkyblue,0,H,-45);

_SECTION_END();
hi nehal,
ithanks for the coding, but here again when the price hits the sar it changes the side. where as i want is, SAR should only start when der is a trade. It should not keep on going.
 

KelvinHand

Well-Known Member
sir i did that basic thing , also if i not create that than how i see that csv fie contains only first day of data ....:)

Maybe the AFL had to work with real-time data.


If you are using static data like me, I can see the Scan/Exploration did not work. It seen to send the EOD data out then IEOD.

What you can do is insert as indicator, it will export the IEOD data out as per wish.
 

Nehal_s143

Well-Known Member
hi nehal,
ithanks for the coding, but here again when the price hits the sar it changes the side. where as i want is, SAR should only start when der is a trade. It should not keep on going.
There was some error in last code, correct code is

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{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 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 25, 30, 100, 5);
ShortPer = Param("Short Period", 50, 30, 100, 5);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Buy = Cross(LongMA, ShortMA);
Short=SAR( acc, accm )>C;
Sell = Cross(ShortMA, LongMA);
Cover=SAR( acc, accm )<C;

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

PlotShapes(Buy*shapeSmallUpTriangle,colorBlue ,0,L,-51);
PlotShapes(Short*shapeHollowDownTriangle,colorPink, 0,L,-45);
PlotShapes(Sell*shapeSmallDownTriangle,colorRed,0,H,-51);
PlotShapes(Cover*shapeHollowUpTriangle,colorSkyblue,0,H,-45);

_SECTION_END();

you need to add loop or if condition for SAR which i dont know how to use, I am beginner in afl coding
 

Nehal_s143

Well-Known Member
Hi

I am trying to code this condition in below afl but condition is not getting honored

Previous/Last candle low has to be lowest price for last 6 candles

_SECTION_BEGIN("Trend Reversal");

TDO = Open; // current open
TDH = High; // current high
TDL = Low; // current low
TDC = Close; // current close
PDO = Ref(Open,-1); // last candle Open
PDH = Ref(High,-1); // last candle high
PDL = Ref(Low,-1); // last candle low
PDC = Ref(Close,-1); // last candle close

slow = LLV(Low, 6);
shigh = HHV(High, 6);

Plot(shigh,"",colorYellow,styleLine);
Plot(slow,"",colorYellow,styleLine);

// Previous/Last candle low has to be lowest price for last 6 candles
Buy3 = PDL = LLV(Low, 6);
Sell3=C<O;
Short3 = PDH = HHV(High, 6);
Cover3=C>O;

Buy3=ExRem(Buy3,Sell3);
Short3=ExRem(Short3,Cover3);
Sell3=ExRem(Sell3,Buy3);
Cover3=ExRem(Cover3,Short3);

PlotShapes(Buy3*shapeSquare, colorBlue, 0, L,Offset=-40);
PlotShapes(Buy3*shapeSquare,colorBlue, 0,L, Offset=-50);
PlotShapes(Buy3* shapeUpArrow,colorWhite, 0,L, Offset=-45);
PlotShapes(Sell3* shapeSquare,colorRed, 0, H, Offset=40);
PlotShapes(Sell3* shapeSquare,colorRed, 0,H, Offset=50);
PlotShapes(Sell3* shapeDownArrow,colorWhite, 0,H, Offset=-45);

_SECTION_END();

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{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 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

Please correct the condition in above afl.
 

pratapvb

Well-Known Member
Hi

I am trying to code this condition in below afl but condition is not getting honored

Previous/Last candle low has to be lowest price for last 6 candles

_SECTION_BEGIN("Trend Reversal");

TDO = Open; // current open
TDH = High; // current high
TDL = Low; // current low
TDC = Close; // current close
PDO = Ref(Open,-1); // last candle Open
PDH = Ref(High,-1); // last candle high
PDL = Ref(Low,-1); // last candle low
PDC = Ref(Close,-1); // last candle close

slow = LLV(Low, 6);
shigh = HHV(High, 6);

Plot(shigh,"",colorYellow,styleLine);
Plot(slow,"",colorYellow,styleLine);

// Previous/Last candle low has to be lowest price for last 6 candles
Buy3 = PDL = LLV(Low, 6);
Sell3=C<O;
Short3 = PDH = HHV(High, 6);
Cover3=C>O;

Buy3=ExRem(Buy3,Sell3);
Short3=ExRem(Short3,Cover3);
Sell3=ExRem(Sell3,Buy3);
Cover3=ExRem(Cover3,Short3);

PlotShapes(Buy3*shapeSquare, colorBlue, 0, L,Offset=-40);
PlotShapes(Buy3*shapeSquare,colorBlue, 0,L, Offset=-50);
PlotShapes(Buy3* shapeUpArrow,colorWhite, 0,L, Offset=-45);
PlotShapes(Sell3* shapeSquare,colorRed, 0, H, Offset=40);
PlotShapes(Sell3* shapeSquare,colorRed, 0,H, Offset=50);
PlotShapes(Sell3* shapeDownArrow,colorWhite, 0,H, Offset=-45);

_SECTION_END();

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{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 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

Please correct the condition in above afl.
this condition
Buy3 = PDL = LLV(Low, 6);

should be
Buy3 = PDL == LLV(Low, 6);

similarly at other places

= is asignment == is comparision
 

Nehal_s143

Well-Known Member
this condition
Buy3 = PDL = LLV(Low, 6);

should be
Buy3 = PDL == LLV(Low, 6);

similarly at other places

= is asignment == is comparision
Thank you very much sir, without = is asignment == is comparision this explanation I would never understand where did I make mistake :)

Sir, now if I want to exit long if stock makes new low, lower then last six candles, what code should be used ?

Buy3 = PDL == LLV(Low, 6);
Exit3 = ??
 
Last edited:

pratapvb

Well-Known Member
Thank you very much sir, without = is asignment == is comparision this explanation I would never understand where did I make mistake :)

Sir, now if I want to exit long if stock makes new low, lower then last six candles, what code should be used ?

Buy3 = PDL == LLV(Low, 6);
Exit3 = ??
Exit3 = L < Ref(LLV(L, 6), -1) ;
 

Nehal_s143

Well-Known Member
Exit3 = L < Ref(LLV(L, 6), -1) ;

Sir, please post link for thread in which below text is refered

color key to bands in the chart
gold - 6min ama ; tan 15-13 ; brown 60-13 ; blue-grey daily-13 ; lavender with red border 15min ama

light orange very aggressive lower tf band
P.S. some early chart posts gold was 3min
 

Similar threads