Highest value different time frame MQL4

 

Hi, i'm trying to get this to work on a 5 min time frame. Period the iHighest function should be searching for is PERIOD_D1.


int HC()
  {
  for(int i=0; i<WHOLE_ARRAY; i++) 
     {
      int BarShift = iBarShift(NULL,PERIOD_D1,time[i],false);
     }
   int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift); //Time Period: 1M=100
   double HCH = High[IV];
   Print(StringConcatenate("Highest = ", HCH));
   return BarShift;
  }
 
Sanjay Rathore:

Hi, i'm trying to get this to work on a 5 min time frame. Period the iHighest function should be searching for is PERIOD_D1.


1. BarShift is defined inside the for loop so its scope is limited to the loop - you cannot use it later outside the loop. (It is better to define variables before loops so you re-use them on each iteration rather repeatedly allocating/deallocating memory).

2. Your usage of StringConcatenate is wrong - click F1 and read the documentation

3. You can get array out of range errors if High is not correctly populated

After fixing those things I could compile it - you should be able to do the same
 
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. for(int i=0; i<WHOLE_ARRAY; i++)

    i < -1 makes no sense.

  3. Why are you getting shifts in a loop, but not using any of them?

  4.    int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift); //Time Period: 1M=100
       double HCH = High[IV];

    You are mixing apples and oranges.

 
R4tna C #:

1. BarShift is defined inside the for loop so its scope is limited to the loop - you cannot use it later outside the loop. (It is better to define variables before loops so you re-use them on each iteration rather repeatedly allocating/deallocating memory).

2. Your usage of StringConcatenate is wrong - click F1 and read the documentation

3. You can get array out of range errors if High is not correctly populated

After fixing those things I could compile it - you should be able to do the same

Hi R4tna C, 

i should have posted these earlier. i'm trying to find the bear market by percentage. I actutally tried the Apple and oranges thing (4) William was talking about but i don't if what ive done is correct.


(haven't been able to get any of these to work. I'm trying to find the highest of the D1 chart and trade on the M1 Chart. i only want to know the percentage change of a another chart (D1) to help with my if statement on the trading chart (M1). if there is a bear market or bull market. the function works on the D1 chart but doesn't work on the M1 chart (pulling data from D1 for M1 trading). these are my attempts;)

1.
   datetime some_time=iTime(NULL,PERIOD_D1,0)+(60*60*18)+(60*34);
 if (some_time > Time[0]) some_time -= 24*60*60;
 
 int shift=iBarShift(NULL,PERIOD_M1,some_time);
 
   int iHi=iHighest(NULL,PERIOD_D1,MODE_HIGH,shift,0);
   int xHig=iHigh(NULL,PERIOD_M1,iHi);

double HC33 = xHig;

double BearMarket = (((HC33-(SymbolInfoDouble(Symbol(), SYMBOL_BID)))/ HC33) * 100);

2.
int HC()
  {
  for(int i=WHOLE_ARRAY-1; i>=0; i--)
     {
      int BarShift = iBarShift(NULL,PERIOD_D1,Time[i]);
     
     }
   int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift+1); //Time Period: 1M=100
   double HCH = High[IV];
   Print(StringConcatenate("Highest = ", HCH));
   return BarShift;
  }

  double HC33 = High[HC()];


double BearMarket = (((HC33-(SymbolInfoDouble(Symbol(), SYMBOL_BID)))/ HC33) * 100);

3.

int HC()
  {
  for(int i=0; i<WHOLE_ARRAY; i++) 
     {
      int BarShift = iBarShift(NULL,PERIOD_D1,D'2018.01.01 01:00');
    }
   int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift); //Time Period: 1M=100
   double HCH = High[IV];
   Print(StringConcatenate("Highest = ", HCH));
   return BarShift;
  }

double HC33 = High[HC()];


double BearMarket = (((HC33-(SymbolInfoDouble(Symbol(), SYMBOL_BID)))/ HC33) * 100);

4.

int HC()
{
UpperBuf[i] = iHigh(NULL, PERIOD_D1, i+1);

for (int iChart - Bars - 1 - indicatorCounted(); iChart >= 0; iChart--)
{

    // What daily bar corresponds to this chart's bar?
   int iDay = iBarShift(NULL, PERIOD_D1, Time[iChart]);

   // Get yesterdays daily high.
   UpperBuf[iChart] = iHigh(NULL, PERIOD_D1, iDay + 1);
}
return UpperBuf;
}
  


double HC33 = High[HC()];


double BearMarket = (((HC33-(SymbolInfoDouble(Symbol(), SYMBOL_BID)))/ HC33) * 100);
 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. i < -1 makes no sense.

  3. Why are you getting shifts in a loop, but not using any of them?

  4. You are mixing apples and oranges.

Hi William, 

2. i'm not sure what you mean by -1? i've put in the following as a forward loop:

for(int i=WHOLE_ARRAY; i>=0; i--)

3. I thought that i was already adding the shits to the iHighest function?

int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift);

4. I've read what you are explaining about using the same i value for two time periods but i'm not sure what you have tried to code.

for (int iChart - Bars - 1 - indicatorCounted(); iChart >= 0; iChart--){

    // What daily bar corresponds to this chart's bar?
    int iDay = iBarShift(NULL, PERIOD_D1, Time[iChart]);

    // Get yesterdays daily high.
    UpperBuf[iChart] = iHigh(NULL, PERIOD_D1, iDay + 1);
}


my interpretation of this is: my thinking is HC() function is for time period D1 and within BearMarket function is current price (SymbolInfoDouble) and D1 highest information. The program itself should run on the M1 chart.

int HC()
  {
  for(int i=WHOLE_ARRAY-1; i>=0; i--)
     {
      int BarShift = iBarShift(NULL,PERIOD_D1,Time[i]);
     }
   double IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift+1);
   
   return BarShift;
  }

double HC33 = High[HC()];

   double BearMarket = (((HC33-(SymbolInfoDouble(Symbol(), SYMBOL_BID)))/ HC33) * 100);
 
Sanjay Rathore #:

Hi R4tna C, 

i should have posted these earlier. i'm trying to find the bear market by percentage. I actutally tried the Apple and oranges thing (4) William was talking about but i don't if what ive done is correct.


(haven't been able to get any of these to work. I'm trying to find the highest of the D1 chart and trade on the M1 Chart. i only want to know the percentage change of a another chart (D1) to help with my if statement on the trading chart (M1). if there is a bear market or bull market. the function works on the D1 chart but doesn't work on the M1 chart (pulling data from D1 for M1 trading). these are my attempts;)

The crux of what you are trying to do is quite simple "I'm trying to find the highest of the D1 chart and trade on the M1 Chart."

First create a working version of the iHighest implementaton and use to get the D1 and M1 data. After that you can progress to the more intricate calculations of percentages and comparisons.

The code you have posted here is still full of bugs and what has been suggested to you does not seem to be clear, so you certainly need to simplify and take it step by step.

 

Please post yout MQL4 related question in the MQL4 section of this forum.

https://www.mql5.com/en/forum/mql4

 
Sanjay Rathore #:


2. i'm not sure what you mean by -1? i've put in the following as a forward loop:
for(int i=WHOLE_ARRAY; i>=0; i--)

3. I thought that i was already adding the shits to the iHighest function?

int IV = iHighest(_Symbol,PERIOD_D1, MODE_HIGH,WHOLE_ARRAY,BarShift);
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

  2. WHOLE_ARRAY is the constant -1. Your loop does nothing.

  3. IV is a shift of the D1 chart. You use it in High[] which is the current chart.
 
R4tna C #:

The crux of what you are trying to do is quite simple "I'm trying to find the highest of the D1 chart and trade on the M1 Chart."

First create a working version of the iHighest implementaton and use to get the D1 and M1 data. After that you can progress to the more intricate calculations of percentages and comparisons.

The code you have posted here is still full of bugs and what has been suggested to you does not seem to be clear, so you certainly need to simplify and take it step by step.Thank

Thanks, yeah, looks like there is limited access to applied knowledge on this forum, hasn't been complete. I'm planning on moving to another software soon, I just want my strategy to work properly. 

 
Sanjay Rathore #:

Thanks, yeah, looks like there is limited access to applied knowledge on this forum, hasn't been complete. I'm planning on moving to another software soon, I just want my strategy to work properly. 

There are lot of helpful people on this forum.

But instead of expecting them to fix your bugs, you need to play your part by providing meaningful code and at least making an attempt to fix the code you write (especially after hints have been provided).

That applies to any software you may decide to use

 
R4tna C #:

There are lot of helpful people on this forum.

But instead of expecting them to fix your bugs, you need to play your part by providing meaningful code and at least making an attempt to fix the code you write (especially after hints have been provided).

That applies to any software you may decide to use

i'm not going to rant on with you, theres probably two more guys like you on here talking the same way as you. as I said; looks like there is limited access to applied knowledge on this forum, not complete.

Reason: