Need Help on Straddle advisor

 
The advisor does not put the Straddle (buy and sell) in at the proper time on InterbankFX charts. It was programmed it to put in a Buy Stop and Sell Stop simotaniously at the TimeAHour, TimeAMin. Can someone help with the problem?? I am willing to give the strategy once fixed I use to one who fixes it that I use live trading now averaging 15 pips per day.


extern double Lots=0.1;
extern int Slippage=3;
extern bool UseDST=false;

extern string EAName = "NewsTrader v2";
extern int MagicNumber = 6541;
extern int MaxTrades = 1;

extern int GMTShift=0;

extern int TimeAHour=1;
extern int TimeAMin=33;

extern int LiveHour=0;
extern int LiveMin=15;

extern int MaxOpenTradeHours = 0;
extern int MaxOpenTradeMin = 19;
extern bool UseMaxOpenTradeTime=false;

//extern int LookBackHour = 0;
//extern int LookBackMin = 15;

extern int BuyStretchPips = 10;
extern int SellStretchPips=10;

extern double ProfitPips = 30;
extern double StopPips = 30;
extern int TrailStartPips=30;
extern int TrailStopPips=30;

extern bool MM = false; //Use Money Management or not
extern int Risk = 10; //%  per trade
extern int PipValue = 10; //Value of 1 pip in Dollars

bool runnable=true;
bool init=true;

datetime timeprev=0;

double price, prcopp;
datetime expiration, exittime;
int ChartPeriod, LookBack, AdjustedEntryHourA;
double Op, Hi, Lo, Cl, Range, Stop, Profit, Spread;
double LongEntry, ShortEntry;
double BuyStretch, SellStretch; 
double iLots;
bool BuyInTrade=false, SellInTrade=false;
 
int init()
{
 return(0);
}

int deinit()
{
 return(0);
}

int start()
{
//Runnable
 if(runnable!=true)
  return(-1);
  
 
 DeleteExtraOrder();
 TrailingAlls(TrailStartPips,TrailStopPips);
 
 if(timeprev==Time[0])
  return(0);
 timeprev=Time[0];
 
 if (UseDST)
  AdjustedEntryHourA = USDayLightSavingsAdjustment(TimeAHour);
 else
  AdjustedEntryHourA = TimeAHour;
 
 
 if(UseMaxOpenTradeTime && (Time[0] >= exittime)) CloseAll(MagicNumber);

 if((TimeHour(Time[0])==(AdjustedEntryHourA + GMTShift) && TimeMinute(Time[0])>=TimeAMin) && (CountTrades()<MaxTrades))
//    TimeMinute(Time[0])<=TimeAMin+3) && (CountTrades()<MaxTrades))
// if((TimeMinute(Time[0])==TimeAMin) && (CountTrades()<MaxTrades))
 {
  expiration=Time[0]+(LiveHour*60*60)+(LiveMin*60);
  exittime=Time[0]+(MaxOpenTradeHours*60*60 + MaxOpenTradeMin*60);
  
  Spread = MarketInfo(Symbol(), MODE_SPREAD); //Ask-Bid;
  BuyStretch = NormalizeDouble(BuyStretchPips*Point, Digits);
  SellStretch = NormalizeDouble(SellStretchPips*Point, Digits);

//  ChartPeriod = Period();
//  LookBack = MathCeil(((LookBackHour*60*60)+(LookBackMin*60))/(ChartPeriod*60));
  
//  Hi = iHigh(NULL, 0, Highest(NULL,0,MODE_HIGH,LookBack,1));
//  Lo = iLow(NULL, 0, Lowest(NULL,0, MODE_LOW,LookBack,1));
  
//  Range = Hi - Lo;
  
//  LongEntry = Hi + BuyStretch + Spread;
//  ShortEntry = Lo - SellStretch;   
     
//  LongEntry = Ask + BuyStretch;
//  ShortEntry = Bid - SellStretch; 
  
  Cl = iClose(NULL, 0, 1);
    
  LongEntry = Cl + BuyStretch; // + Spread;
  ShortEntry = Cl - SellStretch; 
  

  if(MM==true) 
   iLots = LotSize(StopPips);
  else
   iLots = Lots;
    
//Long
  price=LongEntry;
  prcopp=LongEntry-Spread;
  OpenPendingOrder(OP_BUYSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Green);
  BuyInTrade=false;
//Shrt
  price=ShortEntry;
  prcopp=ShortEntry+Spread;
//  OrderSend(Symbol(),OP_SELLSTOP,Lots,price,Slippage,StopShrt(prcopp,StopLoss),TakeShrt(price,TakeProfit),EAName,MagicNumber,expiration,Red);
  OpenPendingOrder(OP_SELLSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Red);
  SellInTrade=false;
 }//Open Pending

 
 return(0);
}

double StopLong(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price-(stop*Point));
}

double StopShort(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price+(stop*Point));
}

double TakeLong(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price+(take*Point));
}

double TakeShort(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price-(take*Point));
}


void TrailingAlls(int start,int stop)
{
 int profit;
 double stoptrade;
 double stopcal;
 
 if(stop==0)
  return;
 
 int trade;
 int trades=;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
   continue;

  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;

  if(OrderType()==OP_BUYSTOP)
  {
   profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Bid-(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
  }//Long
  
  if(OrderType()==OP_SELLSTOP)
  {
   profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Ask+(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
  }//Shrt
  
 }//for
}


void CloseAll(int MagicNum)
{
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

  if(OrderSymbol()!=Symbol())
   continue;
  if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNum)
  {
   if(OrderType()==OP_BUY)
    OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);

   if(OrderType()==OP_SELL)
    OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
  }
 }
}

int OpenPendingOrder(int pType,double pLots,double pLevel,int sp, double pr, int sl, int tp,string pComment,int pMagic,datetime pExpiration,color pColor)
{
  int ticket=0;
  int err=0;
  int c = 0;
  int NumberOfTries = 100;
  switch (pType)
  {
      case OP_BUYLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYLIMIT,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         }   
         break;
      case OP_BUYSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYSTOP,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLLIMIT,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLSTOP,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
  } 
  
  return(ticket);
}  

// ---- Money Management

double LotSize(double StopLossInPips)
{
//   if ( flag ) Lotsi=NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1);   
   double lotMM = MathCeil(AccountFreeMargin() * (Risk) / 10000) / 10;
//   double lotMM = NormalizeDouble((Lots*AccountFreeMargin()*Risk/100)/(StopLossInPips*PipValue), 1);
//   double lotMM = MathCeil(AccountFreeMargin() * Risk /(100* 100))/10;
   if (lotMM < 0.1) lotMM = Lots;
//   if (lotMM > 1.0) lotMM = MathCeil(lotMM);
   if  (lotMM > 100) lotMM = 100;
   return (lotMM);
} 

int CountTrades()
{
 int count=0;
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if((OrderType()==OP_SELL) || (OrderType()==OP_BUY) || 
     (OrderType()==OP_SELLSTOP) || (OrderType()==OP_BUYSTOP))
   count++;
 }//for
 return(count);
}

void DeleteExtraOrder()
{
    int cnt, mode;
    int total = OrdersTotal();
//    for (cnt=0;cnt<total;cnt++)
    for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
    { 
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
      mode=OrderType();
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && 
                              TimeDay(OrderOpenTime()) == TimeDay(CurTime()))     
        {
            if (mode==OP_BUY  && !BuyInTrade ) 
                  BuyInTrade =true;
            if (mode==OP_SELL && !SellInTrade ) 
                  SellInTrade=true;
            
            if (mode == OP_SELLSTOP && BuyInTrade )
            { OrderDelete(OrderTicket()); SellInTrade=false; Print(" ExtraSell"); }
            if (mode == OP_BUYSTOP && SellInTrade )
            { OrderDelete(OrderTicket()); BuyInTrade=false; Print(" ExtraBuy"); }
    
	     }
	 }        
}

int USDayLightSavingsAdjustment(int HourUsed)
{
   int DST = 0;
   
   if (Month() > 4 && Month() < 10) {
      DST = 1;
   } else if (Month() == 4) {
      if ((Day() - DayOfWeek()) > 0) {
         DST = 1;
      }
   } else if (Month() == 10) {
      if (Day() + (7 - DayOfWeek()) <= 31) {
         DST = 1;
      }
   }
   
   if (DST == 1) {
      return (HourUsed - 1);
   } else {
      return (HourUsed);
   }
}
 
What chart size are you wanting to run it on? What time are you experiencing it being placed at?
 
this is to subscribe
 
The advisor does not put the Straddle (buy and sell) in at the proper time on InterbankFX charts. It was programmed it to put in a Buy Stop and Sell Stop simotaniously at the TimeAHour, TimeAMin. Can someone help with the problem?? I am willing to give the strategy once fixed I use to one who fixes it that I use live trading now averaging 15 pips per day.


extern double Lots=0.1;
extern int Slippage=3;
extern bool UseDST=false;

extern string EAName = "NewsTrader v2";
extern int MagicNumber = 6541;
extern int MaxTrades = 1;

extern int GMTShift=0;

extern int TimeAHour=1;
extern int TimeAMin=33;

extern int LiveHour=0;
extern int LiveMin=15;

extern int MaxOpenTradeHours = 0;
extern int MaxOpenTradeMin = 19;
extern bool UseMaxOpenTradeTime=false;

//extern int LookBackHour = 0;
//extern int LookBackMin = 15;

extern int BuyStretchPips = 10;
extern int SellStretchPips=10;

extern double ProfitPips = 30;
extern double StopPips = 30;
extern int TrailStartPips=30;
extern int TrailStopPips=30;

extern bool MM = false; //Use Money Management or not
extern int Risk = 10; //%  per trade
extern int PipValue = 10; //Value of 1 pip in Dollars

bool runnable=true;
bool init=true;

datetime timeprev=0;

double price, prcopp;
datetime expiration, exittime;
int ChartPeriod, LookBack, AdjustedEntryHourA;
double Op, Hi, Lo, Cl, Range, Stop, Profit, Spread;
double LongEntry, ShortEntry;
double BuyStretch, SellStretch; 
double iLots;
bool BuyInTrade=false, SellInTrade=false;
 
int init()
{
 return(0);
}

int deinit()
{
 return(0);
}

int start()
{
//Runnable
 if(runnable!=true)
  return(-1);
  
 
 DeleteExtraOrder();
 TrailingAlls(TrailStartPips,TrailStopPips);
 
 if(timeprev==Time[0])
  return(0);
 timeprev=Time[0];
 
 if (UseDST)
  AdjustedEntryHourA = USDayLightSavingsAdjustment(TimeAHour);
 else
  AdjustedEntryHourA = TimeAHour;
 
 
 if(UseMaxOpenTradeTime && (Time[0] >= exittime)) CloseAll(MagicNumber);

 if((TimeHour(Time[0])==(AdjustedEntryHourA + GMTShift) && TimeMinute(Time[0])>=TimeAMin) && (CountTrades()<MaxTrades))
//    TimeMinute(Time[0])<=TimeAMin+3) && (CountTrades()<MaxTrades))
// if((TimeMinute(Time[0])==TimeAMin) && (CountTrades()<MaxTrades))
 {
  expiration=Time[0]+(LiveHour*60*60)+(LiveMin*60);
  exittime=Time[0]+(MaxOpenTradeHours*60*60 + MaxOpenTradeMin*60);
  
  Spread = MarketInfo(Symbol(), MODE_SPREAD); //Ask-Bid;
  BuyStretch = NormalizeDouble(BuyStretchPips*Point, Digits);
  SellStretch = NormalizeDouble(SellStretchPips*Point, Digits);

//  ChartPeriod = Period();
//  LookBack = MathCeil(((LookBackHour*60*60)+(LookBackMin*60))/(ChartPeriod*60));
  
//  Hi = iHigh(NULL, 0, Highest(NULL,0,MODE_HIGH,LookBack,1));
//  Lo = iLow(NULL, 0, Lowest(NULL,0, MODE_LOW,LookBack,1));
  
//  Range = Hi - Lo;
  
//  LongEntry = Hi + BuyStretch + Spread;
//  ShortEntry = Lo - SellStretch;   
     
//  LongEntry = Ask + BuyStretch;
//  ShortEntry = Bid - SellStretch; 
  
  Cl = iClose(NULL, 0, 1);
    
  LongEntry = Cl + BuyStretch; // + Spread;
  ShortEntry = Cl - SellStretch; 
  

  if(MM==true) 
   iLots = LotSize(StopPips);
  else
   iLots = Lots;
    
//Long
  price=LongEntry;
  prcopp=LongEntry-Spread;
  OpenPendingOrder(OP_BUYSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Green);
  BuyInTrade=false;
//Shrt
  price=ShortEntry;
  prcopp=ShortEntry+Spread;
//  OrderSend(Symbol(),OP_SELLSTOP,Lots,price,Slippage,StopShrt(prcopp,StopLoss),TakeShrt(price,TakeProfit),EAName,MagicNumber,expiration,Red);
  OpenPendingOrder(OP_SELLSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Red);
  SellInTrade=false;
 }//Open Pending

 
 return(0);
}

double StopLong(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price-(stop*Point));
}

double StopShort(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price+(stop*Point));
}

double TakeLong(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price+(take*Point));
}

double TakeShort(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price-(take*Point));
}


void TrailingAlls(int start,int stop)
{
 int profit;
 double stoptrade;
 double stopcal;
 
 if(stop==0)
  return;
 
 int trade;
 int trades=;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
   continue;

  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;

  if(OrderType()==OP_BUYSTOP)
  {
   profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Bid-(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
  }//Long
  
  if(OrderType()==OP_SELLSTOP)
  {
   profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Ask+(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
  }//Shrt
  
 }//for
}


void CloseAll(int MagicNum)
{
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

  if(OrderSymbol()!=Symbol())
   continue;
  if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNum)
  {
   if(OrderType()==OP_BUY)
    OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);

   if(OrderType()==OP_SELL)
    OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
  }
 }
}

int OpenPendingOrder(int pType,double pLots,double pLevel,int sp, double pr, int sl, int tp,string pComment,int pMagic,datetime pExpiration,color pColor)
{
  int ticket=0;
  int err=0;
  int c = 0;
  int NumberOfTries = 100;
  switch (pType)
  {
      case OP_BUYLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYLIMIT,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         }   
         break;
      case OP_BUYSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYSTOP,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLLIMIT,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLSTOP,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
  } 
  
  return(ticket);
}  

// ---- Money Management

double LotSize(double StopLossInPips)
{
//   if ( flag ) Lotsi=NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1);   
   double lotMM = MathCeil(AccountFreeMargin() * (Risk) / 10000) / 10;
//   double lotMM = NormalizeDouble((Lots*AccountFreeMargin()*Risk/100)/(StopLossInPips*PipValue), 1);
//   double lotMM = MathCeil(AccountFreeMargin() * Risk /(100* 100))/10;
   if (lotMM < 0.1) lotMM = Lots;
//   if (lotMM > 1.0) lotMM = MathCeil(lotMM);
   if  (lotMM > 100) lotMM = 100;
   return (lotMM);
} 

int CountTrades()
{
 int count=0;
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if((OrderType()==OP_SELL) || (OrderType()==OP_BUY) || 
     (OrderType()==OP_SELLSTOP) || (OrderType()==OP_BUYSTOP))
   count++;
 }//for
 return(count);
}

void DeleteExtraOrder()
{
    int cnt, mode;
    int total = OrdersTotal();
//    for (cnt=0;cnt<total;cnt++)
    for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
    { 
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
      mode=OrderType();
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && 
                              TimeDay(OrderOpenTime()) == TimeDay(CurTime()))     
        {
            if (mode==OP_BUY  && !BuyInTrade ) 
                  BuyInTrade =true;
            if (mode==OP_SELL && !SellInTrade ) 
                  SellInTrade=true;
            
            if (mode == OP_SELLSTOP && BuyInTrade )
            { OrderDelete(OrderTicket()); SellInTrade=false; Print(" ExtraSell"); }
            if (mode == OP_BUYSTOP && SellInTrade )
            { OrderDelete(OrderTicket()); BuyInTrade=false; Print(" ExtraBuy"); }
    
	     }
	 }        
}

int USDayLightSavingsAdjustment(int HourUsed)
{
   int DST = 0;
   
   if (Month() > 4 && Month() < 10) {
      DST = 1;
   } else if (Month() == 4) {
      if ((Day() - DayOfWeek()) > 0) {
         DST = 1;
      }
   } else if (Month() == 10) {
      if (Day() + (7 - DayOfWeek()) <= 31) {
         DST = 1;
      }
   }
   
   if (DST == 1) {
      return (HourUsed - 1);
   } else {
      return (HourUsed);
   }
}




I have an idea. I think I have a program that would work for this already. You can email me what you want the program to accomplish and I'll tell you is it will work. The program you have posted seems to be far more complicated than need be. email at josh@wholesaleauthority.com
 
The advisor does not put the Straddle (buy and sell) in at the proper time on InterbankFX charts. It was programmed it to put in a Buy Stop and Sell Stop simotaniously at the TimeAHour, TimeAMin. Can someone help with the problem?? I am willing to give the strategy once fixed I use to one who fixes it that I use live trading now averaging 15 pips per day.


extern double Lots=0.1;
extern int Slippage=3;
extern bool UseDST=false;

extern string EAName = "NewsTrader v2";
extern int MagicNumber = 6541;
extern int MaxTrades = 1;

extern int GMTShift=0;

extern int TimeAHour=1;
extern int TimeAMin=33;

extern int LiveHour=0;
extern int LiveMin=15;

extern int MaxOpenTradeHours = 0;
extern int MaxOpenTradeMin = 19;
extern bool UseMaxOpenTradeTime=false;

//extern int LookBackHour = 0;
//extern int LookBackMin = 15;

extern int BuyStretchPips = 10;
extern int SellStretchPips=10;

extern double ProfitPips = 30;
extern double StopPips = 30;
extern int TrailStartPips=30;
extern int TrailStopPips=30;

extern bool MM = false; //Use Money Management or not
extern int Risk = 10; //%  per trade
extern int PipValue = 10; //Value of 1 pip in Dollars

bool runnable=true;
bool init=true;

datetime timeprev=0;

double price, prcopp;
datetime expiration, exittime;
int ChartPeriod, LookBack, AdjustedEntryHourA;
double Op, Hi, Lo, Cl, Range, Stop, Profit, Spread;
double LongEntry, ShortEntry;
double BuyStretch, SellStretch; 
double iLots;
bool BuyInTrade=false, SellInTrade=false;
 
int init()
{
 return(0);
}

int deinit()
{
 return(0);
}

int start()
{
//Runnable
 if(runnable!=true)
  return(-1);
  
 
 DeleteExtraOrder();
 TrailingAlls(TrailStartPips,TrailStopPips);
 
 if(timeprev==Time[0])
  return(0);
 timeprev=Time[0];
 
 if (UseDST)
  AdjustedEntryHourA = USDayLightSavingsAdjustment(TimeAHour);
 else
  AdjustedEntryHourA = TimeAHour;
 
 
 if(UseMaxOpenTradeTime && (Time[0] >= exittime)) CloseAll(MagicNumber);

 if((TimeHour(Time[0])==(AdjustedEntryHourA + GMTShift) && TimeMinute(Time[0])>=TimeAMin) && (CountTrades()<MaxTrades))
//    TimeMinute(Time[0])<=TimeAMin+3) && (CountTrades()<MaxTrades))
// if((TimeMinute(Time[0])==TimeAMin) && (CountTrades()<MaxTrades))
 {
  expiration=Time[0]+(LiveHour*60*60)+(LiveMin*60);
  exittime=Time[0]+(MaxOpenTradeHours*60*60 + MaxOpenTradeMin*60);
  
  Spread = MarketInfo(Symbol(), MODE_SPREAD); //Ask-Bid;
  BuyStretch = NormalizeDouble(BuyStretchPips*Point, Digits);
  SellStretch = NormalizeDouble(SellStretchPips*Point, Digits);

//  ChartPeriod = Period();
//  LookBack = MathCeil(((LookBackHour*60*60)+(LookBackMin*60))/(ChartPeriod*60));
  
//  Hi = iHigh(NULL, 0, Highest(NULL,0,MODE_HIGH,LookBack,1));
//  Lo = iLow(NULL, 0, Lowest(NULL,0, MODE_LOW,LookBack,1));
  
//  Range = Hi - Lo;
  
//  LongEntry = Hi + BuyStretch + Spread;
//  ShortEntry = Lo - SellStretch;   
     
//  LongEntry = Ask + BuyStretch;
//  ShortEntry = Bid - SellStretch; 
  
  Cl = iClose(NULL, 0, 1);
    
  LongEntry = Cl + BuyStretch; // + Spread;
  ShortEntry = Cl - SellStretch; 
  

  if(MM==true) 
   iLots = LotSize(StopPips);
  else
   iLots = Lots;
    
//Long
  price=LongEntry;
  prcopp=LongEntry-Spread;
  OpenPendingOrder(OP_BUYSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Green);
  BuyInTrade=false;
//Shrt
  price=ShortEntry;
  prcopp=ShortEntry+Spread;
//  OrderSend(Symbol(),OP_SELLSTOP,Lots,price,Slippage,StopShrt(prcopp,StopLoss),TakeShrt(price,TakeProfit),EAName,MagicNumber,expiration,Red);
  OpenPendingOrder(OP_SELLSTOP,iLots,price,Slippage,prcopp,StopPips,ProfitPips,EAName,MagicNumber,expiration,Red);
  SellInTrade=false;
 }//Open Pending

 
 return(0);
}

double StopLong(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price-(stop*Point));
}

double StopShort(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price+(stop*Point));
}

double TakeLong(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price+(take*Point));
}

double TakeShort(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price-(take*Point));
}


void TrailingAlls(int start,int stop)
{
 int profit;
 double stoptrade;
 double stopcal;
 
 if(stop==0)
  return;
 
 int trade;
 int trades=;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
   continue;

  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;

  if(OrderType()==OP_BUYSTOP)
  {
   profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Bid-(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
  }//Long
  
  if(OrderType()==OP_SELLSTOP)
  {
   profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
   if(profit<start)
    continue;
   stoptrade=OrderStopLoss();
   stopcal=Ask+(stop*Point);
   if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
    OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
  }//Shrt
  
 }//for
}


void CloseAll(int MagicNum)
{
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

  if(OrderSymbol()!=Symbol())
   continue;
  if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNum)
  {
   if(OrderType()==OP_BUY)
    OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);

   if(OrderType()==OP_SELL)
    OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
  }
 }
}

int OpenPendingOrder(int pType,double pLots,double pLevel,int sp, double pr, int sl, int tp,string pComment,int pMagic,datetime pExpiration,color pColor)
{
  int ticket=0;
  int err=0;
  int c = 0;
  int NumberOfTries = 100;
  switch (pType)
  {
      case OP_BUYLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYLIMIT,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         }   
         break;
      case OP_BUYSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_BUYSTOP,pLots,pLevel,sp,StopLong(pr,sl),TakeLong(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLLIMIT:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLLIMIT,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
      case OP_SELLSTOP:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            ticket=OrderSend(Symbol(),OP_SELLSTOP,pLots,pLevel,sp,StopShort(pr,sl),TakeShort(pLevel,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  break;
               }  
            }
         } 
         break;
  } 
  
  return(ticket);
}  

// ---- Money Management

double LotSize(double StopLossInPips)
{
//   if ( flag ) Lotsi=NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1);   
   double lotMM = MathCeil(AccountFreeMargin() * (Risk) / 10000) / 10;
//   double lotMM = NormalizeDouble((Lots*AccountFreeMargin()*Risk/100)/(StopLossInPips*PipValue), 1);
//   double lotMM = MathCeil(AccountFreeMargin() * Risk /(100* 100))/10;
   if (lotMM < 0.1) lotMM = Lots;
//   if (lotMM > 1.0) lotMM = MathCeil(lotMM);
   if  (lotMM > 100) lotMM = 100;
   return (lotMM);
} 

int CountTrades()
{
 int count=0;
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if((OrderType()==OP_SELL) || (OrderType()==OP_BUY) || 
     (OrderType()==OP_SELLSTOP) || (OrderType()==OP_BUYSTOP))
   count++;
 }//for
 return(count);
}

void DeleteExtraOrder()
{
    int cnt, mode;
    int total = OrdersTotal();
//    for (cnt=0;cnt<total;cnt++)
    for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
    { 
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
      mode=OrderType();
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && 
                              TimeDay(OrderOpenTime()) == TimeDay(CurTime()))     
        {
            if (mode==OP_BUY  && !BuyInTrade ) 
                  BuyInTrade =true;
            if (mode==OP_SELL && !SellInTrade ) 
                  SellInTrade=true;
            
            if (mode == OP_SELLSTOP && BuyInTrade )
            { OrderDelete(OrderTicket()); SellInTrade=false; Print(" ExtraSell"); }
            if (mode == OP_BUYSTOP && SellInTrade )
            { OrderDelete(OrderTicket()); BuyInTrade=false; Print(" ExtraBuy"); }
    
	     }
	 }        
}

int USDayLightSavingsAdjustment(int HourUsed)
{
   int DST = 0;
   
   if (Month() > 4 && Month() < 10) {
      DST = 1;
   } else if (Month() == 4) {
      if ((Day() - DayOfWeek()) > 0) {
         DST = 1;
      }
   } else if (Month() == 10) {
      if (Day() + (7 - DayOfWeek()) <= 31) {
         DST = 1;
      }
   }
   
   if (DST == 1) {
      return (HourUsed - 1);
   } else {
      return (HourUsed);
   }
}




I have an idea. I think I have a program that would work for this already. You can email me what you want the program to accomplish and I'll tell you is it will work. The program you have posted seems to be far more complicated than need be. email at josh@wholesaleauthority.com



I sent you an email from threedist@yahoo.com. Did you get it?? Let me know. Thanks