help troubleshoot

To add comments, please log in or register
traderjes
130
traderjes  
When compiling this code i get an error in line 96 (the last line of code) saying that "lotSize" is not declared. I dont understand as i have declared this variable just above. Also, i get no error message in the similar code i use above to enter long positions.. Can someone see what im doing wrong? 
#property copyright ""
#property link     "" 
#property version   "1.00"
#property strict
#property show_inputs
#include  <CustomFunctions01.mqh>

int magicNB = 55555;


extern int  ATRPeriod           = 14;
extern double SLATRMultiplier   = 2;
extern double TPATRMultiplier   = 5;

extern int fastEMAprd = 20;
extern int slowEMAprd = 55;

input double riskPerTrade = 0.02;


int openOrderID;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Alert("");
   Alert("Starting Strategy Sling Shot");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Alert("Stopping Strategy Sling Shot");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
// ATR Stop Loss and Take Profit

   // high and low price - (check the shift! here it is set to previous bar)
double high = iHigh(NULL,0,1);
double low  = iLow(NULL,0,1);


 // Atr (check the shift! here it is set to previous bar)
double atr = iATR(NULL,0,14,1);

// SL
double SLsell = NormalizeDouble(high + atr * SLATRMultiplier,Digits);
double SLbuy = NormalizeDouble(low - atr * SLATRMultiplier,Digits);

  //TP
double TPbuy = NormalizeDouble( high + atr * TPATRMultiplier, Digits);
double TPsell = NormalizeDouble(low - atr * TPATRMultiplier, Digits);


// EMA trend settings

double fastEMA = iMA(NULL,0,fastEMAprd,0,MODE_EMA,PRICE_CLOSE,0);
double slowEMA = iMA(NULL,0,slowEMAprd,0,MODE_EMA,PRICE_CLOSE,0);




   
   if(!CheckIfOpenOrdersByMagicNB(magicNB))//if no open orders try to enter new position
   
   
   {
   
   //buying
      if(fastEMA > slowEMA && Ask > fastEMA && Close[1] < fastEMA )
      {
        
         double lotSize = OptimalLotSize(riskPerTrade,Ask,SLbuy);
         
         openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,Ask,10,SLbuy,TPbuy,NULL,magicNB);
         if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
         
      }
      
    //sellling
      
      else if(slowEMA > fastEMA && Bid < slowEMA && Open[1] > fastEMA )
        
          
          double lotSize = OptimalLotSize(riskPerTrade,Bid,SLsell);

          openOrderID = OrderSend(NULL,OP_SELLLIMIT,lotSize,Bid,10,SLsell,TPsell,NULL,magicNB);
          if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
      
      }
   
   
   
   
   }
   
   

//+------------------------------------------------------------------+
William Roeder
22318
William Roeder  
  1. else if(slowEMA > fastEMA && Bid < slowEMA && Open[1] > fastEMA ) double lotSize = OptimalLotSize(riskPerTrade,Bid,SLsell);

    What do you think that one line does? Compare that to your buy code.

  2.          openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,Ask,10,SLbuy,TPbuy,NULL,magicNB);
    Don't use NULL.
    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].

  3. openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,Ask,10,SLbuy,TPbuy,NULL,magicNB);
    ⋮
    openOrderID = OrderSend(NULL,OP_SELLLIMIT,lotSize,Bid,10,SLsell,TPsell,NULL,magicNB);

    You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (broker doesn't know.) Use a minimum of two (2) PIPs.

traderjes
130
traderjes  
Great, thanks for the inputs. Problem Solved;) 
William Roeder
22318
William Roeder  

Don't do that. Someone searching might find this thread and still be clueless. What solved what?

How To Ask Questions The Smart Way. 2004
     When You Ask.
          Follow up with a brief note on the solution.

To add comments, please log in or register