need help in my EA coding

 

i have his error in my EA code when i try to back test my EA but compiling the EA there no error .

2010.11.25 22:52:02 RAY MA finish inputs: profit=1000; stoplose=1000; lots=0.1;
2010.11.25 22:52:02 TestGenerator: unmatched data error (low value 1.3667 at 2010.11.19 22:45 is not reached from the least timeframe, low price 1.3672 mismatches)
2010.11.25 22:52:02 TestGenerator: unmatched data error (high value 1.3675 at 2010.11.19 22:45 is not reached from the least timeframe, high price 1.3674 mismatches)
2010.11.25 22:52:02 TestGenerator: unmatched data error (low value 1.3672 at 2010.11.19 22:30 is not reached from the least timeframe, low price 1.3672 mismatches)
2010.11.25 22:52:02 TestGenerator: unmatched data error (volume limit 220 at 2010.11.19 22:30 exceeded)
2010.11.25 22:52:02 TestGenerator: unmatched data error (high value 1.3680 at 2010.11.19 22:33 and price 1.3681 mismatched)
2010.11.25 22:52:02 TestGenerator: unmatched data error (high value 1.3680 at 2010.11.19 22:32 and price 1.3681 mismatched)
2010.11.25 22:52:02 TestGenerator: unmatched data error (low value 1.3678 at 2010.11.19 22:15 is not reached from the least timeframe, low price 1.3681 mismatches)
2010.11.25 22:52:02 TestGenerator: unmatched data error (volume limit 318 at 2010.11.19 22:15 exceeded)

i have read the forum most say me it because of lower time frame candle unmatched to higher time frame candle, to solve the problem just download the data of lower time frame and higher time frame so that they match . i did what the forum told me but still counter this error .

i try to forward test my ea to check where the it workable, there no error in starting the ea but no trade was enter . so i think there some problem in my EA coding i hope you guy can help me out

///---- input parameters
extern int profit=1000;
extern int stoplose=1000;
extern double lots=0.1;
string Symb;
int Total;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//+------------------------------------------------------------------+
//|order accounting |
//+------------------------------------------------------------------+
Symb=Symbol(); // Security name
Total=0; // Amount of orders
         for(int i=1; i>=OrdersTotal(); i++) // Loop through orders  
            {
            if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one
               { // Analyzing orders:
                       
                        if (OrderType()>1) // Pending order found
                        {
                        Alert("Pending order detected. EA doesn't work.");
                        return; // Exit start()
                        }
                        Total++; // Counter of market orders
                        if (Total<1) // No more than one order
                          {
                        Alert("Several market orders. EA doesn't work.");
                        return; // Exit start()
                          }
               }
           }               

//+------------------------------------------------------------------+
//|defining trading criteria |
//+------------------------------------------------------------------+

bool
Ans =false, // Server response after closing
Cls_B=false, // Criterion for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn_S=false; // Criterion for opening Sell
int ma15,ma30;
ma15= iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
ma30=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);
         if(ma15>ma30)
         {
            Opn_B=true;
            Cls_S=true;
         }
         if (ma15<ma30)
         {
         Opn_S=true;
         Cls_B=true;
         }

//+------------------------------------------------------------------+
//|condition for closing |
//+------------------------------------------------------------------+
int Ticket, Price, SL, TP, Lot, Tip;
Ticket=OrderTicket(); // Number of selected order
Tip =OrderType(); // Type of selected order
Price =OrderOpenPrice(); // Price of selected order
SL =OrderStopLoss(); // SL of selected order
TP =OrderTakeProfit(); // TP of selected order
Lot =OrderLots(); // Amount of lots

               while(true) // Loop of closing orders
                  {
                  if (Tip==0 && Cls_B==true) // Order Buy is opened..
                    { // criterion to close
                     Alert("Attempt to close Buy ",Ticket,". Waiting for response..");
                     RefreshRates(); // Refresh rates
                     Ans=OrderClose(Ticket,Lot,Bid,2); // Closing Buy
                     if (Ans==true) // Success :)
                     {
                     Alert ("Closed order Buy ",Ticket);
                     break; // Exit closing loop
                     }
                     if (Tip==1 && Cls_S==true) // Order Sell is opened..
                     { // and there is criterion to close
                     Alert("Attempt to close Sell ",Ticket,". Waiting for response..");
                     RefreshRates(); // Refresh rates
                     Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell
                        if (Ans==true) // Success :)
                        {
                        Alert ("Closed order Sell ",Ticket);
                        break; // Exit closing loop
                        }
                     break; // Exit while
                     }
                  }
                }  
// Order value
int Min_Lot, Free, One_Lot,Prots, Step;
double Lots,Lts;
RefreshRates(); // Refresh rates
Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots 
Free =AccountFreeMargin(); // Free margin
One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot
Step =MarketInfo(Symb,MODE_LOTSTEP); // Step is changed

            if (Lots < 0) // If lots are set,
            Lts =Lots; // work with them
            else // % of free margin
            Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening

            if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal
            if (Lts*One_Lot > Free) // Lot larger than free margin
            {
            Alert(" Not enough money for ", Lts," lots");
            return; // Exit start()
            }
//+------------------------------------------------------------------+
//|condition for opening |
//+------------------------------------------------------------------+
      while(true) // Orders closing loop
      {
         if (Total==0 && Opn_B==true) // No new orders +
            { // criterion for opening Buy
            RefreshRates(); // Refresh rates
            SL=Bid - SL*Point; // Calculating SL of opened
            TP=Bid + TP*Point; // Calculating TP of opened
            Alert("Attempt to open Buy. Waiting for response..");
            Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Opening Buy
              if (Ticket < 0) // Success :)
               {
                  Alert ("Opened order Buy ",Ticket);
                  return; // Exit start()
               }

               if (Total==0 && Opn_S==true) // No opened orders +
               { // criterion for opening Sell
               RefreshRates(); // Refresh rates
               SL=Ask+SL*Point; // Calculating SL of opened
               TP=Ask - TP*Point; // Calculating TP of opened
               Alert("Attempt to open Sell. Waiting for response..");
               Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Opening Sell
               if (Ticket < 0) // Success :)
               {
               Alert ("Opened order Sell ",Ticket);
               return; // Exit start()
               }
         }
         
         break; // Exit while
    } //--------------------------------------------------------------- 9 --
   return(0);
}
//+------------------
}
 

DC

Two problems at least

  for(int i=1; i>=OrdersTotal(); i++) // Loop through orders 

should be

  for(int i=0; i<OrdersTotal(); i++) // Loop through orders 

and

if (Total<1) // No more than one order

should be

if (Total>1) // No more than one order

FWIW

-BB-

 
BarrowBoy:

DC

Two problems at least

should be

for(int i=0; i<OrdersTotal(); i++) // Loop through orders 

-BB-

I thought the same at first

c the next line

if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one

It's really not smart but this is what it is

 
if (Total == 1) // No more than one order
 
qjol:

I thought the same at first

c the next line

why

if (Total>1) // No more than one order

for(int i=1; i>=OrdersTotal(); i++) so if (OrderSelect(i-1,SELECT_BY_POS)==true)

when i enter a trade i will be -1 in value, i from value of 1 will become 0 if 1 trade is enter

so if (total<1) = no trade

i dont think it wrong

 

Total = 0 at the first plase when u enter in a trade (of course with u condition if OrderType() > 1) then u increase The value of Totol (Total++ (so Total = 1))

then if (total == 1) = //No more than one order

 
qjol:

Total = 0 at the first plase when u enter in a trade (of course with u condition if OrderType() > 1) then u increase The value of Totol (Total++ (so Total = 1))

then if (total == 1) = //No more than one

my ea still cannot work ............. i think there mmore then this problem
 
darkclawer:
my ea still cannot work ............. i think there mmore then this problem

can anyone point of my mistake i make in this ea????? need help plz tell me what wrong i want to learn from it
 

Almost every comparison is wrong way round

e.g.

           if (Lots < 0) // If lots are set, // s/b .. > 0 ..
            Lts =Lots; // work with them
...
           if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal // s/b .. Lts < Min_Lot ..
...  
              if (Ticket < 0) // Success :) // s/b > 0
               {
                  Alert ("Opened order Buy ",Ticket);
                  return; // Exit start()
               }
...
               if (Ticket < 0) // Success :) // s/b > 0
               {
               Alert ("Opened order Sell ",Ticket);
               return; // Exit start()
               }
 

Dear Everybody!

Could somebody do a code which could send me an alarm message when the price reach a given rate?

Best Reguards 

 
parisgirl:

Dear Everybody!

Could somebody do a code which could send me an alarm message when the price reach a given rate?

Best Reguards


double PriceRate = 1.30705;
int Count = 20;

if (MarketInfo(Symbol(),MODE_BID) >= PriceRate)
   {
   if (Count <= 20)
      {
      PlaySound("high.wav");
      Alert ("price reached @ " + Symbol() + " " + PriceRate);
      Count++;
      }
   }
Reason: