Help to code exit signal only if buy or sell generated previously.

#1
HellO Experts,

I am new to Amibroker, I have learnt a lot from you all. I would like to thank you all for your help and support.
I have one difficulty in coding the exit system in my AFL.. I kindly request everone of you here to try to fix me this. Let me post the code where I struggle..

Exitbuy = Ref( High, -1 ) == exitbu;
Exitsell = Ref( Low , -1 ) == exitse;
BUY = Buycondition AND timeOK;
Sell = Sellcondition AND timeOK;
Cover = Exitsell AND timeOK;
Short = Exitbuy AND timeOK;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover = ExRem(Cover,Short);
Short = ExRem(Short,Cover);
Exitbuy = ExRem(Exitbuy,Exitsell);
Exitsell = ExRem(Exitsell,Exitbuy);



In the above code, I get perfect entry signals (Buy and Sell) and everything works fine... But for exit singals (Cover and Short) I get it even if I dont have entry signals...
I would like to get exit signal of Buy (Short) only if the previous signal is Buy and exit signal of Sell (Cover) only if the previous signal is Sell. I dont want Cover signal (Exit for sell) for buy entry and vice versa.

NOTE: Its beccause the exit signal condition is met at many places. I want it to generate signals only if there is buy or sell signal.

I hope, I have explained it properly.. Please somebody help me... Thanks...
 

Attachments

lemondew

Well-Known Member
#2
Buy opens long position
Sell closes an existing long position
Short opens short position
Cover closes an existing short position

HellO Experts,

I am new to Amibroker, I have learnt a lot from you all. I would like to thank you all for your help and support.
I have one difficulty in coding the exit system in my AFL.. I kindly request everone of you here to try to fix me this. Let me post the code where I struggle..

Exitbuy = Ref( High, -1 ) == exitbu;
Exitsell = Ref( Low , -1 ) == exitse;
BUY = Buycondition AND timeOK;
Sell = Sellcondition AND timeOK;
Cover = Exitsell AND timeOK;
Short = Exitbuy AND timeOK;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover = ExRem(Cover,Short);
Short = ExRem(Short,Cover);
Exitbuy = ExRem(Exitbuy,Exitsell);
Exitsell = ExRem(Exitsell,Exitbuy);



In the above code, I get perfect entry signals (Buy and Sell) and everything works fine... But for exit singals (Cover and Short) I get it even if I dont have entry signals...
I would like to get exit signal of Buy (Short) only if the previous signal is Buy and exit signal of Sell (Cover) only if the previous signal is Sell. I dont want Cover signal (Exit for sell) for buy entry and vice versa.

NOTE: Its beccause the exit signal condition is met at many places. I want it to generate signals only if there is buy or sell signal.

I hope, I have explained it properly.. Please somebody help me... Thanks...
 
#3
Thank you very much for your quick reply.. If I change like that will it solve the problem. Anyhow thanks for your suggestion, I will change it right away. But please help me how we can fix the problem if your solution won't work.
 

lemondew

Well-Known Member
#4
You cant solve a problem before it occurs. You can never know whether a solution will work without applying it and seeing.

By the way can you tell me in advance what will you do if the code that you have written gives you negative returns. Or the next code that you have thought about also gives you negative returns
 
#5
You cant solve a problem before it occurs. You can never know whether a solution will work without applying it and seeing.

By the way can you tell me in advance what will you do if the code that you have written gives you negative returns. Or the next code that you have thought about also gives you negative returns


I understand that bro. I thought I may get late reply so I asked immediately to know any other options if that fails.. Anyway just give me few minutes. I will change it as per your idea and check it. I somehow need solution brother.
 
#6
You cant solve a problem before it occurs. You can never know whether a solution will work without applying it and seeing.

By the way can you tell me in advance what will you do if the code that you have written gives you negative returns. Or the next code that you have thought about also gives you negative returns
Thank you very much Sir.... Now, its okay... Still getting few signals, but I feel its okay... Thanks from bottom of my heart... Will seek for your help if needed after few tests...
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?