I am looking to add limit orders to a mean reversion grid algorithm.

currently my market entrys/entry limits entering from the script :

if ( valley (avPrices, 28.0) )
enterLong(lots, -(c - GridCenterShift*GridStep - l*GridStep), 0, 0);

if ( peak (avPrices, 28.0) )
enterShort(lots, -(c + GridCenterShift*GridStep + l*GridStep), 0, 0);




I have read through the manual about adding limit orders (OrderLimit) to my current entry point and not sure where to get started.

I thought something like this may work?

if ( valley (avPrices, 65.0) )
OrderLimit = -(c - GridCenterShift*GridStep - l*GridStep);
enterLong(lots, OrderLimit, 0, 0);

if ( peak (avPrices, 65.0) )
OrderLimit = -(c + GridCenterShift*GridStep + l*GridStep);
enterShort(lots, OrderLimit, 0, 0);



I would like to add these limit orders at each of my grid levels instead of entering at market.