Amibroker scan clubbing stocks together

#11
Hello Sardar,

Thank you.

How was your visit to Auroville?

Any idea why this nested conditional write is always returning .. "Neutral"?

Code:
TrendStatus = WriteIf( Close>weightedMA AND Open<weightedMA,"Bullish", WriteIf(Close<weightedMA AND Open>weightedMA, "Bearish", "Neutral" ) );
I will check the code and let you know.

Auroville was good, but that was last year :)


Happy :)
 

trash

Well-Known Member
#12
Any idea why this nested conditional write is always returning .. "Neutral"?

Code:
TrendStatus = WriteIf( Close>weightedMA AND Open<weightedMA,"Bullish", WriteIf(Close<weightedMA AND Open>weightedMA, "Bearish", "Neutral" ) );
View attachment 25938
You should carefully read the documentation. All is explained there already.
https://www.amibroker.com/guide/afl/writeif.html
WriteIf does not return array of strings but single string
Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION
Instead of AddTextColumn and WriteIf you have to use AddMultiTextColumn function.
094507.png
 

pannet1

Well-Known Member
#13
hi @trash

I used AddMultiTextColumn but still could not get the result you posted below. Can you please provide the changes you made to the code.

Here is the changes i made
Code:
IIf(Close>weightedMA AND Open<weightedMA,TrendSelector=1, IIf(Close<weightedMA AND Open>weightedMA, TrendSelector=2, TrendSelector=0)  );
TextList = "No signal\nBuy\nSell";
AddMultiTextColumn( TrendSelector, TextList, "Trend" );




You should carefully read the documentation. All is explained there already.
https://www.amibroker.com/guide/afl/writeif.html
WriteIf does not return array of strings but single string


Instead of AddTextColumn and WriteIf you have to use AddMultiTextColumn function.
View attachment 25955
 

travi

Well-Known Member
#14
Any idea why this nested conditional write is always returning .. "Neutral"?
Following code is working properly in my AB.

Code:
_SECTION_BEGIN("Weighted65");
// Weighted Moving Average on Average price
weightedMA = WMA(Avg, 65);

TrendBull = IIf(Close>weightedMA AND Open<weightedMA,1,0);
TrendBear = IIf(Close<weightedMA AND Open>weightedMA,1,0);

TrendColor = IIf(TrendBull,colorGreen, IIf(TrendBear, colorRed, colorGrey40));

Filter = TrendBull OR TrendBear;

// AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddColumn(O,"Open",1,IIf(O>Ref(O,-1),colorGreen,colorRed));
AddColumn(weightedMA ,"WMA", 1, colorBlack);
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddTextColumn(WriteIf(TrendBull,"Bullish", WriteIf(TrendBear,"Bearish","Neutral")),"Trend",1.2,colorWhite,TrendColor);
_SECTION_END();
 

pannet1

Well-Known Member
#15
Following code is working properly in my AB.

Code:
_SECTION_BEGIN("Weighted65");
// Weighted Moving Average on Average price
weightedMA = WMA(Avg, 65);

TrendBull = IIf(Close>weightedMA AND Open<weightedMA,1,0);
TrendBear = IIf(Close<weightedMA AND Open>weightedMA,1,0);

TrendColor = IIf(TrendBull,colorGreen, IIf(TrendBear, colorRed, colorGrey40));

Filter = TrendBull OR TrendBear;

// AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddColumn(O,"Open",1,IIf(O>Ref(O,-1),colorGreen,colorRed));
AddColumn(weightedMA ,"WMA", 1, colorBlack);
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddTextColumn(WriteIf(TrendBull,"Bullish", WriteIf(TrendBear,"Bearish","Neutral")),"Trend",1.2,colorWhite,TrendColor);
_SECTION_END();
hi ravi,

i copied your code. sorry look at the text in the trend column

1528809342815.png
 

pannet1

Well-Known Member
#17
o_O
i made following changes to the code and it worked now... thanks @travi @trash @Happy_Singh ... awesome guys.


Code:
TextList = "Neutral\nBullish\nBearish";
TrendSelection = 0 + 1 * TrendBull + 2 * TrendBear;
AddMultiTextColumn(TrendSelection, TextList, "trend", 1.2, colorWhite, TrendColor);
 

pannet1

Well-Known Member
#18
Filter only the first 2 bars of the 5Min timeframe

I want to UP this a little bit ... for day today purpose its fine .... but when i am doing a manual backtesting ... i want to only consider those crossovers that happened from 9:15 Hrs to 9:25 Hrs. How to achieve that. Well here is an attempt .... but it did not work

Code:
tn = TimeNum();
startTime = 91500; // start in HHMMSS format
endTime = 925000;  // end in HHMMSS format
timeOK = tn >= startTime AND tn <= endTime;

// some code removed for brevity
Filter = TrendBull OR TrendBear AND timeOK;