Dealing with multiple signals in amibroker during formation of candle

Hello, My Question is about Amibroker. I am trading on 15 minute candle. Current bar moving average trend decides whether entry is to be taken or not. The algo i am working on takes buy when currentbar MA is above the previous bar MA.During the formation of candle number of signals are coming and vanishing as the Moving average vis a vis the previous average is more or less than the previous MA. One solution that was mentioned was to base the logic on previous bar i.e either take buy or sell after bar closes…while this appears to solve the problem, lot of price movement is given away. I am looking at a solution to take the signal as the bar is getting formed , but reconcile at the end of the bar, so that if the entry is a whipsaw i come out of it absorbing loss… The question is how to do this in Amibroker. can some one give me a code snippet for this. Thanks in advance.

You can make use of below simple moving average AFL

P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 

Hi …

If U use close Array for your indicator…then during the candle formation.the value of C changes throughout the candle formation…So in sometime during candle formation,Ur Buy/Sell conditions fulfilled…so U got Signal…This is what is called Repainting AFL…

To Avoid Such things…There are two options…

1.Refering Previous Bar…i.e. Ref(Buy,-1)…The problem with this is Price Slippage…i.e.Ur condition is fulfilled at some lower price on Previous Bar but Current Opening of Bar may be Higher (in case of Buy) than the Conditions Price…there by Eating your potion of Profit.

  1. Another method U Can use… Static Variable…to check whether the Previous Bar has some False Signal or NOT if Yes then exit the Position…This Order details cannot be shown in Back test…It works only in Real time where C array is Changing throughout candle formation…But in Static Chart…C is fixed for each bar…so U won’t get any False Signals…

Hello @botoany02

Can you help, how to use Static Variable please . I am struggling to apply code for repainiting. I have some of them but they push my entry and exit to next candle. I want to keep entry and exit same but dont want repainting signals. Can you please tell how to apply static variable.

Thank you in advance.
regards