How to reveal all signals in repaint afl?

helo friends ,

  1. i want to know modification where in repainting signals afl --all signals are displayed esp when they stay at end of bar but disappear in next few bars . how can we code where all signals which had once appeared on completion of candle are displayed by either arrow or candle color changes beside signals which stays despite future candle. ?in short like to know where and which direction of buy sell signals got repainted.(AFL Which showed all signals (one which has disappeared plus one which has stayed at end of candle );

look forward to more insight
thank you

2 Likes

Hi @drpragnesh

If I understood well your problem is the repaint.
To solve that repaint happens, you have write something like " when the last bar is finish, then buy on the next bar open "
Maybe is little bit different if you have a condition with a group of bars, like pivot or patterns, please just use the same logic.

Buy =  Long condition here..
Buy = ref( buy,-1); // Buy if the bar is completed
Buyprice = open;  

// Below is the same logic 
cond1 = Long condition here..
Buy = ref( cond1,-1); // Buy if the bar is completed
Buyprice = open; 
1 Like

thanks for reply. my buy codition in repaint takes trade only on completion of bar. so thats not the point i wanted to know. i like to know disapperance of signals after few future bars like in peak valley function. i just like to know where they appeared and then disappeared..those which stays are obvisouly seen..but those diseappeared can we code that they leave some signature on chart to know where they occured in past.

hello @drpragnesh
Oo well i don’t know why you need to track signals that never began true.

One solution is, Yes of course you can keep tracking those moments of that signals, with a static Variable. (signals that disappear later on )

Now I am thinking out loud the second solution, what will happen if you make one more time the same condition and you place a smaller number in the second parameter (change) of the Peak function? Peak(ARRAY, change, n = 1)

i want to track disappeared signal to see if i go algo which time frame gives least disappearing singals in which time frame.

1 Like

You were saying that there is a way using static variables. I have similar requirements and I want to know how we can use static variable in this manner.

Hi
We need to know what you are try to achieve and why.
If possible write an example afl and post it here.

1 Like

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);
4 Likes

I am trying to figure out how many false signals my strategy has, if they are not many then I think it is possible to manually exit at the next candle and still maintain a good profit. I have painstakingly manually checked a data of 1 year using bar replay and it only had 2 vanishing signals. If this were to be a live trade and if I were to exit each of them at a loss of 200points then still I would have maintained a profit. Hence I want to know how many vanishing signals there are in my 10 year database without doing it manually.

NOTE: I used trade delays and it ate up all the profits, to avoid using it I came up with this idea

Can you elaborate on how to use this further. I did follow your instructions and found a file named Live trade on my local disk c: drive folder and it had a file named on the current date but it had nothing inside it.

I also wanted to ask if it works on historical data or if it only works during live trades.

Do bar replay in Amibroker. It will write the file.

image

2 Likes

Understood and does the speed of the bar replay matter? and if yes then could you suggest the speed/other settings and thanks for spending your valuable time on my subject matter.

Yes It matter. For real market testing you need 1-sec data and you have to replay it with 1sec and speed 1. It will take time but that the way the market work. .

If you have one min data it will not work as real market data. Because indicator value change when every tick came..

So be careful before live trading...

1 Like

So according to your suggested time settings wouldn't it take more than a span of 5 years at least if I wanted to run it on a database of 10 years.

@drpragnesh and @KirtiKher - it is definitely a good idea to have a methodology and/or code to check for entry signals that disappear, but the generation of those signals should be considered a bug and fixed prior to running the system live in the market.

1 Like

Hello @PanoS
Hope you are well. I am not sure if you are still active on this forum.
I wanted to know you suggested that To solve that repaint problem , you have write something like " when the last bar is finish, then buy on the next bar open "

Can you help me please, should I direclty copy paste this in the formula. Or is it some otherway.

Sorry I am new to the afl code.
Thank you in advane.
Sudhir

@sudhir_123,

You joined in 2019 yet you still don't have "Verified Badge".

Only users with "Verified Badge" are allowed to post on this forum.

Search "Verified Badge" for more information on how to get verified.

Hello @sudhir_123

Yes. I am visiting the forum very often.
To cover your question. YES, we have to write the logic in AFL.

// Below is a same logic 
// Buy at next bar OPEN, if your condition is met at the previous bar

cond1 =  write Long condition here..
Buy = ref( cond1,-1); 
Buyprice = open; 

About the ref() function read here AFL Function Reference - REF

Can you please Verified your License

Only users with License Verified Badge are allowed to post on this forum.
https://forum.amibroker.com/t/license-verified-badge/13353

1 Like

Hello @PanoS , Thank you so much for your inputs.

1 Like

Hello Dear Ashok Kumar Sir
This message is regarding Super trend 7,3 indicator you sent long back. there i was unable to reply to you. So I am replying here. please dont mind. I am unable to plot two super trends 7,3 and 14,6 on the same chart. its showing as error when I am tryimg to plot both 7,3 and 14,6 super trends. but I am able to plot any one again like either 7,3 or 14,6 alone. so, there is no error in the formula i have edited in the place of 7,3 i put 14,6. please suggest how to deploy two super trends