need help! - page 2

 

Hi,

I finished my code.I did something simple to understand how it works.I had no errors and warnings on meta editor,but after testing on strategy tester I got error 130(invalid stops).Can I get answer ?where is an error in my code and how to fix errors if errors are coming on strategy tester?How to find errors before I try strategy tester if no errors after compiling?

   extern double lot = 1;
extern double stoloss =100;
extern double takeprofit=100;
extern double cci_period=80;
extern double cci_applied_price=0;
extern double cci_prev=0;

 
int start()
  {
     double sl;
     double tp;
     sl    =OrderStopLoss();
     tp    =OrderTakeProfit();
     double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
     
     //---- buy conditions
     
   if(cci_curr > 0 && cci_prev <= 0)  
     {
      OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-sl*Point,Ask+tp*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),0,Green);
      return;
     }
     
     //---- sell conditions
     
   if(cci_curr < 0 && cci_prev >= 0)  
     {
      OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+sl*Point,Bid-tp*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),0,Red);
      return;
     }
       
     //----close condition
     
   for (int i=0; i<OrdersTotal(); i++)
   if (OrderSelect(i,SELECT_BY_POS,MODE_TIME)==true)
   
   //---- check order type 
   
      if(OrderType()==OP_BUY)
      OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
      
      if(OrderType()==OP_SELL)
      OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
     
     
   return(0);
  }
//+------------------------------------------------------------------+
 
Yes invalid stops. Change the code where you set ordersend, to either include not sl and tp but stoploss and takeprofit that you set before start function or change sl and tp variables to take those values instead of OrderStopLoss and OrderTakeProfit. Those 2 functions serve absolutely no function there. They return 0, so you set no sl or tp.
 
WHRoeder:
so look at the log, see the error message, reread my post #3

Hi,

I was trying to ajust my code for 5 digit broker.No errors after compiling,but can you check my errors?Is ajustment for 5 digits in right position in the code?

//+------------------------------------------------------------------+
//|                                                       pirmas.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#define MAGICMA 7777


int     Count=0;
//--- input parameters
extern double    Lots           =0.1;
extern int       Slipage        =5;
extern double    MaximumRisk    = 0.02;
extern string    Order_Comment  ="";
extern double    StopLoss       =100;
extern double    TakeProfit     =100;
extern double    DecreaseFactor = 3;
extern double    MovingShift    = 6;

//+------------------------------------------------------------------+
extern int       cci_period     =80;
extern int       cci_applied_price = 0;


//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+

int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+


void CheckForOpen()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   double cci_prev=iCCI(NULL,0,cci_period,cci_applied_price,1);
   int   res;
//---- buy conditions
   if(cci_curr > 0 && cci_prev <= 0)  
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > 100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > -100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
//---- sell conditions
   if(cci_curr < 0 && cci_prev >= 0)  
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < 100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < -100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
//----
  }

//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
  
//----

  }
  
  int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }}

//+------------------------------------------------------------------+
 
el90ras:
I was trying to ajust my code for 5 digit broker.No errors after compiling,but can you check my errors?Is ajustment for 5 digits in right position in the code?
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,
You didn't change ANYTHING, TP, SL, or slippage. Go back to my previous post #4 and look at the bottom comment.
 
WHRoeder:
You didn't change ANYTHING, TP, SL, or slippage. Go back to my previous post #4 and look at the bottom comment.
I am in trouble.I do not knew where to put it.I was trying diferent places of code and had a lot of errors after compiling.After what part of code ajustment goes in the code?
 

You have to use the values calculated in that code to modify your SL, TP, Slippage accordingly.

If you don't understand the code you have been given it's time to learn and understand it . . . . or simply give up.

 

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
if(Digits==3||Digits==5)                 // error is here in front of if
  {dxPoint=10;Slipage=Slipage*dxPoint;
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
I have error 'if'- semicolon expected in front of if after compilind .What is wrong?
 
el90ras:
I have error 'if'- semicolon expected in front of if after compilind .What is wrong?
int init()
if(Digits==3||Digits==5)                 // error is here in front of if
  {dxPoint=10;Slipage=Slipage*dxPoint;
  1. no open brace after init()
  2. Each time you refresh the chart, change pairs or timeframes, init is called AGAIN. So Slippage will go 10x, 100x, 1000x, etc.