Generating Duplicate orders - 1 Hourtimeframe - Rsi above 60

Dear Members and Admin,

Kindly support to remove the excess signal when the RSI is touched 60.
I tried with Exrem and for loop function, but it is not working due to rsi is touching the level 60 in the samebar.

After that i tried with amibroker community, from this i tried with addtocompositive function. still the issue is not resloved.

Kindly support for Reslove this issue. ( Entry = Rsi() > 60 and Exit = Rsi() <60)

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

NEWDAY = Day() != Ref(Day(),-1);
EndDay = (Day()!= Ref(Day(), 1));
Squareoftime =ParamTime("Trade Exit","15:15:00");
Entry_End = ParamTime("Entry End","14:15:00");

MA20 = MA(C,20);
buycondition = O < MA20;
Shortcondition = O > MA20 ;

BUY1 = Ref(buycondition,-2) AND O > MA20;
Short1 = Ref(Shortcondition,-2) AND O < MA20;

RSIB = RSI(15) > 60;
RSIS = RSI(15) < 40;

AddToComposite( RSIB, "~RSIBuy", "V");
Graph0 = RSIBC =  Foreign("~RSIcomp", "V");
AddToComposite( RSIS, "~RSIShort", "V");
Graph0 = RSISC =  Foreign("~RSIcomp", "V");

Buy =  RSIBC  AND Buy1 AND  (TimeNum() <= Entry_End) ; 
Short =  RSISC AND Short1 AND TimeNum() <= Entry_End; 

Cover =BarsSince(Short) AND (TimeNum() >= Squareoftime) ;
Sell = BarsSince(Buy) AND (TimeNum() >= Squareoftime);

BuyPrice = C;
ShortPrice = C;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

Moderator comment: YOU MUST USE CODE TAGS! I added them now, but won't accept any more posts without code tags!

Use Cross function instead or larger than ( > ) / smaller than ( < ) operators if you want to have impulse signals.

RSIB = Cross(RSI(15), 60);
RSIS = Cross(40, RSI(15));

As aside Graph* is obsolete and outdated.
Use Plot instead.

Also I don't see reason to use AddToComposite...

1 Like

Agreed. These are totally useless in that code. Typical "reason" is that user does not know what he is doing and trying to copy random pieces from the Internet, paste them in random order and be surprised it does not work.

Recommended reading for original poster:

As to "duplicate" orders - did you bother to read There are no duplicate orders because duplicate SIGNALS are filtered by the backtester. And no you don't need ExRem for the backtester.
You don't need to test if position is open to issue Sell or Cover because backtester does NOT sell or cover position that is not open. Hence all those BarsSince() calls are redundant and should be removed.

And follow advice given here:

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Dear Fxhrat,

@fxshrat Thanks for your reply. As per your guidance i have used the cross function in the AFL.
still i am facing the below issue.

  1. I am getting the duplicate orders in logwindow even i coded like RSIB = Cross(RSI(15), 60); .
  2. The signal is dispear when the close of bar RSI is below the 60.
    It is leads to only buy order excuted and sell order wont come.


and as you mentioned , addtocomposite is not required for this strategy. now i understand the function of usage.