# Tutorial 144 | Introduce delay to market order entry after average cross

A Gold Pass member was developing an example strategy involving two averages crossing each other to trigger a market buy order. He did not want to have to wait until the next bar to enter the trade but he did not want to enter a market order immediately. He asked how to go about introducing a user input number of ticks between the price where the cross occurs and the level that has to be reached (or exceeded) to place the market buy order.

As a bar develops the values of the averages change as price changes. This means that the lines can cross and uncross each other several times within the bar. The only way to be sure that the lines have crossed is to wait until the end of the bar. A good example of this can be seen below.
Why is XAverage( C, 1 ) the same as Close?

The formula used in the expoenential moving average function is:

if CurrentBar = 1 then XAverage = Price
else XAverage = XAverage[1] + SmoothingFactor * ( Price – XAverage[1] );

If we use XAverage( C, 1 )  then the SmoothingFactor  = 1.

XAverage = XAverage[1] + SmoothingFactor * ( Price – XAverage[1] ) becomes

XAverage = XAverage[1] + 1 * ( Price – XAverage[1] ), i.e.

XAverage = XAverage[1] + Price – XAverage[1]  i.e.

XAverage = XAverage[1] – XAverage[1] + Price i.e.

XAverage = Price

### How tutorial 144 works

Tutorial 144 works by:

• Monitoring the value of the difference between the fast and slow averages on a tick by tick basis
• If the lines cross (i.e. the value of the difference is positive this tick but was negative the previous tick) set a boolean to true and record the value of close in an intrabarpersist variable
• The entry price target is calculated and the market order requires
• The boolean to be true
• The price entry target to be exceeded
• If the fast average crosses below the slow average then the boolean is set to false
This tutorial requires that Use look-inside-bar back-testing is selected with 1 tick resolution and Enable intra bar order generation and calculation is selected. This is demonstrated in the video below.

Watch the overview video below.

The indicator plots the averages. The inputs in the indicator and the strategies are NOT synchronized, i.e. the user needs to make sure that the same averages are being plotted with the indicator as used in the strategies.

### Input

NumTcksAbove( 5 );

The input is an integer that determines how many ticks above the price when the average cross occurs to insitigate a marke buy order.