Problems related to iCustom Functon...

 
when i use the iCustom function to fetch the values from the data window and alert the values , I get the values..
But when i compare that values to Open or Close function it doesn't take any trade according to my condition
//+------------------------------------------------------------------+
//|                                                    Swings_EA.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//Order Settings
int maxRisk = 100;
int OrderId;

//Indicator Buffers
const string indicatorName = "MAs WAVE";
const int Buffer1 = 0;
const int Buffer2 = 1;

double value1 = 0;
double value2 = 0;

//Indicator inputs
input string TimeFrame       = "current time frame";
input int    HalfLength      = 35;
input int    Price           = PRICE_CLOSE;
input int    EnvelopeShift   = 0;
input double Deviation       = 0.35;

input string note            = "turn on Alert = true; turn off = false";
input bool   alertsOn        = false;
input bool   alertsOnCurrent = false;
input bool   alertsMessage   = false;
input bool   alertsSound     = false;
input bool   alertsEmail     = false;
input string soundfile       = "news.wav";


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Alert("Strategy_1 just started.");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Alert("Strategy_1 just closed.");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- 
      double stopLossPrice;
      double takeProfitPrice;
      double Lots = 1.00;
      
      //Indicator values
      value1 = iCustom(NULL, PERIOD_CURRENT, indicatorName, TimeFrame, HalfLength, Price, 
                       EnvelopeShift, Deviation, note, alertsOn, alertsOnCurrent, alertsMessage, 
                       alertsSound, alertsEmail, soundfile, Buffer1,0);
      value2 = iCustom(NULL, PERIOD_CURRENT, indicatorName, TimeFrame, HalfLength, Price, 
                       EnvelopeShift, Deviation, note, alertsOn, alertsOnCurrent, alertsMessage, 
                       alertsSound, alertsEmail, soundfile, Buffer2, 0);   
      
      if(Open[0] < value2 && Close[0] > value2)
        {
            stopLossPrice = iLowest(NULL, PERIOD_CURRENT, MODE_LOW, 5);
            takeProfitPrice = value1;
            OrderId = OrderSend(NULL, OP_BUY, Lots, Ask, 5, stopLossPrice, takeProfitPrice); 
        }
        
      if(Open[0] > value1 && Close[0] < value1)
        {
            stopLossPrice = iHighest(NULL, PERIOD_CURRENT, MODE_HIGH, 5);
            takeProfitPrice = value2;
            OrderId = OrderSend(NULL, OP_SELL, Lots, Bid, 5, stopLossPrice, takeProfitPrice); 
        }
  }
Files:
MAs_WAVE.mq4  6 kb
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 

the values which i got from the iCustom functions are correct ...

but when i run the EA, it didn't take any trades or shows any error in the journal

 
            OrderId = OrderSend(NULL, OP_SELL, Lots, Bid, 5, stopLossPrice, takeProfitPrice); 
  1. You would know why, had you bothered to

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum (2012)
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles (2014)

  2. Be careful with 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[].
    5. Cloud Protector Bug? - MQL4 programming forum (2020.07.25)