Help with my EA. - page 4

 
whroeder1:

If you had bothered to read the second link provided in #20.6 you would see that my synthetic PIP starts with tick size.

I've bothered to read your link but you haven't answered my question. Is there a reason for using the name "PIP"? I think the TickSize is enough, isn't it? I think PIP isn't used in Indexes, Metals...
 

UPDATE:

Hey all! thank's A LOT for the help, I managed to make the EA work combining some of the suggestions and some things that I came up to, for example the TP and SL levels to be able to either close on opposite or have a fixed SL and TP

The new issue is this: The EA only opens buy orders, not sure what's wrong on the sell section code, I made a walk-around putting the Sell order after the successful close of the buy orders, but I want to clean that part and make it work on the section is intended to make the sell.

Here's the updated code:

extern int MagicNumber = 76526226;
extern int MASlow   = 30;
extern int MAFast   = 25;
extern int MASignal = 10;
extern double Lots  = 0.01;
extern int Slippage = 10;
extern double StopLoss = 30; // StopLoss (0 = Cerrar en señal contraria).
extern double TakeProfit = 30; // TakeProfit (0 = Cerrar en señal contraria).
enum Digitos_Broker
      {
         Cuatro, //Cuatro Digitos
         Cinco  //Cinco Digitos
        };
input Digitos_Broker Digitos = Cinco; // Digitos en el brokker. 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  { 
//====Conversion de 4 a 5 digitos====//

   double Pips = Point;
 if(Digitos == Cinco)
   {
     Pips = Point*10;
    }
  else if(Digitos == Cuatro)
   {
      Pips = Point;
    }  
//====Variables=====//
    
    double SlowMA = iMA(Symbol(),Period(),MASlow,0,MODE_LWMA,PRICE_CLOSE,1);
    double FastMA = iMA(Symbol(),Period(),MAFast,0,MODE_LWMA,PRICE_CLOSE,1);
    double SignalMA = iMA(Symbol(),Period(),MASignal,0,MODE_LWMA,PRICE_CLOSE,1);
    double PrevSlowMA = iMA(Symbol(),Period(),MASlow,0,MODE_LWMA,PRICE_CLOSE,2);
    double PrevFastMA = iMA(Symbol(),Period(),MAFast,0,MODE_LWMA,PRICE_CLOSE,2);
    double PrevSignalMA = iMA(Symbol(),Period(),MASignal,0,MODE_LWMA,PRICE_CLOSE,2); 
         
    static int ticket = 0;

//====SL/TP o Cerrar en entrada opuesta====//

double BuyTakeProfitLevel = TakeProfit;
double SellTakeProfitLevel = TakeProfit;
double BuyStopLossLevel = StopLoss;
double SellStopLossLevel = StopLoss;

//====TP====//

 if(TakeProfit > 0)
   {
      BuyTakeProfitLevel = Bid+TakeProfit*Pips;
      SellTakeProfitLevel = Ask-TakeProfit*Pips;      
    }
    
  else if(TakeProfit == 0)
   {
      BuyTakeProfitLevel = 0;
      SellTakeProfitLevel = 0;
    }
//====SL====//

 if(StopLoss > 0)
   {
      BuyStopLossLevel = Bid-StopLoss*Pips;
      SellStopLossLevel = Ask+StopLoss*Pips;
      
    }
    
  else if(StopLoss == 0)
   {
      BuyStopLossLevel = 0;
      SellStopLossLevel = 0;
    }

//====Slippage====//

int SlippageLevel = Slippage;
 if(Digitos == Cinco)
   {
      SlippageLevel = Slippage*Pips;
    }
   else if(Digitos == Cuatro)
   {
  SlippageLevel = Slippage;
  }
    
//=====Revisar trades=====// 
   
 bool res;
 res = OrderSelect(ticket,SELECT_BY_TICKET);
 
//====Enviar trades====// 
       
      if(!res)
      { 
       if (SignalMA > FastMA && SignalMA > SlowMA && !(PrevSignalMA > PrevFastMA && PrevSignalMA > PrevSlowMA))
        {
         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,SlippageLevel,BuyStopLossLevel,BuyTakeProfitLevel,"RKSDTV",MagicNumber);
               
          if(ticket < 0)
           {
            Alert("Error enviando orden de compra");
            Alert("Codigo del error: ",GetLastError());
           }
          } 
        else if (SignalMA < FastMA && SignalMA < SlowMA && !(PrevSignalMA < PrevFastMA && PrevSignalMA < PrevSlowMA))
         {
          ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SellStopLossLevel,SellTakeProfitLevel,"RKSDTV",MagicNumber);
           if(ticket < 0 )
            {
             Alert("Error enviando orden de venta");
             Alert("Codigo del error: ",GetLastError());
            }
           }
          }
          
//====Condiciones de salida====//  

   else
   {  
      if(OrderMagicNumber() == MagicNumber && OrderCloseTime() == 0)
       { 
        if(OrderType() == OP_BUY)
       {
        if(SignalMA < FastMA && SignalMA < SlowMA)
         {
           bool res3;
           res3 = OrderClose(ticket,Lots,OrderClosePrice(),50);
           if (res3)
            { 
             ticket = 0;
              ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SellStopLossLevel,SellTakeProfitLevel,"RKSDTV",MagicNumber);
           if(ticket < 0 )
            {
             Alert("Error enviando orden de venta");
             Alert("Codigo del error: ",GetLastError());
            }
             }
            else 
               {
                Alert("Error cerrando orden #",ticket);
                Alert("Codigo del error: ",GetLastError());
                }
           }
         }
        else if(OrderType() == OP_SELL)
        {
         if(SignalMA > FastMA && SignalMA > SlowMA)
          {
            bool res4;
            res4 = OrderClose(ticket,Lots,OrderClosePrice(),50);
             if(res4)
             {
              ticket = 0;
              }
             else 
             {
              Alert("Error cerrando orden #",ticket);
              Alert("Codigo del error: ",GetLastError());
              }
             }
            }
           }     
          }
         }

UPDATE ON COMENT:

Found the error, on the sell conditions I forgot to update to use PrevMA's, EA is working propertly:) thanks all!

 
Petr Nosek:
I've bothered to read your link but you haven't answered my question. Is there a reason for using the name "PIP"? I think the TickSize is enough, isn't it? I think PIP isn't used in Indexes, Metals...
A pip is a convention name used mainly in Forex, it's undefined or unclear for CFDs, Metals and never used in centralized markets (Stocks, Options, Futures...).