Below is the AFL code which will write CSV file to the location C:\LiveTrade.
From CSV file you can easily count the no of false signal
Yogya_Upcolor = ColorRGB( 0, 177, 88 );
Yogya_DownColor = ColorRGB( 246, 70, 65 );
Setchartoptions( 0, Chartshowarrows | chartShowDates );
SetbarfillColor( IIf( C > O, Yogya_Upcolor, Yogya_DownColor ) );
Plot( C, "Price", IIf( C > O, Yogya_Upcolor, Yogya_DownColor ), styleCandle | styleNoTitle );
RSI_Para = Param("Rsi Period", 14, 1, 100, 1 );
RSI_Value = RSI(RSI_Para);
Plot( RSI_Value, StrFormat("\nRSI(%g)", RSI_Para), colorLightOrange ,styleNoDraw|styleOwnScale|styleNoLabel|styleNoLine);
Buy =RSI_Value > 60;
Sell = RSI_Value < 40;
Short = RSI_Value < 30;
Cover = RSI_Value > 40;
Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -15 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -25 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -20 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 15 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 25 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -20 );
PlotShapes( IIf( Cover, shapeStar, shapeNone ), colorRed, 0, L, Offset = -20 );
PlotShapes( IIf( Sell, shapeStar, shapeNone ), colorGreen, 0, H, Offset = 20 );
Buy_Qty = Sell_Qty = 1;//ValueWhen( Realbuy OR( Sell AND Buy ), Position );
Short_Qty = Cover_Qty = 1;// ValueWhen( RealShort OR( Short AND Cover ), Position );
Buy_Price = BuyPrice;// Plot_BuyPrice;
Buy_Target = BuyPrice;// Plot_Buy_Target;
Buy_SL = BuyPrice;// Plot_Buy_SL;
Sell_Price = SellPrice;
Short_Price = ShortPrice;// Plot_ShortPrice;
Short_Target = ShortPrice;// Plot_Short_Target;
Short_SL = ShortPrice;// Plot_Short_SL;
Cover_Price = CoverPrice;
EnableTextOutput(False);
SetBarsRequired(sbrAll);
_SECTION_BEGIN( "Alerts Setup(Akmeheta@gmail.com)" );
Sound_use = ParamList( "Alert Sound?", "Yes|No", 0 );
Write_csv_file = ParamList( "Write CSV File", "Yes|No", 0 );
Audio_use = ParamList( "Listen Text Audio ?", "Yes|No", 1 );
Pop_Up_Use = ParamList( "Use Pop Up?", "Yes|No", 0 );
Reset_Alert = ParamTrigger( "To Reset Alerts", "Click Here" );
_SECTION_END();
function Day_Name_Alert( Day_Of_Week )
{
Day_Name_Alert1 = WriteIf( Day_Of_Week == 0, "Sun", WriteIf( Day_Of_Week == 1, "Mon", WriteIf( Day_Of_Week == 2, "Tue", WriteIf( Day_Of_Week == 3, "Wed", WriteIf( Day_Of_Week == 4, "Thu", WriteIf( Day_Of_Week == 5, "Fri", WriteIf( Day_Of_Week == 6, "Sat", "Unknown" ) ) ) ) ) ) );
return Day_Name_Alert1;
}
function Month_Name_Alert( No_Month_Alert )
{
Month_Name_Alert1 = WriteIf( No_Month_Alert == 1, "Jan", WriteIf( No_Month_Alert == 2, "Feb", WriteIf( No_Month_Alert == 3, "Mar", WriteIf( No_Month_Alert == 4, "Apr", WriteIf( No_Month_Alert == 5, "May",
WriteIf( No_Month_Alert == 6, "Jun", WriteIf( No_Month_Alert == 7, "Jul", WriteIf( No_Month_Alert == 8, "Aug", WriteIf( No_Month_Alert == 9, "Sept", WriteIf( No_Month_Alert == 10, "Oct", WriteIf( No_Month_Alert == 11, "Nov", WriteIf( No_Month_Alert == 12, "Dec", "Unknown" ) ) ) ) ) ) ) ) ) ) ) );
return Month_Name_Alert1;
}
function Time_HMS( AHour, AMinute, ASecond )
{
Hour_Min_Sec = WriteIf( AHour > 9, "" + AHour, "0" + AHour ) + ":" + WriteIf( AMinute > 9, "" + AMinute, "0" + AMinute ) + ":" + WriteIf( ASecond > 9, "" + ASecond, "0" + ASecond );
return Hour_Min_Sec;
}
Day_Of_Week = DayOfWeek();
No_Month_Alert = Month();
CustomDateFormat = "" + Day_Name_Alert( Day_Of_Week ) + " " + NumToStr( Day(), 1.0 ) + " " + Month_Name_Alert( No_Month_Alert ) + " " + NumToStr( Year(), 1.0, False ) + " " + WriteIf( Interval() < inDaily, Time_HMS( Hour(), Minute(), Second() ), "" ) ;
Alerts_Buy_Heading = "Buy " + Name() + " x " + Buy_Qty + " Qty at " + Buy_Price;
Alerts_Buy_Body = "Buy " + Name() + " x " + Buy_Qty + " Qty at " + Buy_Price + " is placed \n" +
"\nEntry Time: " + CustomDateFormat +
" \nTimeFrame: " + Interval( 2 ) +
"\n\nEntry : " + Buy_Price +
"\nTarget : " + Buy_Target +
"\n SL : " + Buy_SL;
Alerts_Sell_Heading = "Sell " + Name() + " x " + Buy_Qty + " Qty at " + Sell_Price;
Alerts_Sell_Body = "Sell " + Name() + " x " + Buy_Qty + " Qty at " + Sell_Price + " is placed \n" +
"\nEntry Time: " + CustomDateFormat +
" \nTimeFrame: " + Interval( 2 ) +
"\n\nExit : " + Sell_Price;
Alerts_Short_Heading = "Short " + Name() + " x " + Short_Qty + " Qty at " + Short_Price;
Alerts_Short_Body = "Short " + Name() + " x " + Short_Qty + " Qty at " + Short_Price + " is placed \n" +
"\nEntry Time: " + CustomDateFormat +
" \nTimeFrame: " + Interval( 2 ) +
"\n\nEntry : " + Short_Price +
"\nTarget : " + Short_Target +
"\n SL : " + Short_SL;
Alerts_Cover_Heading = "Cover " + Name() + " x " + Short_Qty + " Qty at " + Cover_Price;
Alerts_Cover_Body = "Cover " + Name() + " x " + Short_Qty + " Qty at " + Cover_Price + " is placed \n" +
"\nEntry Time: " + CustomDateFormat +
" \nTimeFrame: " + Interval( 2 ) +
"\n\nExit : " + Cover_Price;
Buy_Text_Alert = "Buy Order Placed in " + Name() ;
Sell_Text_Alert = "Long Square Off Order Placed in " + Name() ;
Short_Text_Alert = "Short Order Placed in " + Name();
Cover_Text_Alert = "Short Square Off Order Placed in " + Name() ;
function Alert_CSV_File_Write( filePath, mode, retryCount, line )
{
result = True;
for( i = 1; i <= retryCount; i++ )
{
fh = fopen( filePath, mode );
if( fh )
{
fputs( line + "\n", fh );
fclose( fh );
break;
}
else
{
result = False;
_TRACE( "[Attempt: " + i + "] Failed to write line: " + line );
}
}
return result;
}
function Alert_CSV_File_Text( filePath, line )
{
return Alert_CSV_File_Write( filePath, "a", 1, line );
}
Now_Year = Now( 8 );
Now_Month = Month_Name_Alert( Now( 7 ) );
Now_Day = Now( 6 );
System_Time = WriteIf( StrLen( NumToStr( Now( 4 ), 1.0, False ) ) == 5, "0" + NumToStr( Now( 4 ), 1.0, False ), "" + NumToStr( Now( 4 ), 1.0, False ) );
Desktop_Path = "C:";//ParamStr( "Desktop Path", "C:\\Users\\akmeh\\Desktop" );
System_Date = "" + Now_Year + "_" + Now_Month + "_" + Now_Day; //DateTimeFormat( " %Y_%b_%d", Now( 5 ) );
Path_For_Data1 = Desktop_Path + "\\LiveTrade\\";
Path_For_Data = Desktop_Path + "\\LiveTrade\\" + System_Date + "\\";
CSV_File_Path = Path_For_Data + "LiveTradeData" + System_Date + ".csv";
fmkdir( Path_For_Data1 );
fmkdir( Path_For_Data );
System_Date_Time = System_Date + "_" + System_Time;
Buy_Write_Text = Name() + ",Buy," + Buy_Qty + "," + Buy_Price + "," + Interval( 2 ) + "," + CustomDateFormat + "," + System_Date_Time;
Short_Write_Text = Name() + ",Short," + 1 + "," + Short_Price + "," + Interval( 2 ) + "," + CustomDateFormat + "," + System_Date_Time;
Sell_Write_Text = Name() + ",Sell," + Buy_Qty + "," + Sell_Price + "," + Interval( 2 ) + "," + CustomDateFormat + "," + System_Date_Time;
Cover_Write_Text = Name() + ",Cover," + 1 + "," + Cover_Price + "," + Interval( 2 ) + "," + CustomDateFormat + "," + System_Date_Time;
SetBarsRequired( sbrAll );
Last_Bar_No = LastValue( BarIndex() );
BuyBarno = StaticVarGet( Name() + GetChartID() + "AlertsBuyBarno" );
SellBarno = StaticVarGet( Name() + GetChartID() + "AlertsSellBarno" );
ShortBarno = StaticVarGet( Name() + GetChartID() + "AlertsShortBarno" );
CoverBarno = StaticVarGet( Name() + GetChartID() + "AlertsCoverBarno" );
if( LastValue( Sell ) AND Nz( SellBarno ) != Last_Bar_No AND Nz( BuyBarno ) > 0 )
{
if( Audio_use == "Yes" ) Say( Sell_Text_Alert );
if( Sound_use == "Yes" AND Audio_use != "Yes" ) PlaySound( "C:\\Windows\\Media\\chimes.wav" );
if( Pop_Up_Use == "Yes" ) PopupWindow( Alerts_Sell_Body, Alerts_Sell_Heading, 8, 100, 200 ) ;
if( Write_csv_file == "Yes" ) Alert_CSV_File_Text( CSV_File_Path, Sell_Write_Text );
StaticVarSet( Name() + GetChartID() + "AlertsSellBarno", Last_Bar_No );
}
if( LastValue( Cover ) AND Nz( CoverBarno ) != Last_Bar_No AND Nz( ShortBarno ) > 0 )
{
if( Audio_use == "Yes" ) Say( Cover_Text_Alert );
if( Sound_use == "Yes" AND Audio_use != "Yes" ) PlaySound( "C:\\Windows\\Media\\chimes.wav" );
if( Pop_Up_Use == "Yes" ) PopupWindow( Alerts_Cover_Body, Alerts_Cover_Heading, 8, 100, 500 ) ;
if( Write_csv_file == "Yes" ) Alert_CSV_File_Text( CSV_File_Path, Cover_Write_Text );
StaticVarSet( Name() + GetChartID() + "AlertsCoverBarno", Last_Bar_No );
}
if( LastValue( Buy ) AND Nz( BuyBarno ) != Last_Bar_No )
{
if( Audio_use == "Yes" ) Say( Buy_Text_Alert );
if( Sound_use == "Yes" AND Audio_use != "Yes" ) PlaySound( "C:\\Windows\\Media\\chimes.wav" );
if( Pop_Up_Use == "Yes" ) PopupWindow( Alerts_Buy_Body, Alerts_Buy_Heading, 8, 100, 200 ) ;
if( Write_csv_file == "Yes" ) Alert_CSV_File_Text( CSV_File_Path, Buy_Write_Text );
StaticVarSet( Name() + GetChartID() + "AlertsBuyBarno", Last_Bar_No );
}
if( LastValue( Short ) AND Nz( ShortBarno ) != Last_Bar_No )
{
if( Audio_use == "Yes" ) Say( Short_Text_Alert );
if( Sound_use == "Yes" AND Audio_use != "Yes" ) PlaySound( "C:\\Windows\\Media\\chimes.wav" );
if( Pop_Up_Use == "Yes" ) PopupWindow( Alerts_Short_Body, Alerts_Short_Heading, 8, 100, 500 ) ;
if( Write_csv_file == "Yes" ) Alert_CSV_File_Text( CSV_File_Path, Short_Write_Text );
StaticVarSet( Name() + GetChartID() + "AlertsShortBarno", Last_Bar_No );
}
if( Reset_Alert ) StaticVarRemove( Name() + GetChartID() + "Alerts*" );
EnableTextOutput(True);