Want help to write program in afl (amibroker) to setup buy call- logic as follows

bunti_k23

Well-Known Member
#11
Set chart as 1 min candle stick
Logic starts when market is in sell mode
Analyse market to sell mode by EMA 20 - 50 down
for the same example chart.jpg is enclosed for the reference with the variables marked on it

-Logic starts only when market hit bottom of the day
- record the highest price above EMA20-EMA50 - store it in variable - r1 (7984)
- price comes down record lowest price store it in variable - r2 (7975)
if r2 >= EMA 20 & EMA 50 then - EMA20 IS 7974.18 EMA50 7973.48
continue
else
exit from the logic

- program exit mode - if price goes below r2 exit from logic

- continue
- price goes above r1 record highest price in variable - r3 (8003.43)
- price comes down record the lowest price - r4 (7985.35)
if r4 < r2 then
exit from the logic
else
- continue
- after this 1st white candle comes record highest point - r5 (7988.7)
- buy above r5 trigger price (r5+0.5) trade price (r5+0.5+1)
- set stop loss as r4
- set exit price as (r5+0.5+1+12)
try this,this is ST'S logic probably similiar to your logic....:)
Code:
GraphXSpace =15;
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetPositionSize(1,4);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();



/////////////////


tf = Param( "TF", 1, 1, 1000, 1 );

TimeFrameSet(in1Minute*tf );

SetBarsRequired(sbrAll,sbrAll);
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Optimize("R_S",Param("R_S",3,1,50,1) ,1,50,1);
leftStrength=Optimize("L_S",Param("L_S",3,1,50,1), 1,50,1);

function pkID(rightStrength,leftStrength)
{
pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength);
return pk;
}
function trID(rightStrength,leftStrength)
{
tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength);
return tr;
}

pk=pkID(rightStrength,leftStrength);
tr=trID(rightStrength,leftStrength);


SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0 ,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));


pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength+1));
trLow1=Ref(ValueWhen(Tr,L,1),-(rightStrength+1));
pkHigh0=ValueWhen(pk,H,0);
trLow0=ValueWhen(Tr,L,0);



Plot(pkHigh1,"",colorBlue,24,Null,Null,0,2,1);
Plot(trLow1,"",colorRed,24,Null,Null,0,2,1);


TimeFrameRestore();

////////////////////////
 
#12
For getting R1
In some cases if following case takes place
After getting bottom of the day
If one white candle crosses 2050 but close is below 2050 (i.e. only high is above 2050) & next minute candle is black, in such case also exit from the logic. After that search for new bottom of the day to start logic
That means for getting R1 there must be positive & consecutive break out of 2050 with two cosecutive white candles without black candle interference.
If it is not fulfilling our criteria then exit from the logic till get another new bottom of the day only when EMA 2050 is down
Hope this difficult logic would work
Thank you
 
#13
For getting R1
In some cases if following case takes place
After getting bottom of the day
If one white candle crosses 2050 but close is below 2050 (i.e. only high is above 2050) & next minute candle is black, in such case also exit from the logic. After that search for new bottom of the day to start logic
That means for getting R1 there must be positive & consecutive break out of 2050 with two cosecutive white candles without black candle interference.
If it is not fulfilling our criteria then exit from the logic till get another new bottom of the day only when EMA 2050 is down
Hope this difficult logic would work
Thank you
 
#14
For getting R1
In some cases if following case takes place
After getting bottom of the day
If one white candle crosses 2050 but close is below 2050 (i.e. only high is above 2050) & next minute candle is black, in such case also exit from the logic. After that search for new bottom of the day to start logic
That means for getting R1 there must be positive & consecutive break out of 2050 with two consecutive white candles without black candle interference.
If it is not fulfilling our criteria then exit from the logic till get another new bottom of the day only when EMA 2050 is down
Hope this difficult logic would work
Thank you
 
#15
For getting R1
In some cases if following case takes place
After getting bottom of the day
If one white candle crosses 2050 but close is below 2050 (i.e. only high is above 2050) & next minute candle is black, in such case also exit from the logic. After that search for new bottom of the day to start logic
That means for getting R1 there must be positive & consecutive break out of 2050 with two consecutive white candles without black candle interference.
If it is not fulfilling our criteria then exit from the logic till get another new bottom of the day only when EMA 2050 is down
Hope this difficult logic would work
Thank you
 
#16
Hi

Sorry I am not able really understand the requirements.

What I can do is give you a template code with EMA 20, EMA 50 and swing Pivots marked,
maybe you can modify it to get what you want/need

Thanks
Happy :)

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("EMAS");
E50 = EMA(C,50);				E20 = EMA(C,20);
UP = E50 > Ref(E50,-1) AND E20 > Ref(E20,-1) AND E20 > E50;
DN = E50 < Ref(E50,-1) AND E20 < Ref(E20,-1) AND E20 < E50;
LONGMODE = Flip(UP,DN);		SHRTMODE = Flip(DN,UP);

Plot(E50,"EMA50",colorGreen,styleThick);
Plot(E20,"EMA20",colorRed,styleThick);
Plot(10,"",IIf(LONGMODE,colorBlue,colorRed),styleOwnScale|styleNoLabel|styleArea,0,300);
_SECTION_END();


_SECTION_BEGIN("Pivots");

GraphXSpace = 5; 
dist = 0.7*ATR(40); 

PH= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

PL= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));

//Plot(PH, "UpPivot",colorGreen, styleNoLabel|styleStaircase,0,0,-2);
//Plot(PL, "DownPivot", colorRed,styleNoLabel|styleStaircase,0,0,-2);

for (a=4;a<BarCount;a++)
{
if ((H[a-2] >= H[a-4]) AND
(H[a-2] >= H[a-3]) AND
(H[a-2] >= H[a-1]) AND
(H[a-2] >= H[a]))
PlotText("R", a-2, H[a-2]+dist[a-2], colorGreen);

if ((L[a-2] <= L[a-4]) AND
(L[a-2] <= L[a-3]) AND
(L[a-2] <= L[a-1]) AND
(L[a-2] <= L[a]))
PlotText("R", a-2, L[a-2]-dist[a-2], colorRed);
}

_SECTION_END();
 
#18
Hi,
Happy_sing
Is it possible to meet across table
I think you could help me
my contact no is
Dear Sameer

Please remove your contact number from the post.
It's against forum rules to exchange contact information or making commercial deals :)

Anyway Currently, I do not have enf time to be available for writing Amibroker code.

But if you take it up and try to learn, there are many here who can help you with your efforts.

Thanks
Happy :)
 
#19
For my big logic i will split it into many to find out each variables.

First to find out market low of the day

; i think this logic will give me lowest value
When ema20-50 is down &
lowest value till close of current market value crosses ema20-50;

; start program at 10:15 AM so that both ema20-50 will be plotted;
;initially just fill values in the variables at time of start of program;

m_low = low now
ema20 = ema20 now
ema50 = ema50 now

if ema20 < ema50 then
while close now > max( ema 20, ema 50) ; 1 minute candle close considered;
if low now < m_low then ; 1 minute candle low ;
m_low = low now; compair with prev. stored market low with current 1 minute low;
end if
end if
wend
end if
;if market moves up then again it tries to give another bottom then we have to do following logic for next low bottom of the day;

if ema20 < ema50 then
if low now < m_low then ; should work only when current market 1 minute candle low is less than previous make low stored in variable;
while close now > max( ema 20, ema 50)
m_low = low now
end if
endif
wend
; i think this logic will find out market low at all situations;

Please send me your opinion whether i could able to define market low

Thank you
 
Last edited:
#20
i dont think that this can be done in amibroker since the scan and analysis window will run on each 1 min and if the lowest level may be keep on occurring for each min even though you r4 > r2 is true so its like re writing the values multiple times.
 

Similar threads