buy script with spread targeting

 
//+------------------------------------------------------------------+
//|                                              Buy  with SL and TP |
//|                               Copyright © 2008, smjones          |
//|                                               sjcoinc            |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, smjones"
#property link      "sjcoinc2000@yahoo.com"


//#property show_inputs

extern double Lots = 0;
extern bool   UseMoneyMgmt = true;
extern double RiskPercent = 8;
extern bool   UseStop = false;
extern bool   UseTakeProfit = false;
extern double StopLoss = 200;
extern double TakeProfit = 400;
extern string Note="0 in Entry field means Market Order Buy";
extern double Entry = 0.0000;
double  MaxSpread     = 0.0;

string Input = " Buy Price ";



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
  if((Ask-Bid)*10000>MaxSpread) return(0);  
  double Risk = RiskPercent / 100;
  if (UseMoneyMgmt)  
   Lots = NormalizeDouble( AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2); 
  int Mode = OP_BUYSTOP;
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  double SLB = Entry - StopLoss*Point, TPB = Entry + TakeProfit*Point;
  if (UseStop == false) SLB = 0;
  if (UseTakeProfit == false) TPB = 0;
  if(Lots > 0)
   OrderSend(Symbol(),Mode, Lots, Entry, 2,SLB , TPB, "", 0, NULL, LimeGreen);


           
   return(0);
  }
//+------------------------------------------------------------------+
how can I loop this script so that the script would execute a buy order at market when spread drop down to ZERO.  currently is executed once on the chart, but without an open trade; since it's only about 2% chance spread would be at my target of ZERO.
 
double spread = MarketInfo( Symbol(), MODE_SPREAD );

if ( spread == 0 ) {
   //order placement code here
}

As for looping the script, why not use an EA? If you just want it to place an order when the condition is met and then be removed, you could do something like:

while ( spread > 0 ) {
  //...
}

//order placement code here