My code does not work as I expect (repeated signals)

  1. in realtime i do'nt know why it generates to many signals(sometime).
  2. in real time it gives false signals (sometime).
  3. but when i back test(amibroker) it gives no issue.
  4. i know nothing about programming.
  5. i want to buy just at the close of the signal bar, how can i do that.
_SECTION_BEGIN("RSI Crossover Alert");


SetChartOptions(0,0,chartGrid1|chartGrid100);
periods = Param( "Periods", 14, 1, 200, 1 );
RS= RSI( periods);
Plot( RS, _DEFAULT_NAME(), colorred, ParamStyle("Style")  );

Plot (30, "Oversold", colorGreen,stylethick);
Plot (70, "Overbought", colorGreen,stylethick); 


buy = Cross(30,RS);
sell = Cross(RS,70);

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

/* Prices when Buy, Sell condition is true  */
BuyPrice = ValueWhen(Buy,C);
SellPrice = ValueWhen(Sell,C);




shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes( shape, IIf( Buy, colorGreen, colorGreen ), 0, RS );

AlertIF( Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 1 );
AlertIF( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );




if ( LastValue(Buy) == True )
{
	placeOrderUsingParams(AT_EXCHANGE, AT_SYMBOL, "BUY", AT_ORDER_TYPE, AT_QUANTITY, buyPrice, defaultTriggerPrice(), 1);
}

if ( LastValue(Sell) == True )
{
	placeOrderUsingParams(AT_EXCHANGE, AT_SYMBOL, "SELL", AT_ORDER_TYPE, AT_QUANTITY, sellPrice, defaultTriggerPrice(), 1);
}



_SECTION_END();

The answer already exists on this forum:

Using SEARCH feature allows to find answers without creating duplicate threads.

1 Like

Please use existing thread: Preventing repeatition of trade in LiveAutoTrading