Iif, WriteIf coding error(s)

The code between the dashed lines in the following Exploration does not work.
I would appreciate receiving advice as to where my error is and the correct coding to display the text......please.

Filter = 0;
FastLine = 12;
SlowLine = 26;

MACDLine = MACD(FastLine, SlowLine);
SignalLine = Signal(FastLine, SlowLine);

GCross = False;
DCross = False;
Buy = False;
Sell = False;
GC = False;
DC = False;

GCross = (Cross(MACDLine, SignalLine) AND IIf (MACDLine < 0.00,1,0) AND IIf (SignalLine <0.00,1,0));
DCross = (Cross(SignalLine, MACDLine) AND IIf(MACDLine > 0.00,1,0) AND IIf(SignalLine > 0.00,1,0));

Buy = IIf(GCross,True,False);
Sell = IIf(DCross,True,False);
//------------------------------------------------------------
GC = ((IIf(Buy AND MACDLine < -0.09, True,False)
OR
IIf(Sell AND MACDLine > 0.09,True,False)));
//-------------------------------------------------------------
ThisCode = Name();

SetOption("NoDefaultColumns",True);
BckColour = colorWhite;
TxtColour = colorBlack;

Filter = Buy OR Sell;

AddTextColumn(Name() ,"Code",1.2,TxtColour,BckColour,100);
AddTextColumn(FullName() ," Full Name ",1.2,TxtColour,BckColour,350);
AddColumn(DateTime()," Date/Time ",formatDateTime,TxtColour,BckColour,185);
AddColumn(C," Close ",1.2,TxtColour,BckColour,120);
AddColumn(MACDLine," MACD ",1.3,TxtColour,BckColour,120);
AddColumn(SignalLine," Signal ",1.3,TxtColour,BckColour,120);
AddColumn(V," Volume ",1.0,TxtColour,BckColour,200);
AddColumn( IIf( Buy, 66, 83 ), "Buy/Sell?",formatChar,TxtColour,BckColour,135) ;

//------------------------------------------------------------
SText = WriteIf(GC,"S"," ");
AddTextColumn(SText,"Strong",formatChar,TxtColour,BckColour,135);
//AddTextColumn((WriteIf(GC,"S"," ")),"Strong",formatChar,TxtColour,BckColour,135);
//------------------------------------------------------------

AddColumn(FastLine," Fast",1.0,TxtColour,BckColour,100);
AddColumn(SlowLine,"Slow",1.0,TxtColour,BckColour,100);

Use Code Block!

See how-to-use-this-site.

image

1 Like
Filter = 0;
FastLine = 12;
SlowLine = 26;

MACDLine = MACD(FastLine, SlowLine);
SignalLine = Signal(FastLine, SlowLine);

GCross = False;
DCross = False;
Buy = False;
Sell = False;
GC = False;
DC = False;

GCross = (Cross(MACDLine, SignalLine) AND IIf (MACDLine < 0.00,1,0) AND IIf (SignalLine <0.00,1,0));
DCross = (Cross(SignalLine, MACDLine) AND IIf(MACDLine > 0.00,1,0) AND IIf(SignalLine > 0.00,1,0));

Buy = IIf(GCross,True,False);
Sell = IIf(DCross,True,False);
//------------------------------------------------------------
GC = ((IIf(Buy AND MACDLine < -0.09, True,False)
	OR
	IIf(Sell AND MACDLine > 0.09,True,False)));
//------------------------------------------------------------- 
ThisCode = Name();	

SetOption("NoDefaultColumns",True);
BckColour = colorWhite;
TxtColour = colorBlack;

Filter = Buy OR Sell;

AddTextColumn(Name() ,"Code",1.2,TxtColour,BckColour,100);
AddTextColumn(FullName() ,"  Full Name  ",1.2,TxtColour,BckColour,350);
AddColumn(DateTime(),"  Date/Time  ",formatDateTime,TxtColour,BckColour,185);
AddColumn(C," Close ",1.2,TxtColour,BckColour,120);
AddColumn(MACDLine," MACD ",1.3,TxtColour,BckColour,120);
AddColumn(SignalLine," Signal ",1.3,TxtColour,BckColour,120);
AddColumn(V,"  Volume  ",1.0,TxtColour,BckColour,200);
AddColumn( IIf( Buy, 66, 83 ), "Buy/Sell?",formatChar,TxtColour,BckColour,135) ;
	
//------------------------------------------------------------
SText = WriteIf(GC,"S"," ");
AddTextColumn(SText,"Strong",formatChar,TxtColour,BckColour,135);
//AddTextColumn((WriteIf(GC,"S"," ")),"Strong",formatChar,TxtColour,BckColour,135);
//------------------------------------------------------------

AddColumn(FastLine," Fast",1.0,TxtColour,BckColour,100);
AddColumn(SlowLine,"Slow",1.0,TxtColour,BckColour,100);

You need to be more specific about your issue.

See how-to-ask-a-good-question.

Also see WriteIf and note that WriteIf returns single string.

Read the Knowledge Base:

All the knowledge you need is there.

That was the first error! :upside_down_face:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.