not working anymore

 

Hello,


long time ago, that i used mql5 the last time

but why i dont the right value out there?


   value = iHigh(_Symbol,PERIOD_CURRENT,iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,20,0));


it should give me the highest price of the last 20 candles


regards

amando

 
amando: it should give me the highest price of the last 20 candles
  1. Correct
  2. Your posted code is without context. Where is that line?

 
William Roeder #:
  1. Correct
  2. Your posted code is without context. Where is that line?

i testet it again and it was working in this way

then i used


input int               Candles = 20;
input ENUM_TIMEFRAMES   CandlesTimeframe = PERIOD_H1;




double PeriodHigh()
{
   ResetLastError();
   double value = 0;
   
   value = iHigh(_Symbol,CandlesTimeframe,iHighest(_Symbol,CandlesTimeframe,MODE_HIGH,Candles,0));
   
   Print("high: ", value);
   Print("high0: ", iHigh(_Symbol,PERIOD_CURRENT,0));
   
   if(GetLastError() != 0)
      Print("Last Error: ",GetLastError()," Function: ",__FUNCTION__);

   return(value);

}

and now i get wrong values


2024.05.02 21:24:07.728 2024.05.01 15:59:59   high: 1.08851

2024.05.02 21:24:07.728 2024.05.01 15:59:59   high0: 1.06848


what says high0 is working but as long i uns input timeframe i get wrong values



 
amando #:

i testet it again and it was working in this way

then i used


and now i get wrong values


2024.05.02 21:24:07.728 2024.05.01 15:59:59   high: 1.08851

2024.05.02 21:24:07.728 2024.05.01 15:59:59   high0: 1.06848


value stores the highest high of the last 20 candles (including the current bar) in the H1 timeframe (or whatever the input is). Then you print the high of the current bar in the selected chart timeframe. The values may be different because you are fetching the highs from different timeframes. Also, the high of the current bar may not be the highest high of the last 20 bars.

 
Emanuel Cavalcante Amorim Filho #:

value stores the highest high of the last 20 candles (including the current bar) in the H1 timeframe (or whatever the input is). Then you print the high of the current bar in the selected chart timeframe. The values may be different because you are fetching the highs from different timeframes. Also, the high of the current bar may not be the highest high of the last 20 bars.

this is an tester issiu, i run this on the strategy tester

in an H1 timeframe and get these wrong results



not really a secret what i did


//+------------------------------------------------------------------+
//|                                                    ....ööööö.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

struct SymbolInfos
  {
   double            Ask;
   double            Bid;
  };


SymbolInfos trade;



#include <Trade\Trade.mqh>               CTrade _trade;                    // wird verwendet für die Trade Funktionen 





input double            Volume = 0.01;

input int               Candles = 20;
input ENUM_TIMEFRAMES   CandlesTimeframe = PERIOD_H1;



input int               LimitOrder = 5;        // input offset für Limit Order


input int               GMTOffset = 4;
input int               StartHour = 8;
input int               StartMinute = 30;

input int               StopHour    = 16;
input int               StopMinute  = 30;



input group             "--- General ---";
input int               MN = 12345678;
input string            Text = "Text";

input group             "---ATR Setting---";
input int               ATRPeriod = 20;
input ENUM_TIMEFRAMES   ATRTimeframe = PERIOD_H1;

int ATRh;
double ATR[];


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ResetLastError();
   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
     {
      Print("Expert are not allowed on this account");
      MessageBox("Expert are not allowed","Alert",0);
     }


   _trade.SetExpertMagicNumber(MN);

   if(ATRh != iATR(_Symbol,ATRTimeframe,ATRPeriod)
      && GetLastError() != 0)
      Print("Error: ", GetLastError(), " on loading ATR indicator");
   ArraySetAsSeries(ATR,true);




   if(GetLastError() != 0)
      Print("Last Error: ",GetLastError()," Function: ",__FUNCTION__);


   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   MqlDateTime tm;
   TimeCurrent(tm);


   trade.Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);     // gibt den Ask Preis zurück+
   trade.Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);     // gibt den Bid Preis zurück

   CopyBuffer(ATRh,0,0,5,ATR);




   if(TradeAllowed()
      && (OrdersTotal() == 0 
      && PositionsTotal() ==0) )      // 2te REgel fehlt noch
     {
      if(   iHigh(_Symbol,CandlesTimeframe,0) >= PeriodHigh()    // 1te Regel
         && trade.Bid <= PeriodLow()                             // 3te Regel 
      )
      
      _trade.BuyStop(Volume,PeriodLow() + LimitOrder*_Point,_Symbol,0,PeriodLow() + LimitOrder*_Point+20*_Point,ORDER_TIME_DAY,0,Text);


     }





   if(GetLastError() != 0)
      ExpertRemove();

  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool TradeAllowed()
  {
   ResetLastError();

   bool Trade = false;


   MqlDateTime tm;
   TimeCurrent(tm);

   if(tm.hour >= StartHour
      && tm.hour <  StopHour)
      Trade = true;


   if(GetLastError() != 0)
      Print("Last Error: ",GetLastError()," Function: ",__FUNCTION__);

   return(Trade);

  }



double PeriodHigh()
{
   ResetLastError();
   double value = 0;
   
   value = iHigh(_Symbol,CandlesTimeframe,iHighest(_Symbol,CandlesTimeframe,MODE_HIGH,Candles,0));
   
   Print("high: ", value);
   Print("high0: ", iHigh(_Symbol,PERIOD_CURRENT,0));
   
   if(GetLastError() != 0)
      Print("Last Error: ",GetLastError()," Function: ",__FUNCTION__);

   return(value);

}

double PeriodLow()
{
   ResetLastError();
   double value = 0;
   
   value = iLow(_Symbol,CandlesTimeframe,iLowest(_Symbol,CandlesTimeframe,MODE_LOW,Candles,0));
   
   Print("low: ", value);
   
   if(GetLastError() != 0)
      Print("Last Error: ",GetLastError()," Function: ",__FUNCTION__);

   return(value);

}  
  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isNewBar()
  {
   static datetime lastTime=0;
   datetime lastbarTime=(datetime)SeriesInfoInteger(_Symbol,0,SERIES_LASTBAR_DATE);
   if(lastTime==0)
     {
      lastTime=lastbarTime;
      return(false);
     }
   if(lastTime!=lastbarTime)
     {
      lastTime=lastbarTime;
      return(true);
     }
   return(false);
  }


//+------------------------------------------------------------------+
 

there must be an bug, when i use instead of






 value = iHigh(_Symbol,CandlesTimeframe,iHighest(_Symbol,CandlesTimeframe,MODE_HIGH,Candles,0));

this version

value = iHigh(_Symbol,PERIOD_CURRENT,iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,Candles,0));

then its working

i tried this on 1h Timeframe and 

input ENUM_TIMEFRAMES   CandlesTimeframe = PERIOD_H1;

is set to 1h

 

Your issue is not fully clear.

When is it working and when not ? what what timeframe ? What is the output ?

Even if it was working, as you can see it yourself now, this code is not good, because on MT5 iHighest(), iHigh() or whatever "data" function can always return an error (if the symbol/timeframe are not the current ones). So you need to check the value returned by iHighest(), then use it with iHigh.

 

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
          Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018)
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019)