Download MetaTrader 5

Minor Errors When Compiling. Cannot figure them out - page 2

To add comments, please log in or register
TheForexGamer
68
TheForexGamer  
TheForexGamer:
Just wanted to make sure i understood. Yes i will post the code when i get home today. Thanks again

Hey Alain, so this is what I have:

(I declared MathAbs as a double in the set up area)

 if(PositionSelect(_Symbol) == false) // We have no open position
      { 
      
      if(MathAbs(PriceDataTable[1] - mAData[1]) < 10 * P) // and price action comes within 10 pips of the MA line
            {
            
         // ..and these Buy Conditions are met
      if (PriceDataTable[1].high > mAData[1] && PriceDataTable[1].close > PriceDataTable[2].close)
       
        //Open a Buy Trade
        {
         
         if (useStopLoss) stopLossLevel = currentAsk - stopLossPipsFinal * _Point * P; else stopLossLevel = 0.0;
         if (useTakeProfit) takeProfitLevel = currentAsk + takeProfitPipsFinal * _Point * P; else takeProfitLevel = 0.0;
        
         
            
         tradingControlPanel.PositionOpen(_Symbol, ORDER_TYPE_BUY, lot, currentAsk, stopLossLevel, takeProfitLevel, "Buy Trade. Magic Number #" + (string) tradingControlPanel.RequestMagic()); 
         
         if(tradingControlPanel.ResultRetcode()==10008 || tradingControlPanel.ResultRetcode()==10009) 
            {
            Print("Entry rules: A Buy order has been successfully placed with Ticket#: ", tradingControlPanel.ResultOrder());
            }
         else
            {
            Print("Entry rules: The Buy order request could not be completed. Error: ", GetLastError());
            ResetLastError();
            return;
             }
            }
         }

I keep getting the errors:     '-' illegal operation use and,    '-' parameter conversion not allowed


On the second piece of code I posted:

int SearchArray()
  {
  
   if (PositionSelect(_Symbol) == true) // If there is an open position
   {
      ArrayMaximum(PriceDataTable, 0, WHOLE_ARRAY);
      
   }
   return 0;
  }

I have placed this at the absolute bottom of the EA (outside of the OnTick area) and now have taken off the '[]', I have the warning that 'expression has no effect'.


What I want it to do is for each bar just gone 'PriceDataTable[1]', if that price is > the maximum price found in the array from [2]-[9], then enter a trade. So i changed it to this:


int SearchArray()
  {
  
   if (PositionSelect(_Symbol) == false) // If there is no open position
   {
      ArrayMaximum(PriceDataTable, 2, WHOLE_ARRAY);
      
   }
   return 0;
  }

...but it still says: 'expression has no effect'


I'm not sure where to go from here?

Thanking you in advance!

Ariel Rivas Batista
137
Ariel Rivas Batista  
Mathabs is a local  variable and it don't need to be defined. 
Ariel Rivas Batista
137
Ariel Rivas Batista  
And in the second piece of code you need an int viable that take the value of ArrayMaximum. Ex:

int Max = ArrayMaximum (hdhksksksskskdhdjdjdhf) ;
TheForexGamer
68
TheForexGamer  
Ariel Rivas Batista:
Mathabs is a local  variable and it don't need to be defined. 

I took off the declaration and still got the same message. What i did try is doing the subtraction outside of the MathAbs and it worked. It is not working because PriceDataTable[] is MqlRates i think? Instead of a double? Is it possible to query MqlRates within the MathAbs? As i need to query the different prices of the candles?

TheForexGamer
68
TheForexGamer  
Ariel Rivas Batista:
And in the second piece of code you need an int viable that take the value of ArrayMaximum. Ex:

int Max = ArrayMaximum (hdhksksksskskdhdjdjdhf) ;

int arrayindex = ArrayMaximum(PriceDataTable, 2, WHOLE_ARRAY); << i defined that in the set up area and tried at the bottom outside of the OnTick area, both gave the 

message: 'possible loss of data due to type conversion' as a warning and still the warning: 'expression has no effect'

whroeder1
17116
whroeder1  
TheForexGamer:

int arrayindex = ArrayMaximum(PriceDataTable, 2, WHOLE_ARRAY); << i defined that in the set up area and tried at the bottom outside of the OnTick area, both gave the 

message: 'possible loss of data due to type conversion' as a warning and still the warning: 'expression has no effect'

Not with that line of code. Post all the relevant code and indicate what line the message refers to. That includes your definition of PriceDataTable.

TheForexGamer
68
TheForexGamer  
whroeder1:

Not with that line of code. Post all the relevant code and indicate what line the message refers to. That includes your definition of PriceDataTable.

Ok i will post the entire EA when i get home. Thanks!
TheForexGamer
68
TheForexGamer  

Ok so below is my EA. I have put '========= For Issue 1 ' y next to all the relevant parts, and my function issue is right at the bottom of the EA.

Thank guys I appreciate your assistance.

The error log says: 

'PositionInfo.mqh' PositionInfo.mqh 1 1

'DealInfo.mqh' DealInfo.mqh 1 1

'-' - illegal operation use Mariah 1.2.mq5 211 36 <<<<<<<<<<<<<<<<<<<<<<<<<< Issue 1

'-' - parameter conversion not allowed Mariah 1.2.mq5 211 36 <<<<<<<<<<<<<<<<<<<<<<<<<< Issue 1

expression has no effect Mariah 1.2.mq5 286 7 <<<<<<<<<<<<<<<<<<<<<<<<<< Issue 2 (warning)

2 error(s), 1 warning(s) 3 2



//+------------------------------------------------------------------+
//|                                 Mariah 1.2.mq5                   |
//|                        Copyright 2017, Global Holistics Ltd.     |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Global Holistics Ltd"
#property link      ""
#property version   "1.00"


#include <Trade\Trade.mqh>


//----- My input variables ------------

input double   lot = 0.1;
input int      movingAveragePeriod = 20;
input bool     useStopLoss = true;
input double   stopLoss = 20;
input bool     useTakeProfit = true; 
input double   takeProfit = 40;
input bool useTrailingStop=true;
input double trailingStopPips=40;

CTrade tradingControlPanel;
MqlRates PriceDataTable[];     //================================================== For Issue 1
double mAData[]; 
int controlPanel, pricePoints, numberOfmAData, numberOfPriceDataPoints, P;
double currentBid, currentAsk;
double stopLossPipsFinal, takeProfitPipsFinal, stopLevelPips;
double stopLossLevel, takeProfitLevel;
double newStopLossPips;
double newTrailingStopPrice;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
ArraySetAsSeries (mAData, true);
controlPanel = iMA(_Symbol, _Period, 20, 0, MODE_SMA, PRICE_CLOSE);

ArraySetAsSeries (PriceDataTable, true); //=================================================================================== FOR ISSUE 1   
   if(_Digits == 5 || _Digits == 3 || _Digits == 1) P = 10;else P = 1; // To account for 5 digit brokers
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
currentBid = SymbolInfoDouble(_Symbol,SYMBOL_BID); // Get latest Bid Price
currentAsk = SymbolInfoDouble(_Symbol,SYMBOL_ASK); // Get latest Ask Price
   

numberOfmAData = CopyBuffer(controlPanel, 0, 0, 20, mAData); 
int maDataFill = CopyBuffer(controlPanel, 0, 0, 20, mAData);

numberOfPriceDataPoints = CopyRates(_Symbol,0,0,10,PriceDataTable); //======================== FOR ISSUE 1
pricePoints = CopyRates(_Symbol,0,0,10,PriceDataTable);                //======================== FOR ISSUE 1

stopLevelPips = (double) (SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) + SymbolInfoInteger(_Symbol, SYMBOL_SPREAD)) / P; // Defining minimum StopLevel

   if (stopLoss < stopLevelPips) 
      {
      stopLossPipsFinal = stopLevelPips;
      } 
   else
      {
      stopLossPipsFinal = stopLoss;
      } 
      
   if (takeProfit < stopLevelPips) 
      {
      takeProfitPipsFinal = stopLevelPips;
      }
   else
      {
      takeProfitPipsFinal = takeProfit;
      }




// -------------------- EXITS --------------------
   
   if(PositionSelect(_Symbol) == true) // If We have an open position
      {
      
      if (false) // ..and this condition is met (System based stop, But using hard stop and target)
         {
               
      if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) // ..and If it is Buy position
            { 
               
            tradingControlPanel.PositionClose(_Symbol); // Closes position related to this symbol
            
            if(tradingControlPanel.ResultRetcode()==10008 || tradingControlPanel.ResultRetcode()==10009) //Request is completed or order placed
               {
               Print("Exit rules: A close order has been successfully placed with Ticket#: ",tradingControlPanel.ResultOrder());
               }
            else
               {
               Print("Exit rules: The close order request could not be completed.Error: ",GetLastError());
               ResetLastError();
               return;
               }
               
            }
            
            
       else if (false) // /else if this condition is met 
           {
          
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) // and If it is a Sell position
            { 
            
            tradingControlPanel.PositionClose(_Symbol); // Closes position related to this symbol (_Symbol = the current pair)
            
            if(tradingControlPanel.ResultRetcode()==10008 || tradingControlPanel.ResultRetcode()==10009) //Request is completed or order placed
               {
               Print("Exit rules: A close order has been successfully placed with Ticket#: ", tradingControlPanel.ResultOrder());
               }
            else
               {
               Print("Exit rules: The close order request could not be completed. Error: ", GetLastError());
               ResetLastError();
               return;
               }
            }
            }
         }   
}

// Trailing Stops Area ==========================================
/*
if (useTrailingStop == true)
   {
      if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
      {
         newTrailingStopPrice = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID) - trailingStopPips*(_Point*P),_Digits);
         if(newTrailingStopPrice > PositionGetDouble(POSITION_PRICE_OPEN))
         {
         if(newTrailingStopPrice > PositionGetDouble (POSITION_SL))
         {
         tradingControlPanel.PositionModify (_Symbol, newTrailingStopPrice, PositionGetDouble(POSITION_TP));
         Print ("Trailing Stop has moved to: ", newTrailingStopPrice);
         }
         }
      }
      
      if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
      {
         newTrailingStopPrice = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK) + trailingStopPips*(_Point*P),_Digits);
         if(newTrailingStopPrice < PositionGetDouble(POSITION_PRICE_OPEN))
         {
         if(newTrailingStopPrice < PositionGetDouble (POSITION_SL) || PositionGetDouble(POSITION_SL) == 0)
         {
         tradingControlPanel.PositionModify (_Symbol, newTrailingStopPrice, PositionGetDouble(POSITION_TP));
         Print ("Trailing Stop has moved to: ", newTrailingStopPrice);
         }
         }
      }
   }
   
   // End of Trailing stops area =======================================================
   */
   
   
// -------------------- ENTRIES --------------------  
         
   if(PositionSelect(_Symbol) == false) // We have no open position
      { 
      
      if(MathAbs(PriceDataTable[1] - mAData[1]) < 10 * P) //========================================================== FOR ISSUE 1
            {
 
         // ..and these Buy Conditions are met
      if (PriceDataTable[1].high > mAData[1] && PriceDataTable[1].close > PriceDataTable[2].close)
       
        //Open a Buy Trade
        {
         
         if (useStopLoss) stopLossLevel = currentAsk - stopLossPipsFinal * _Point * P; else stopLossLevel = 0.0;
         if (useTakeProfit) takeProfitLevel = currentAsk + takeProfitPipsFinal * _Point * P; else takeProfitLevel = 0.0;
        
         
            
         tradingControlPanel.PositionOpen(_Symbol, ORDER_TYPE_BUY, lot, currentAsk, stopLossLevel, takeProfitLevel, "Buy Trade. Magic Number #" + (string) tradingControlPanel.RequestMagic()); // Open a Buy position
         
         if(tradingControlPanel.ResultRetcode()==10008 || tradingControlPanel.ResultRetcode()==10009) //Request is completed or order placed
            {
            Print("Entry rules: A Buy order has been successfully placed with Ticket#: ", tradingControlPanel.ResultOrder());
            }
         else
            {
            Print("Entry rules: The Buy order request could not be completed. Error: ", GetLastError());
            ResetLastError();
            return;
             }
            }
         }
        
         
         // If no Buy Conditions, also look for Sell Condtions..
         
       else if (PriceDataTable[1].close < PriceDataTable[2].close && 
      PriceDataTable[2].high > mAData[2])
       {
       
       
    
         if (useStopLoss) stopLossLevel = currentBid + stopLossPipsFinal * _Point * P; else stopLossLevel = 0.0;
         if (useTakeProfit) takeProfitLevel = currentBid - takeProfitPipsFinal * _Point * P; else takeProfitLevel = 0.0;

         tradingControlPanel.PositionOpen(_Symbol, ORDER_TYPE_SELL, lot, currentBid, stopLossLevel, takeProfitLevel, "Sell Trade. Magic Number #" + (string) tradingControlPanel.RequestMagic()); // Open a Sell position
         
         if(tradingControlPanel.ResultRetcode()==10008 || tradingControlPanel.ResultRetcode()==10009) //Request is completed or order placed
            {
            Print("Entry rules: A Sell order has been successfully placed with Ticket#: ", tradingControlPanel.ResultOrder());
            }
         else
            {
            Print("Entry rules: The Sell order request could not be completed.Error: ", GetLastError());
            ResetLastError();
            return;
            }
         
         }
         
         
   } 
}

//==================================================================================
//==================================================================================
//================================ FUNCTIONS =======================================
//==================================================================================
//==================================================================================


int SearchArray() //========================================================================================== FOR ISSUE 2
  {
  
   if (PositionSelect(_Symbol) == false) // If there is no open position
   {
      ArrayMaximum(PriceDataTable, 2, WHOLE_ARRAY);
   }
   return 0;
  }
   
//+------------------------------------------------------------------+



TheForexGamer
68
TheForexGamer  

I would like to open a new feed to see if anyone else can help, how do i close this one?

whroeder1
17116
whroeder1  
TheForexGamer: I would like to open a new feed to see if anyone else can help, how do i close this one?
  1. You can't close them
  2. Don't open another that is double posting

Don't double post

123
To add comments, please log in or register