Help with ExRem function in Amibroker

#1
Hi,
I have a doubt. Can you please clarify?
While using ExRem function, it is supposed to remove extra buy sell signals. What it does is, it will plot only alternate buy sell signals.
When trying to code intraday system, I dont want the extra signals, but want the FIRST signal of the day. now suppose a buy signal was formed yesterday, and a buy signal is again formed today, the ExRem function deletes that Buy signal, whereas it should be a valid signal, as it is formed next day of the previous buy signal.
Anyone have any idea around this problem?

Thanks
 

Rajvir

Active Member
#2
write this at start of AFL

_SECTION_BEGIN("Time Num");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

_SECTION_END();


Then write sell and cover condition like this

Sell = sell condition OR Short OR Timenum() > 152500 ;
Cover = cover condition OR Buy OR Timenum() > 152500;

Buy= ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
 
#3
Thanks Rajvir.

It solves the purpose of taking only the first signal of the day. However, it is also plotting buy/sell arrows at the end of each day. I think it may be because of "OR Timenum() > 152500"

Thanks
 

trash

Well-Known Member
#4
This example should work

Code:
dtnum  = DateNum();
Buysig = Cross( CCI(20), 100 );
Buysum = Sum( Buysig, BarsSince( dtnum != Ref(dtnum, -1)) + 1); //Only one trade per Day
Buy    = Buysum AND Ref(Buysum, -1) == 0;                       //Only one trade per Day

BuyPrice = Close;
Sell  = 0; 
Short = 0;
Cover = 0;

ApplyStop( stopTypeProfit, stopModePoint, 30, 1, 0 );
ApplyStop( stopTypeLoss, stopModePoint, 30, 1, 0);
Do you wanna exit at the same day, so max sell at close of the day?
 
#5
Hi Trash,

Thanks for the code. It did solve 95% of the problem.
This code will generate only the first Buy and Sell signals in the day, right. If sequence is Buy - Sell - Buy, then the second Buy will not be formed. Is is right?

Thanks
 

trash

Well-Known Member
#6
Hi Trash,

Thanks for the code. It did solve 95% of the problem.
This code will generate only the first Buy and Sell signals in the day, right. If sequence is Buy - Sell - Buy, then the second Buy will not be formed. Is is right?

Thanks

The next buy is triggered next day (depending on Sell or in this case applystop trigger).
 
Last edited:

sikandar

Active Member
#7
write this at start of AFL

_SECTION_BEGIN("Time Num");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

_SECTION_END();
Hi Rajvir
If we want start bars from yesterday or day before yesterday how can we code need a help.

if we want volume waited average price from yestedays first bar how do we do that
:)
 
#8
Hi in the below code:
My Stop Loss is low of past five candles and it's getting updating entire time , which I don't want. My SL should remaim static once position is taken. Kindly help on this.
Buy = 0;

Short = 0;

Sell = 0;

Cover = 0;



Buy = PriceActionCriteriaLong AND Status("BarInRAnge") AND TimeNum()<150500;

Short = PriceActionCriteriaShort AND Status("BarInRAnge") AND TimeNum()<150500;



Buy = (ExRem(Buy, Sell));

Short = (ExRem(Short,Cover));





BuyPrice = iif(Buy==1,ValueWhen(Buy,Close,1),Null);

Stoplevelbuy = 0;

Targetlevelbuy = 0;



Stoplevelbuy = ValueWhen(Buy,LLV(Low,5)-1.2*ATR(21),1);

Targetlevelbuy = ValueWhen(Buy,BuyPrice + (BuyPrice-Stoplevelbuy )*8,1);

StopBuy = Cross(Stoplevelbuy,Low);

TargetBuy = Cross(High,Targetlevelbuy);



ShortPrice = iif(Short==1,ValueWhen(Short,Close,1),Null);

Stoplevelshort = 0;

Targetlevelshort = 0;



Stoplevelshort = ValueWhen(Short,HHV(High,5)+1.2*ATR(21),1);

TargetlevelShort = ValueWhen(Short,ShortPrice-(Stoplevelshort-ShortPrice)*8,1);

StopShort = Cross(High,Stoplevelshort);

TargetShort = Cross(TargetlevelShort,Low);





Sell = IIf((Sum(Buy,BarsOfDay)-Sum(Sell,BarsofDay))>0, (StopBuy OR TargetBuy OR TimeNum()>151300),0) AND Status("BarInRAnge");

Cover =IIf((Sum(Short,BarsOfDay)-Sum(Cover,BarsofDay))>0,(StopShort OR TargetShort or TimeNum()>151300),0) AND Status("BarInRAnge");



/*

Sell = (StopBuy OR TargetBuy OR TimeNum()>151300) AND Status("BarInRAnge");

Cover = (StopShort OR TargetShort or TimeNum()>151300) AND Status("BarInRAnge");

*/



Filter = Buy OR Sell OR Cover OR Short;



Sell = Exrem(Sell,Buy);

Cover = Exrem(Cover,Short);

Buy = (ExRem(Buy, Sell));

Short = (ExRem(Short,Cover));
 

Similar threads