Simple Coding Help - No Promise.

Dear Fellow Senior traders,

I am trying to write a code... Fyi, I am new with AFL coding and learning everyday :) Looks like my problem is simple but I do not know the syntax that very well

I am using a chart with green and red candles.

What I am trying to code is... let's say.. stock is in uptrend, so mostly BARS will be closing high (GREEN). After every green candle appears, I want to look behind and find closing price of any RED candle/s that occurred previously in most recent period

If there are 2-3 continuous bars closing below open price, then I want to get the lowest value of all these bars immediately after current Candle closes Green

(lets assume that current bar is green and price closed above Open price)

Please note that: Value Not needed for those Red candles which are not closing below low of "its" PREVIOUS Green candle if any.


Hope I could explain (please refer the attached Image for quick visual understanding)...I will really appreciate your guidance.

Regards,
Dinesh
 

Attachments

casoni

Well-Known Member
Dear Fellow Senior traders,

I am trying to write a code... Fyi, I am new with AFL coding and learning everyday :) Looks like my problem is simple but I do not know the syntax that very well

I am using a chart with green and red candles.

What I am trying to code is... let's say.. stock is in uptrend, so mostly BARS will be closing high (GREEN). After every green candle appears, I want to look behind and find closing price of any RED candle/s that occurred previously in most recent period

If there are 2-3 continuous bars closing below open price, then I want to get the lowest value of all these bars immediately after current Candle closes Green

(lets assume that current bar is green and price closed above Open price)

Please note that: Value Not needed for those Red candles which are not closing below low of "its" PREVIOUS Green candle if any.


Hope I could explain (please refer the attached Image for quick visual understanding)...I will really appreciate your guidance.

Regards,
Dinesh
well i am not senior trader / coder

but i had code for similar setup , code presented will [ hopefully ] meet your requirement.
check if this helps

SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);

O1=Ref(O,-1);
C1=Ref(C,-1);
pup=C1>O1;
pdn=C1<O1;
up=C>O;
dn=C<O;
sup=pdn AND up AND C>C1 AND L>Ref(L,-1);
PlotShapes(shapeSmallcircle*sup,5,0,L,-10);
Plot(valuewhen(sup,Ref(L,-1),1),"support",5,1);
 
Try this

Code:
/* Done by    Rajandran R  */ 
/* Author of www.marketcalls.in  */ 
  
_SECTION_BEGIN("N Bar High/Low Dots"); 
  
SetBarsRequired(100000,0); 
  
GraphXSpace = 15; 
  
SetChartOptions(0,chartShowArrows|chartShowDates); 
  
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0))); 
  
GfxSetBkMode(0); 
  
GfxSetOverlayMode(1); 
  
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey))); 
  
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0); 
  
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); 
  
nhigh = Param("N Bar High", 20, 1,100,1); 
nlow =  Param("N Bar Low", 20, 1,100,1); 
  
nhi = HHV(H,nhigh); 
nlow = LLV(L,nlow); 
  
hidot = IIf(nhi>Ref(nhi,-1),True,False); 
lowdot = IIf(nlow<Ref(nlow,-1),True,False); 
  
Plot(IIf(hidot,H,Null),"High Dots",colorYellow,style = styleDots | styleThick | styleNoLine); 
Plot(IIf(lowdot,L,Null),"Low Dots",colorOrange,style = styleDots | styleThick | styleNoLine); 
  
_SECTION_END();  

Filter=hidot OR lowdot ;
AddColumn(IIf(Hidot,Hidot,Null)  ," New High "  ,6.2,1.2,colorGreen);
AddColumn(IIf(Lowdot,Lowdot,Null)," New Low ",6.2,1.2,colorOrange);

_SECTION_END();

works perfect .


thanks


best rgds



sumit
 
well i am not senior trader / coder

but i had code for similar setup , code presented will [ hopefully ] meet your requirement.
check if this helps

SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);

O1=Ref(O,-1);
C1=Ref(C,-1);
pup=C1>O1;
pdn=C1<O1;
up=C>O;
dn=C<O;
sup=pdn AND up AND C>C1 AND L>Ref(L,-1);
PlotShapes(shapeSmallcircle*sup,5,0,L,-10);
Plot(valuewhen(sup,Ref(L,-1),1),"support",5,1);


Thanks Casoni :thumb:... it is fantastic and appreciate your quick help. It is something similar to what I am looking for however still lacking. I used it today while trading and noticed that Profit booking is very difficult with this...at should kind of have trailing stops depending upon the recent turns which works good as important levels. Not sure If I am able to explain. Let me know if I need to give you more details.
 

casoni

Well-Known Member
Thanks Casoni :thumb:... it is fantastic and appreciate your quick help. It is something similar to what I am looking for however still lacking. I used it today while trading and noticed that Profit booking is very difficult with this...at should kind of have trailing stops depending upon the recent turns which works good as important levels. Not sure If I am able to explain. Let me know if I need to give you more details.
Yes give more details..
 
Dear All,

Please help,

This code by "Mastermind007" Sir, for the karthik's strategy of EMA110/CCI914).

I have added Entry/Exit time for intraday setup, it is working for entry but not covering/closing at exit time, it should close the position as per settings of end time in parameters.


i added following time param:

startTime = Param("Start Trading",100000,0,240000);
endTime = Param("Stop Trading",230000,0,240000);
//////////////////////////////////////////////////////////////////////////////////


_SECTION_BEGIN("EMA-CCI");

SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ColorRGB(192,192, 192));

NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);
Plot(NewDay, "", ParamColor("NewDay", colorWhite), 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);

if (Interval() == in5Minute)
{
FilterPercent = Param("Filter Percent %", 0.2, 0.1, 2, 0.1) / 100;
_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 )) ));

//========================================================================
EMA110 = EMA(C,110);

CCI14 = CCI(14);

startTime = Param("Start Trading",100000,0,240000);
endTime = Param("Stop Trading",230000,0,240000);


if (ParamToggle("Entry Line", "Show|Hide", 1) == 1)
{
Plot(EMA110,"EMA110",colorBlue,styleLine);
Plot(CCI14,"CCI(14)",colorBlue, styleOwnScale | styleNoLine);
}

bullish = C > EMA110 AND CCI14 > 100;
bearish = C < EMA110 AND CCI14 < -100;

LEP = (1 + FilterPercent) * H;
SEP = (1 - FilterPercent) * L;

CandleColor=IIf(bullish,colorGreen,IIf(bearish,colorRed,colorBlack));
Plot( C, "Close", CandleColor , styleNoTitle | styleCandle );
//========================================================================
BuyMode = Flip(bullish, bearish);
SellMode = Flip(bearish, bullish);
//========================================================================

LongEntryPrice = ValueWhen(BuyMode == 1 AND Ref(BuyMode,-1) == 0, LEP);
LongTargetPrice = LongEntryPrice + Param("Target",100, 0, 500, 0.01);
LongSLPrice = ValueWhen(BuyMode == 1 AND Ref(BuyMode,-1) == 0, L) - 10;

Buy = (BuyMode == 1) AND bullish AND Cross(H,LongEntryPrice) AND TimeNum() >= startTime AND TimeNum() < endTime;
Sell= (( ( Ref (BuyMode,-1) == 1) AND (BuyMode == 0))
OR Cross(H,LongTargetPrice)
OR Cross(LongSLPrice,L));

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

//========================================================================
ShortEntryPrice = ValueWhen(SellMode == 1 AND Ref(SellMode,-1) == 0, SEP);
ShortTargetPrice = ShortEntryPrice - Param("Target",10, 0, 500, 0.01);
ShortSLPrice = ValueWhen(SellMode == 1 AND Ref(SellMode,-1) == 0, H) + 10;

Short = (SellMode == 1) AND Cross(ShortEntryPrice, L)AND TimeNum() >= startTime AND TimeNum() < endTime;
Cover = ( ((Ref(SellMode,-1) == 1) AND (SellMode == 0))
OR (ShortTargetPrice >= L)
OR (H >= ShortSLPrice));


Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
//========================================================================

PlotShapes(IIf(Buy , shapeUpArrow,shapeNone),colorGreen,0,L,Offset=-10);
PlotShapes(IIf(Sell, shapeStar, shapeNone), colorRed,0,H,Offset=-10);
PlotShapes(IIf(Cover, shapeStar, shapeNone), colorGreen,0,L,Offset=-10);
PlotShapes(IIf(Short, shapeDownArrow,shapeNone),colorRed,0,H,Offset=-10);

//========================================================================
if ( (SelectedValue(BuyMode) == 1) AND ((SelectedValue(BarsSince(Sell)) == 0) OR (SelectedValue(BarsSince(Sell)) >= SelectedValue(BarsSince(Buy)))))
{
endingBar = SelectedValue(BarIndex()) + 25;
startingBar = SelectedValue(BarIndex()) - 5;

Plot(LineArray(startingBar, SelectedValue(LongEntryPrice), endingBar, SelectedValue(LongEntryPrice), 0, True), "Long Entry", colorGreen, styleNoTitle| styleThick | styleDashed | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(LongTargetPrice), endingBar, SelectedValue(LongTargetPrice), 0, True), "Long Target", colorGreen, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(LongSLPrice), endingBar, SelectedValue(LongSLPrice), 0, True), "Stop Loss", colorRed, styleNoTitle | styleDots | styleNoLabel, Null, Null);

Plot(LongEntryPrice,"\nLong Entry Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(LongTargetPrice,"Long Target Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(LongSLPrice,"Long Stop Loss Price",colorRed, styleOwnScale | styleDashed | styleNoLine);

} else if ( ( SelectedValue(SellMode) == 1) AND ((SelectedValue(BarsSince(Cover)) == 0) OR (SelectedValue(BarsSince(Cover)) >= SelectedValue(BarsSince(Short)))))
{
endingBar = SelectedValue(BarIndex()) + 25;
startingBar = SelectedValue(BarIndex()) - 5;

Plot(LineArray(startingBar, SelectedValue(ShortEntryPrice), endingBar, SelectedValue(ShortEntryPrice), 0, True), "Short Entry", colorGreen, styleNoTitle| styleThick | styleDashed | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(ShortTargetPrice), endingBar, SelectedValue(ShortTargetPrice), 0, True), "Short Target", colorGreen, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(ShortSLPrice), endingBar, SelectedValue(ShortSLPrice), 0, True), "Stop Loss", colorRed, styleNoTitle | styleDots | styleNoLabel, Null, Null);

Plot(ShortEntryPrice,"\nShort Entry Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(ShortTargetPrice,"Short Target Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(ShortSLPrice,"Short Stop Loss Price",colorRed, styleOwnScale | styleDashed | styleNoLine);
}
//========================================================================

segments = IIf( Interval() < inDaily, Day(), Month() );
segments = segments != Ref( segments , -1 );
Plot(segments, "", colorRed, styleHistogram | styleOwnScale );
//========================================================================

} else
{
_N(Title = "\n\n\n\n\n\n\n\nSORRY, BUT THIS AFL IS MEANT TO WORK ON INTERVAL OF 5 MINUTES ONLY");
}
_SECTION_END();

//===================================================================================

Please Help.

Ramulu
 

bunti_k23

Well-Known Member
anyone knows how to code the angle of any ma ,ma15 shown in following image by white arrow .:)

 

bunti_k23

Well-Known Member
Hmmm.. jst thinking. doesn't MA line itself show direction/angle.. why another parallel arrow to show it again.. :D
Nana i was not saying that i want a parallel line .i jst want that condition/slope to be defined so that in buy sell conditions we shd able to use it.i have just pointed out the slope by arrows .

Look at the first arrow ma15(orange color) the slope is very steep.
Now at second arrow slope of ma15 is bit less than first condition.
 

casoni

Well-Known Member
Nana i was not saying that i want a parallel line .i jst want that condition/slope to be defined so that in buy sell conditions we shd able to use it.i have just pointed out the slope by arrows .

Look at the first arrow ma15(orange color) the slope is very steep.
Now at second arrow slope of ma15 is bit less than first condition.
Hello bunti,
You will get idea of slope / angle from woodies cci.
Thank you
 

Similar threads