This is a two part question: I have 5 variables that I want to use to make buy limit orders (Call them moving averages). My approach to this has been to try and find the closest support point to the current market price and create a limit buy order at that variable support price. Question 1: I have been trying to create code that will tell me what the closest support point is under the current price and put a limit buy order at that price. If that order gets filled then find the new closest variable for a buy price, etc. Is this the best way to accomplish this? Is there some sort of function that will tell me what I need to know? Question 2: Lets say one of the variables is 1142.58. And I do a limit at that price in the ES futures which increments in .25. Will the order be 1142.50 or 1142.75? Also how can you make your order round up to the nearest tick?

The following function will help you round to the nearest tick above or below the number. Code: inputs: price(numericsimple), upordown(numericsimple); if upordown=1 then round2tick=ceiling(price/tick/10)*tick*10 else if upordown=-1 then round2tick=floor(price/tick/10)*tick*10 else round2tick=round(price/tick/10,0)*tick*10; Where the input price is the price you would like to round, and upordown can be a value =1, 0, or 1, meaning floor, round, or ceiling respectively.

Thanks for the replies. I am hoping there is some kind of function that can help me out with the first issue. I have figured out a way to code this but it is very lengthy and not very elegant. I thought what I am trying to accomplish in the first question is a common task in many autotrading programs.

The only problem with that is I need to associate the support/resistance points with a moving average. A moving average is always changing values so if I already bought that moving average I don't want to buy it again.

In the strategy properties you can set the strategy to only execute orders generated by a different entry order. Then you just submit a different order for each s/r level.

But if the S/R's a re moving averages then the orders would change everytime a the moving average changed and could cause multiple entries based on the same S/R variable.

The only way I have figured out to find the closest support point is to first calculate the difference between the close and each variable support point. Then once I have all of those differences I would find the one that is closest to 0 and not negative. Then I would need to associate that closest difference back to the support variable and place the order at that support variable price. ******************************* This seems like such a barbaric way to acheive what I am trying to do. Which is why I am looking for help.

Unless I am misunderstanding what you are trying to do, this is certainly possible. Code: support[0]=average(c,10)+avgtruerange(20); support[1]=average(c,20+avgtruerange(20) support[2]=average(c,30)+avgtruerange(20); support[3]=average(c,40)+avgtruerange(20); support[4]=average(c,50)+avgtruerange(20); resist[0]=average(c,10)-avgtruerange(20); resist[1]=average(c,20)-avgtruerange(20); resist[2]=average(c,30)-avgtruerange(20); resist[3]=average(c,40)-avgtruerange(20); resist[4]=average(c,50)-avgtruerange(20); buy ("resist0") next bar at resist[0] limit; buy ("resist1") next bar at resist[1] limit; buy ("resist2") next bar at resist[2] limit; buy ("resist3") next bar at resist[3] limit; buy ("resist4") next bar at resist[4] limit; Sell short ("support0") next bar at support[0] limit; Sell short ("support1") next bar at support[1] limit; Sell short ("support2") next bar at support[2] limit; Sell short ("support3") next bar at support[3] limit; Sell short ("support4") next bar at support[4] limit; By setting the strategy property to "when the order is generated by a different entry order", it will only allow each order to fill 1 time. For example, the order named resist0 will only be allowed to fill once before it is exited.