Help Me to Create AFL

#1
Mr.Karthick EMA and CCI Strategy.
======================================================
Let's go to the strategy!!

Setup

1). Timeframe : 5min chart
2). EMA : 110 period
3). CCI : 14 days

Why EMA 110? To be frank no idea but when tested proved with results to guage the TREND!

RULE

BUY / GO LONG CONDITION

a). The 5 min candle should be above 110 EMA.
b). CCI should be > 100. We consider CCI reading only for ENTRY not for EXIT. This CCI will act as a FILTER to avoid false Traps
c). A 0.10% filter on the High price

SELL / GO SHORT CONDITION

a). The 5 min candle should be below 110 EMA.
b). CCI should be < -100. We consider CCI reading only for ENTRY and not for EXIT. This CCI will act as a FILTER to avoid false Traps
c). A 0.10% filter on the Low price

EXIT : Rs.10/- min

SL : Rs.10/- (as I want to keep RR as 1:1)

Recommended Scrips : MARUTI, AXISBANK, LT, TCS, ICICIBANK & SBI

I have tested the strategy with the above scrips and hence posted as recommendation. Why I have selected the above scrip is bacause of the highly traded volume.

I will explain in detail with the Charts

Karthik
=========================================================



I am trying to create AFL for Above Mr.Karthick's Strategy.

AFL Code :

TimeFrameSet( in5Minute);

dec = (Param("Decimals",2,0,7,1)/10)+1;
EMA110=EMA(C,110);
pt=CCI()>100;nt=CCI()<-100;

Buy2show = 0;
Sell2show = 0;

// Check if it is time to close the postions.
EOD = IIf(TimeNum()>152900, 1, 0);
noEOD = IIf(TimeNum() < 152900,1, 0);

// Logic for uptrend or downtrend
uptrend = C>EMA110 AND pt;
downtrend=C<EMA110 AND nt;

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,0);

// The current bar should be more than previous bar value + 0.1% for buy in uptrend
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1)+ H*.001 )) AND Datefine ;
// the current bar should be less than previous bar value - 0.1% for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L < ( Ref(L, -1)-L*.001 )) AND Datefine ;

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1)) ;
SellSB= BarsSince(Ref(SellV,-1));

BuyPrice = IIf(BuyV==1 AND BuySB > SellSB ,Max(O,Ref(H,-1)+H*.001 ),0);
SellPrice = IIf(SellV==1 AND BuySB < SellSB ,Min(O,Ref(L,-1)-L*.001 ),0);

Bp = ValueWhen(BuyPrice !=0,BuyPrice);
Sp = ValueWhen(SellPrice !=0,SellPrice);


// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine ;
// We can signal sell only if previous signal was a buy.
Sell =SellV AND BuySB < SellSB AND Datefine ;

//Cover = BuyPrice;
//Short = SellPrice;
CP = 0;
Trend = 1;
//***************************************************************************************//
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\n"+"\n"+"\n"+"Buy@" +WriteVal( Bp[ i],1.2), i-5, L[ i ]-Trend, colorWhite, colorBlue);
Buy2show=Bp;
}

if( Sell )
{
PlotText( "\n"+"\n"+"\n"+"Sell@" +WriteVal (Sp[ i ],1.2), i-5, L[ i ]+Trend, colorWhite, colorRed );
Sell2show=Sp;
}
}


SetChartOptions(0, chartShowDates);
//Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNone),colorWhite,0,SellPrice,0);

//PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorYellow,0,H,-15);
//PlotShapes(IIf(Cover,shapeUpArrow,shapeNone),colorYellow,0,L,-15);


_SECTION_BEGIN("Price");
Graph0 = Close;
Graph0Style = 128;
barcolor = IIf( downtrend, colorRed, IIf( uptrend, colorGreen ,colorWhite ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );
SetBarFillColor( IIf( downtrend,colorRed, colorGreen) );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey));
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Uptrend %g,Open %g, Hi %g, Lo %g,Close %g (%.1f%%) {{VALUES}}", uptrend,O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C) + "\n" + "\n" ;
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
Plot( 2, /* defines the height of the ribbon in percent of pane width*/ "ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorTan )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

//filters
Filter=Buy | Sell;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "SYMBOL");
AddColumn(DateTime(), "DATE", formatDateTime);
AddColumn(TimeNum() ,"Time",1, 75);
AddColumn(IIf(Buy, 66, 83), "TRIGGER", formatChar, colorWhite, IIf(Buy, colorGreen, colorRed));
AddColumn(IIf(Buy, BuyPrice,SellPrice), "TRIG PRICE", 1.2);
AddColumn(IIf(Buy, (BuyPrice)+10, (SellPrice)-10), "Target", 1.2);
AddColumn(IIf(Buy, (BuyPrice)-10, (SellPrice)+10), "Stop Loss", 1.2);
AddColumn(C, "Last Close", 1.2);
SetSortColumns( -3 );Title = EncodeColor(29)+ Title = Name() + " " + EncodeColor(32)
+ Date() + " " + EncodeColor(29) + "{{INTERVAL}} " +
EncodeColor(29)+ " Open = "+ EncodeColor(17)+ NumToStr
(O,dec) +
EncodeColor(29)+ " High = "+ EncodeColor(17) + NumToStr
(H,dec) +
EncodeColor(29)+ " Low = "+ EncodeColor(17)+ NumToStr
(L,dec) +
EncodeColor(29)+ " Close = "+ EncodeColor(17)+ NumToStr
(C,dec) +
EncodeColor(29)+ " Volume = "+ EncodeColor(17)+ NumToStr
(V,1.0) +"\n"+"\n"+
WriteIf (Buy , " GO LONG / Reverse Signal at "+BuyPrice+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+SellPrice+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(SellPrice-Bp)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(Sp-BuyPrice)+"","");
GraphXSpace=12;
_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 110, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style",styleThick) );
_SECTION_END();
========================================================

I like to add below condition :-

1) If I have Long position still 3.25 then I should show here Sell(or Short) signal in chart .

2) If I have Short position still 3.25 then I should show here Buy(or Cover) signal in chart .

3) Fresh Day first Signal dont check previous signal is buy or sell.


Example :- Current day sell signal come as per above strategy, Last Day Trade signal also show sell in chart in this condition, current day first sell signal not show in chart. (If Last Trade day Last signal show Buy signal then show today's first trade sell signal correctly ).

Here I attached Screenshot :-
=======================
Axisbank Futures:
=============
Yesterday Axisbank futures Show Last Signal sell @ 9.20 a.m. (only one trade). Today also Sell signal should come @ 11 a.m. But not show in chart.





Tcs Futures :
===========
Yesterday Tcs futures Show Last Signal Buy @ 3.20 a.m. Today Sell Signal is Correctly showing @ 9.20 a.m.

 

sr114

Well-Known Member
#2
Mr.Karthick EMA and CCI Strategy.
======================================================

I am trying to create AFL for Above Mr.Karthick's Strategy.

AFL Code :

TimeFrameSet( in5Minute);

dec = (Param("Decimals",2,0,7,1)/10)+1;
EMA110=EMA(C,110);
pt=CCI()>100;nt=CCI()<-100;

Buy2show = 0;
Sell2show = 0;

// Check if it is time to close the postions.
EOD = IIf(TimeNum()>152900, 1, 0);
noEOD = IIf(TimeNum() < 152900,1, 0);

// Logic for uptrend or downtrend
uptrend = C>EMA110 AND pt;
downtrend=C<EMA110 AND nt;

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,0);

// The current bar should be more than previous bar value + 0.1% for buy in uptrend
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1)+ H*.001 )) AND Datefine ;
// the current bar should be less than previous bar value - 0.1% for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L < ( Ref(L, -1)-L*.001 )) AND Datefine ;

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1)) ;
SellSB= BarsSince(Ref(SellV,-1));

BuyPrice = IIf(BuyV==1 AND BuySB > SellSB ,Max(O,Ref(H,-1)+H*.001 ),0);
SellPrice = IIf(SellV==1 AND BuySB < SellSB ,Min(O,Ref(L,-1)-L*.001 ),0);

Bp = ValueWhen(BuyPrice !=0,BuyPrice);
Sp = ValueWhen(SellPrice !=0,SellPrice);


// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine ;
// We can signal sell only if previous signal was a buy.
Sell =SellV AND BuySB < SellSB AND Datefine ;



//Cover = BuyPrice;
//Short = SellPrice;
CP = 0;
Trend = 1;
//***************************************************************************************//
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\n"+"\n"+"\n"+"Buy@" +WriteVal( Bp[ i],1.2), i-5, L[ i ]-Trend, colorWhite, colorBlue);
Buy2show=Bp;
}

if( Sell )
{
PlotText( "\n"+"\n"+"\n"+"Sell@" +WriteVal (Sp[ i ],1.2), i-5, L[ i ]+Trend, colorWhite, colorRed );
Sell2show=Sp;
}
}


SetChartOptions(0, chartShowDates);
//Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorWhite,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNone),colorWhite,0,SellPrice,0);

//PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorYellow,0,H,-15);
//PlotShapes(IIf(Cover,shapeUpArrow,shapeNone),colorYellow,0,L,-15);


_SECTION_BEGIN("Price");
Graph0 = Close;
Graph0Style = 128;
barcolor = IIf( downtrend, colorRed, IIf( uptrend, colorGreen ,colorWhite ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );
SetBarFillColor( IIf( downtrend,colorRed, colorGreen) );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey));
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Uptrend %g,Open %g, Hi %g, Lo %g,Close %g (%.1f%%) {{VALUES}}", uptrend,O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C) + "\n" + "\n" ;
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
Plot( 2, /* defines the height of the ribbon in percent of pane width*/ "ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorTan )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

//filters
Filter=Buy | Sell;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "SYMBOL");
AddColumn(DateTime(), "DATE", formatDateTime);
AddColumn(TimeNum() ,"Time",1, 75);
AddColumn(IIf(Buy, 66, 83), "TRIGGER", formatChar, colorWhite, IIf(Buy, colorGreen, colorRed));
AddColumn(IIf(Buy, BuyPrice,SellPrice), "TRIG PRICE", 1.2);
AddColumn(IIf(Buy, (BuyPrice)+10, (SellPrice)-10), "Target", 1.2);
AddColumn(IIf(Buy, (BuyPrice)-10, (SellPrice)+10), "Stop Loss", 1.2);
AddColumn(C, "Last Close", 1.2);
SetSortColumns( -3 );Title = EncodeColor(29)+ Title = Name() + " " + EncodeColor(32)
+ Date() + " " + EncodeColor(29) + "{{INTERVAL}} " +
EncodeColor(29)+ " Open = "+ EncodeColor(17)+ NumToStr
(O,dec) +
EncodeColor(29)+ " High = "+ EncodeColor(17) + NumToStr
(H,dec) +
EncodeColor(29)+ " Low = "+ EncodeColor(17)+ NumToStr
(L,dec) +
EncodeColor(29)+ " Close = "+ EncodeColor(17)+ NumToStr
(C,dec) +
EncodeColor(29)+ " Volume = "+ EncodeColor(17)+ NumToStr
(V,1.0) +"\n"+"\n"+
WriteIf (Buy , " GO LONG / Reverse Signal at "+BuyPrice+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+SellPrice+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(SellPrice-Bp)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(Sp-BuyPrice)+"","");
GraphXSpace=12;
_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 110, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style",styleThick) );
_SECTION_END();
========================================================

I like to add below condition :-

1) If I have Long position still 3.25 then I should show here Sell(or Short) signal in chart .

2) If I have Short position still 3.25 then I should show here Buy(or Cover) signal in chart .

3) Fresh Day first Signal dont check previous signal is buy or sell.


Example :- Current day sell signal come as per above strategy, Last Day Trade signal also show sell in chart in this condition, current day first sell signal not show in chart. (If Last Trade day Last signal show Buy signal then show today's first trade sell signal correctly ).



for closing trade at the end of the day use the following condition

mktclose=Param("Market Close Time",152500,000000,235959,1 );

Buy = Buy cond;
Sell=sell cond OR TimeNum() > mktclose);
Short = Short cond;
Cover=cover cond OR TimeNum() > mktclose);
Fresh Day first Signal dont check previous signal is buy or sell.

for this use the following:
Today = LastValue(Day());

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Today ;// dont use Datefine ;
// We can signal sell only if previous signal was a buy.
Sell =SellV AND BuySB < SellSB AND Today; // dont use Datefine ;



regds
subroto
 
#3
Fresh Day first Signal dont check previous signal is buy or sell.

for this use the following:
Today = LastValue(Day());

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Today ;// dont use Datefine ;
// We can signal sell only if previous signal was a buy.
Sell =SellV AND BuySB < SellSB AND Today; // dont use Datefine ;



regds
subroto
Thanks for your help subroto. I tried above code. But could not solve my problem. As per Karthick's Strategy Today ICICIBANK sell @ 11.25 a.m. But not showing in Amibroker Chart. Because Yesterday last Signal is showing Sell signal. So Today's First Sell signal did not show in chart. kindly help me to solve this problem.
 
#4
How create code for below condition ?

if time now is = 091500 //if this condition is correct enter the loop otherwise dont enter loop.
{a=0; //Condition 1
b=0; //Condition 2
}
Else
 
#5
Today's Trade Details:-
=================
Axis Bank :
==========
10.05 Sell @ 1292.75
10.35 Cover @ 1302.75 (SL)

10.50 Buy @ 1318.25
11.35 Sell @ 1328.25 (Profit)

ICICI :
=====
10.35 Buy @ 1035.45
10.45 Sell @ 1045.45 (Profit)

LT :
===
10.05 Sell @ 1432.0
10.35 Cover@ 1442.60 (SL)

1.15 Sell @ 1445.95
1.30 Cover @ 1435.95 (Profit)

Maruti:
=====
10.15 Sell @ 1324.55
10.50 Cover@ 1334.55 (SL)

1.15 Sell @ 1315.50
1.30 Cover@ 1305.50 (Profit)

Sbin :
====
1.15 Sell @ 2144.05
1.30 Covr@ 2134.05 (Profit) .




Axis Bank Futures:
==============





LT Futures:
========




Report Image:
==========



I like to add Sell and Cover signal in below condition.

Sell = Buyprice + 10(Target) OR Buyprice - 10 (SL) OR (check previous trade is Buy then show Sell signal @ 3.25 p.m)

Cover = Shortprice - 10(Target) OR Shortprice + 10 (SL) OR (check previous trade is Short then show Cover signal @ 3.25 p.m)


Anyone one can help me ?
 
#6
Here AFL :
========
/*
Setup

1). Timeframe : 5min chart
2). EMA : 110 period
3). CCI : 14 days

Why EMA 110? To be frank no idea but when tested proved with results to guage the TREND!

RULE

BUY / GO LONG CONDITION

a). The 5 min candle should be above 110 EMA.
b). CCI should be > 100. We consider CCI reading only for ENTRY not for EXIT. This CCI will act as a FILTER to avoid false Traps
c). A 0.10% filter on the High price

SELL / GO SHORT CONDITION

a). The 5 min candle should be below 110 EMA.
b). CCI should be < -100. We consider CCI reading only for ENTRY and not for EXIT. This CCI will act as a FILTER to avoid false Traps
c). A 0.10% filter on the Low price

EXIT : Rs.10/- min

SL : Rs.10/- (as I want to keep RR as 1:1)

Recommended Scrips : MARUTI, AXISBANK, LT, TCS, ICICIBANK & SBI

I have tested the strategy with the above scrips and hence posted as recommendation. Why I have selected the above scrip is bacause of the highly traded volume.

I will explain in detail with the Charts

Karthik
*/
TimeFrameSet( in5Minute);

dec = (Param("Decimals",2,0,7,1)/10)+1;
EMA110=EMA(C,110);
pt=CCI()>100;nt=CCI()<-100;

Buy2show = 0;
Short2show = 0;
Sell2show = 0;
Cover2show = 0;
Today = LastValue(Day());

// Check if it is time to close the postions.
EOD = IIf(TimeNum()>152900, 1, 0);
noEOD = IIf(TimeNum() < 152900,1, 0);

// Logic for uptrend or downtrend
uptrend = C>EMA110 AND pt;
downtrend=C<EMA110 AND nt;

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,0);


// The current bar should be more than previous bar value + 0.1% for buy in uptrend
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1)+ H*.001 )) AND Datefine ;
// the current bar should be less than previous bar value - 0.1% for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L < ( Ref(L, -1)-L*.001 )) AND Datefine ;

BuyPrice = IIf(BuyV==1,Max(O,Ref(H,-1)+H*.001 ),0);
ShortPrice = IIf(SellV==1,Min(O,Ref(L,-1)-L*.001 ),0);

Bp = ValueWhen(BuyPrice !=0,BuyPrice);
Sp = ValueWhen(ShortPrice !=0,ShortPrice);

mktclose=Param("Market Close Time",152500,000000,235959,1 );

Buy = BuyV AND Today ;
Short= SellV AND Today ;
Cover = TimeNum() > mktclose ;
Sell = TimeNum() > mktclose ;

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

CP = 0;
Trend = 1;
//***************************************************************************************//
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\n"+"\n"+"\n"+"Buy@" +WriteVal( Bp[ i],1.2), i-5, L[ i ]-Trend, colorWhite, colorBlue);
Buy2show=Bp;
}

if( Short )
{
PlotText( "\n"+"\n"+"\n"+"Short@" +WriteVal (Sp[ i ],1.2), i-5, L[ i ]+Trend, colorWhite, colorRed );
Short2show=Sp;
}
}


SetChartOptions(0, chartShowDates);
//Plot(C,"\nC",colorWhite,64);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);

PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Short,shapeHollowDownArrow,shapeNone),colorWhite,0,H,-15);
PlotShapes(IIf(Short,shapeHollowSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorYellow,0,H,-15);
PlotShapes(IIf(Cover,shapeUpArrow,shapeNone),colorYellow,0,L,-15);


_SECTION_BEGIN("Price");
Graph0 = Close;
Graph0Style = 128;
barcolor = IIf( downtrend, colorRed, IIf( uptrend, colorGreen ,colorWhite ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );
SetBarFillColor( IIf( downtrend,colorRed, colorGreen) );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorWhite));
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Uptrend %g,Open %g, Hi %g, Lo %g,Close %g (%.1f%%) {{VALUES}}", uptrend,O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C) + "\n" + "\n" ;
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
Plot( 2, /* defines the height of the ribbon in percent of pane width*/ "ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorTan )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

//filters
Filter=Buy|Short;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "SYMBOL");
AddColumn(DateTime(), "DATE", formatDateTime);
AddColumn(TimeNum() ,"Time",1, 75);
AddColumn(IIf(Buy, 66, 83), "TRIGGER", formatChar, colorWhite, IIf(Buy, colorGreen, colorRed));
AddColumn(IIf(Buy, BuyPrice,ShortPrice), "TRIG PRICE", 1.2);
AddColumn(IIf(Buy, (BuyPrice)+10, (ShortPrice)-10), "Target", 1.2);
AddColumn(IIf(Buy, (BuyPrice)-10, (ShortPrice)+10), "Stop Loss", 1.2);
AddColumn(C, "Last Close", 1.2);
SetSortColumns( -3 );Title = EncodeColor(29)+ Title = Name() + " " + EncodeColor(32)
+ Date() + " " + EncodeColor(29) + "{{INTERVAL}} " +
EncodeColor(29)+ " Open = "+ EncodeColor(17)+ NumToStr
(O,dec) +
EncodeColor(29)+ " High = "+ EncodeColor(17) + NumToStr
(H,dec) +
EncodeColor(29)+ " Low = "+ EncodeColor(17)+ NumToStr
(L,dec) +
EncodeColor(29)+ " Close = "+ EncodeColor(17)+ NumToStr
(C,dec) +
EncodeColor(29)+ " Volume = "+ EncodeColor(17)+ NumToStr
(V,1.0) +"\n"+"\n"+
EncodeColor(colorRed)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+BuyPrice+" ","")+
WriteIf (Short , " EXIT LONG / Reverse Signal at "+ShortPrice+" ","")+"\n"+EncodeColor(colorBlue)+
WriteIf(Short , "Total Profit/Loss for the Last Trade Rs."+(ShortPrice-Bp)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(Sp-BuyPrice)+"","");
GraphXSpace=12;
_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 110, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style",styleThick) );
_SECTION_END();
 
#8
for closing trade at the end of the day use the following condition



Fresh Day first Signal dont check previous signal is buy or sell.

for this use the following:
Today = LastValue(Day());

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Today ;// dont use Datefine ;
// We can signal sell only if previous signal was a buy.
Sell =SellV AND BuySB < SellSB AND Today; // dont use Datefine ;



regds
subroto
Hey guys I was wondering if you could help me writing an afl for the following stratergy

Hey All,
Can some one help in writing a code for the following
Candle stick, bars
1) Higher high bar/candle = green, lower low = red
2) If price is above a 5,15 and 30 moving average, then the bar should be green.
3) If price is below a 5,15 and 30 moving average, then the bar should be red .

Now here is the tricky part,

If the 5 MA is below the 15 MA but above the 30 MA or
if the 5 MA is above the 15 MA but below the 30 MA, the bars should be yellow.

Thanks in advance,

Max
 

Bewinner

Well-Known Member
#9
Hi Maximillion,

U have started a thread by your own with the same message...
Don't spread the message in every thread...

Seniros will help you in your own thread.
 

johnnypareek

Well-Known Member
#10
Hey guys I was wondering if you could help me writing an afl for the following stratergy

Hey All,
Can some one help in writing a code for the following
Candle stick, bars
1) Higher high bar/candle = green, lower low = red
2) If price is above a 5,15 and 30 moving average, then the bar should be green.
3) If price is below a 5,15 and 30 moving average, then the bar should be red .

Now here is the tricky part,

If the 5 MA is below the 15 MA but above the 30 MA or
if the 5 MA is above the 15 MA but below the 30 MA, the bars should be yellow.

Thanks in advance,

Max
Well,

What color if high is higher but price is below a 5,15 and 30 moving average. shud it be green??
 

Similar threads