Use the following snippet. Modify according ot your requirement. Add commas for CSV and Carraige Return/LineFeed characters.
alreadyopenbuy = StaticVarGetText("alreadyopenbuy"+GetChartID());
alreadyopensell = StaticVarGetText("alreadyopensell"+GetChartID());
fh = fopen( "C:\\Users\\Admin\\Desktop\\buysellsignals.txt", "w" );
if ( LastValue(Buy) == True AND alreadyopenbuy == "")
{
StaticVarSetText("alreadyopenbuy"+GetChartID() , "1");
StaticVarSetText("alreadyopensell"+GetChartID() , "");
y = Year();
m = Month();
d = Day();
ds = StrFormat("%02.0f-%02.0f-%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );
qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f\n",
O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
fputs( qs, fh );
}
if ( LastValue(Sell) == True AND alreadyopensell == "")
{
StaticVarSetText("alreadyopenbuy"+GetChartID() , "");
StaticVarSetText("alreadyopensell"+GetChartID() , "1");
y = Year();
m = Month();
d = Day();
ds = StrFormat("%02.0f-%02.0f-%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );
qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f\n",
O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
fputs( qs, fh );
}
fclose(fh);
@ startsystem.
Thanks for your time.
It is writing to file but missing many signals.
I guess it is giving Buy then sell then buy only...
irrespective of symbols..
ACC buy given
RIL buy missed
RELCAP buy missed
YES SELL given
BOI SELL missed
Ibu BUY given
Below is the code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("5/10 EMA TrenNotify");
W=EMA(C,5);
X=EMA(C,10);
Buy = Ref(c, -1)> X AND W>X AND L<X;
Sell = Cross(X, W);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
alreadyopenbuy = StaticVarGetText("alreadyopenbuy"+GetChartID());
alreadyopensell = StaticVarGetText("alreadyopensell"+GetChartID());
fh = fopen( "C:\\Users\\Admn\\Desktop\\tradelog.csv", "a" ); //-----> changed it to csv and "a" append mode, Admn instead of Admin
if(fh)
{
if ( LastValue(Buy) == True AND alreadyopenbuy == "")
{
StaticVarSetText("alreadyopenbuy"+GetChartID() , "1");
StaticVarSetText("alreadyopensell"+GetChartID() , "");
fputs( "BUY" + " ," + Name() + " ," +Close+ "\n", fh );
}
if ( LastValue(Sell) == True AND alreadyopensell == "")
{
StaticVarSetText("alreadyopenbuy"+GetChartID() , "");
StaticVarSetText("alreadyopensell"+GetChartID() , "1");
fputs( "SELL" + " ," + Name() + " ," +Close+ "\n", fh );
}
fclose(fh);
}
else
{
_TRACE("Failed to open the file");
}
remark = "SELL" + " " + Name() + " " +Close;
AlertIf(BUY,"",remark,1,1+2+4+8,0);
barcomplete = Barindex() < lastvalue(Barindex());
AlertIf(barcomplete AND Sell,"",remark,2);
Filter=Buy OR Sell;
AddColumn(Buy,"BUY",1.2);
AddColumn(Sell,"SELL",1.2);
PlotShapes( shapeUpArrow*Buy, colorGreen,0, L, -20);
PlotShapes( shapeDownArrow*Sell, colorRed,0,H, -20) ;
Plot(EMA(Close,5),"5-EMA",colorOrange,styleLine);
Plot(EMA(Close,10),"10-EMA",colorGreen,styleLine);
_SECTION_END();
///////////////////////////
Sorry to bother you again.
Thank you