Signal not trigger & storing in realtime but working in Bar replay

Hi,

Iam new to Amibroker programming. Recently have tried coding to trigger signal and signal can be stored in text file. Coding working fine while Bar replay. signal are stored in text file and indication also coming correctly.

But in real time in market, signal showing correctly but not storing in text file. Anyone can help me on this please.

_SECTION_BEGIN("RSI Crossover Alert-all Stock");
SetChartOptions(0,0,chartGrid30|chartGrid70);
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
periods = Param( "Periods", 14, 1, 200, 1 );
RS= RSI( periods);
Plot( RS, _DEFAULT_NAME(), colorred, ParamStyle("Style")  );

Plot (25, "Oversold", colorGreen,stylethick);
Plot (75, "Overbought", colorRed,stylethick);

buy = Cross(25,RS);
sell = Cross(RS,75);


shape = Buy * shapehollowsmallcircle + Sell * shapehollowsmallcircle;

PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, RS );

BuyP = LastValue(ValueWhen(Buy,C),1);

SellP = LastValue(ValueWhen(Sell,C),1);;

if(LastValue(Buy))
{

PopupWindow("BUY Order: RSI" + buyp,"Alert", 2, 640*mtRandom(), 480*mtRandom()); 

Filepath  	= "C:/Users/Administrator/Documents/";
Filename  	= Name()+"stock";
fhw = fopen( Filepath + filename + ".txt", "w" );
fputs("BUY-" + BuyP,fhw);
fclose( fhw);


}

if(LastValue(Sell))
{

PopupWindow("SELL Order:RSI" + sellp,"Alert", 2, 640*mtRandom(), 480*mtRandom()); 
Filepath  	= "C:/Users/Administrator/Documents/";
Filename  	= Name()+"stock";
fhw = fopen( Filepath + filename + ".txt", "w" );
fputs("SEL-" + sellP,fhw);
fclose( fhw);
}


_SECTION_END();

Moderator comment: you REALLY need to use Code Tags. We have edited your post but next time, post without code tags will be rejected.

Regards,
Krishnakumar

1 Like

Suggest you try "a" instead of "w". You might also need, "fdelete(fhw);", and to reorganize your code a bit.

Hi, Thanks for your input. will change it.