Trying to develop a New EA... - page 3

 
" should not matter whether its a demo or live account "
 
timdchambers:
" should not matter whether its a demo or live account "
Click edit and add your words. Don't need to post a new one.
 
deysmacro:
Click edit and add your words. Don't need to post a new one.

It's not so important.
 
Yes, I know. XD
 

we need to see the code to solve it

ERR_INVALID_STOPS 130 Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescence. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_INVALID_TRADE_VOLUME 131 Invalid trade volume, error in the volume granularity. All attempts to trade must be stopped, and the program logic must be changed.
 

Ok here is the first EA cross over I typed up, nothing special though a simple moving average cross over executing a BUY and SELL etc

//+------------------------------------------------------------------+
//|                                              anothersimpleEA.mq4 |
//|                                Copyright 2014, TJDesignsolutions |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Iducate Learning Technologies"
#property link      "http://www.metaquotes.net"
#property version   "1.00"
#property strict

extern double TakeProfit=20.0;
extern double Lots=0.1;
extern double StopLoss=10.0;
extern double OutofRange=0;

static int lastDirection=0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int Init()
  {
//---
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int Deinit()
  {
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Start on tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
   
double shortEMA, longEMA;
int currentDirection=0;

shortEMA=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);
longEMA=iMA(NULL,0,25,0,MODE_EMA,PRICE_CLOSE,0);

if(shortEMA>longEMA)
   currentDirection=1;//uptrend
   else
   currentDirection=2;//downtrend

if(lastDirection!=currentDirection){//crossover
   if(currentDirection==1){
      Print("Cross over Up!");
         int ticketNo=0;
         ticketNo=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Point*StopLoss,Ask+TakeProfit*Point,"MyEA",12345,0,Green);
   if(ticketNo<0){
      Print("OrderSend failed with error #",GetLastError());
      return(0);
      }
}
   else if(currentDirection==2){
      Print("Cross over Down!");
         int ticketNo=0;
         ticketNo=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Point*StopLoss,Bid-TakeProfit*Point,"MyEA",12345,0,Red);

   if(ticketNo<0){
      Print("OrderSend failed with error #",GetLastError());
      return(0);
      }
   }    
   /*Code to close trades*/
   int totalOrdersOpened=0;
   totalOrdersOpened=OrdersTotal();
   
   if(totalOrdersOpened>=1){
   for(int count=0;count<totalOrdersOpened;count++){
      //for each opened order
      //select most recent order first
      OrderSelect(count,SELECT_BY_POS,MODE_TRADES);
      
      if(OrderType()==OP_BUY&&currentDirection==2){
      OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
      }
      else if(OrderType()==OP_SELL&&currentDirection==1){
      OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
      }
    }
  }  
}
else{

double gap=shortEMA-longEMA;
      Print("shortEMA="+shortEMA+"longEMA="+longEMA+"Gap"+"="+gap);
      }

lastDirection=currentDirection;

return(0);

}
//---Print("shortEMA of"+shortEMA+"is above longEMA of"+longEMA);
//---else
//---Print("longEMA of"+longEMA+"is above shortEMA of"+shortEMA);
//---return(0);
//---  }
//+------------------------------------------------------------------+
Reason: