There is an interesting trading idea. Help me find errors in the code (mql4). - page 17

 
Karputov Vladimir:

Please insert the code correctly:Insert the code correctly in the forum(I have corrected your post).

Added: I also strongly recommend to use code styler - it will help to detect errors(Working with source code: Styler - Program Development).

I will add to strong recommendations to use updated functions

such as

int OnInit()
void OnTick()

and others...

 
vladislavch19:

Please advise where to write or who can help me to correct 2 errors in advisor '}' - unexpected end of program '{' - unbalanced parentheses TMA.mq4



Oooooooooh how many syntactic errors there are.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
extern int   TakeProfit       =100;
extern int   StopLoss         =50;
extern double Lots            = 0.01;
extern int    Slippage        =5;
extern string comment         ="Продажа";
extern int    Megic           = 123;
extern string Indi            = "данные индикатора";
extern string TimeFrame="current time frame";//текущее время кадра
extern int    HalfLength      = 56;
extern int    Price           = PRICE_CLOSE;
extern double ATRMultiplier   = 2.0;
extern int    ATRPeriod       = 100;
extern bool   Interpolate     = true;

double PriceHigh,PriceLow,SL,TP;
int ticket;
bool res;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   if(Digits==3 || Digits==5)
     {
      TakeProfit*=10;
      StopLoss*=10;
      Slippage*=10;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()

  {
   PriceHigh=iCustom(Symbol(),0,"TMA with Distancer",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,1,0);
   PriceLow=iCustom(Symbol(),0,"TMA with Distancer",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,2,0);

   if(Bid>=PriceHigh)
     {
      SL=NormalizeDouble(Bid+StopLoss*Point,Digits);
      TP=NormalizeDouble(Bid-TakeProfit*Point,Digits);

      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,comment,123,0,Maroon);

      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
            res=OrderModify(ticket,OrderOpenPrice(),SL,TP,0);
        }
     }

   if(Ask<PriceLow)
     {
      SL=NormalizeDouble(Ask-StopLoss*Point,Digits);
      TP=NormalizeDouble(Ask+TakeProfit*Point,Digits);

      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,comment,123,0,clrDarkBlue);

      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
            res=OrderModify(ticket,OrderOpenPrice(),SL,TP,0);
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountSell()
  {
   int count=0;
   for(int trede=OrdersTotal()-1;trede>=0;trede--)
     {
      if(OrderSelect(trede,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Megic)
           {
            if(OrderType()==OP_SELL)count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountBuy()
  {
   int count=0;
   for(int trede=OrdersTotal()-1;trede>=0;trede--)
     {
      if(OrderSelect(trede,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Megic)
           {
            if(OrderType()==OP_BUY)count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
 
In the morning decided to bet on the real, but something last option owl does not hold the first options seem to hang, and this 6 flies and reloaded - on the demo then worked well... or it's too good - they don't let it work...))
 
Сергей Криушин:
In the morning decided to bet on the real, but something last option owl does not hold the first options seem to hang, and this 6 flies and reloaded - on the demo then worked well... Or is it too good - don't let it go to work...))
Did a general purge - now standing...cleaned 13 trojans from code... stale MT5...haven't used robot in a while... must have piled up...
 
Сергей Криушин:
In the morning decided to bet on the real, but something last option owl does not hold the first options seem to hang, and this 6 flies and reloaded - on the demo then worked well... or it's too good - they don't let it work...))
d What does it say in the logs when it flies off? I have finished rewriting my EA with mt5 for mt5 today.
 
Sergey Gritsay:
d What does it say in the logs when it flies? I finished rewriting a crossed EA with a martin for mt5 today.
I don't know, I'm afraid to touch it... I'm afraid to touch it... and martin is for risky people, or sell only - bet $1000 - it will pay off handsomely, on my real account today I also made $3 profit... that's good... and if I don't get greedy, I won't probably blow it, so I can open a couple more accounts later... thanks a lot...))
 
Сергей Криушин:

here's the report...and this is the second spurt...

Well what can I say, keep it up.
 
error 'ST' - undeclared identifier test3.mq4 69 13 and possible loss of data due to type conversion test3.mq4 85 15

extern string TMA="Параметры";
extern int   TakeProfit       =100;
extern int   StopLoss         =50;
extern int    Megic           = 123;
extern double Lots            = 0.01;
extern int    Slippage        =5;
extern string TimeFrame       = "current time frame";
extern int    HalfLength      = 56;
extern int    Price           = PRICE_CLOSE;
extern double ATRMultiplier   = 2.0;
extern int    ATRPeriod       = 100;
extern bool   Interpolate     = true;


double PriceHigh,PriceLow,SL,TP;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   if(Digits==3 || Digits==5)
     {

      TakeProfit*=10;
      StopLoss*=10;
      Slippage*=10;
      }
      



                return(INIT_SUCCEEDED);
                
     }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+


//---

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
   void OnTick()
     {
      PriceHigh=iCustom(NULL,0,"TMA_Fair",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,1,0);
      PriceLow=iCustom(NULL,0,"TMA_Fair",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,2,0);

  if(CountBuy()==0 && Ask<=PriceLow)

        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"tma",Megic,0,Blue);
         if(ticket>0)
           {
            TP=NormalizeDouble(Ask+TakeProfit*Point,Digits);
            ST=NormalizeDouble(Ask-StopLoss*Point,Digits);

            if(OrderSelect(ticket,SELECT_BY_TICKET))

              if( OrderModify(ticket,OrderOpenPrice(),ST,TP,0))
                Print("Ошибка");
               }
  
        }

      if(CountSell()==0 && Bid>=PriceHigh)

        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"tma",Megic,0,Red);
         if(ticket>0)
           {
            ST=NormalizeDouble(Bid+StopLoss*Point,Digits);
            TP=NormalizeDouble(Bid-TakeProfit*Point,Digits);

            if(OrderSelect(ticket,SELECT_BY_TICKET))

               if( OrderModify(ticket,OrderOpenPrice(),ST,TP,0))
               Print("Ошибка");
           }
           }
        }
      //+------------------------------------------------------------------+
      int CountSell()
        {
         int count=0;
         for(int trede=OrdersTotal()-1;trede>=0;trede--)
           {
            if(OrderSelect(trede,SELECT_BY_POS,MODE_TRADES))
              {
               if(OrderSymbol()==Symbol() && OrderMagicNumber()==Megic && OrderType()==OP_SELL)

                  count++;
                  
              }
           }
         return(count);
        }

      int CountBuy()
        {
         int count=0;
         for(int trede=OrdersTotal()-1;trede>=0;trede--)
           {
            if(OrderSelect(trede,SELECT_BY_POS,MODE_TRADES))
              {
               if(OrderSymbol()==Symbol() && OrderMagicNumber()==Megic && OrderType()==OP_BUY)

                  count++;
                  
              }
           }
        
      return(count);
     }
//+------------------------------------------------------------------+

 
vladislavch19:
error 'ST' - undeclared identifier test3.mq4 69 13 and possible loss of data due to type conversion test3.mq4 85 15


you have declared one variable name

double PriceHigh,PriceLow,SL,TP;

but you write another one

ST=NormalizeDouble(Ask-StopLoss*Point,Digits);
 

No errors with variables, "thank you".

now it warns possible loss of data due to type conversion test3.mq4 87 15

and in the tester cannot open file 'C:\Users\ÀÀministrator\AppData\Roaming\MetaQuotes\Terminal\F8B0CF1E1FEED3B00D2D7E193237B799\MQL4\indicators\TMA_Fair.ex4' [2]