LogiBar mean renko

 

Hi all,

In the below table you have Traditional renko chart script. In Noraml Renko chart you do not see the real Open Price for renko candel. If anybody can change the following renko code or have LogiBar mean renko script please share it here.


//+------------------------------------------------------------------+
//|                                                        renko.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property show_inputs
#include <WinUser32.mqh>
extern int boxSize = 10;

int        ExtHandle=-1;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int    i, start_pos, last_fpos, i_time;
   double d_open, d_low, d_high, d_close, d_volume;
   int hwnd;
  
//---- History header
   int    version=400;
   string c_copyright;
   string c_symbol=Symbol();
   int    i_period=boxSize+1; 
   int    i_digits=Digits;
   int    i_unused[13];
//----  
   ExtHandle=FileOpenHistory(c_symbol+i_period+".hst", FILE_BIN|FILE_WRITE);
   if(ExtHandle < 0) return(-1);
//---- write history file header
   c_copyright="(C) 4e, 4ebur@mail.ru";
   FileWriteInteger(ExtHandle, version, LONG_VALUE);
   FileWriteString(ExtHandle, c_copyright, 64);
   FileWriteString(ExtHandle, c_symbol, 12);
   FileWriteInteger(ExtHandle, i_period, LONG_VALUE);
   FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);
   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //timesign
   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //last_sync
   FileWriteArray(ExtHandle, i_unused, 0, 13);
//---- write history file
  
   start_pos=Bars-1;
   
   Comment("Renk_Live_Scr : Open Offline ",c_symbol,"M", boxSize + 1," to view chart");
   datetime time = iTime(NULL,0,i);
   double difference,x1,x2;
   double boxPointSize = boxSize*Point;
   int boxAmount;
   double lastHigh = Close[start_pos],lastLow = Close[start_pos];
  
              
   for(i=start_pos-1;i>=0; i--)
     {
      //get price based on closed bar
      x2 = Close[i];
      if((x2<=lastHigh)&&(x2>=lastLow)) continue;
      if(x2>lastHigh) {x1 = lastHigh;}
      if(x2<lastLow) {x1 = lastLow;}
      
      difference  = x2-x1;
      boxAmount =difference/boxPointSize;
      
       int ctime = 0;
       while(boxAmount != 0)
       {
         //check if new bar up is made
         if(boxAmount>0)
            {
               lastLow = lastHigh;
               lastHigh +=boxPointSize; 
    
               boxAmount--;
               
               d_open  = lastLow;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh;
               d_volume = 2;
               i_time =iTime(NULL,0,i)+ctime;
               ctime+=60;
            }
         //check if new bar down is made
         if(boxAmount<0)
            {
               lastHigh = lastLow;
               lastLow -= boxPointSize; 
             
               boxAmount++;
               
               d_open  = lastHigh;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastLow;
               d_volume = 1;
               i_time =iTime(NULL,0,i)+ctime;
               ctime+=60;               
            }
           
         last_fpos=FileTell(ExtHandle); //get last position in file
         // write values to file
         FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
         FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
         //clear the file buffer
         FileFlush(ExtHandle);
        }
     } 
  //clear the file buffer
   FileFlush(ExtHandle);
 //end historical data
 //begin live data
   int last_time=LocalTime()-5;
   while(IsStopped()==false)
     {
      int cur_time=LocalTime();
       //---- check for new rates
      if(RefreshRates())
        {
         FileSeek(ExtHandle,last_fpos,SEEK_SET);
         // use if creating off of closed bars
         //x2 = Close[1];
         // use if creating off of ticks
         x2 = Bid;
         if((x2<=lastHigh)&&(x2>=lastLow)) continue;
         if(x2>lastHigh) {x1 = lastHigh;}
         if(x2<lastLow) {x1 = lastLow;}
      
         difference  = x2-x1;
         boxAmount = difference/boxPointSize;
         
          //ctime = 0;
          while(boxAmount != 0)
          {
           // check if new bar up is made
           if(boxAmount>0)
            {
               lastLow = lastHigh;
               lastHigh +=boxPointSize; 
    
               boxAmount--;
               
               d_open  = lastLow;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh;
               d_volume = 2;
               //i_time =iTime(NULL,0,i)+ctime;
               i_time = Time[0];
               //ctime+=60;
            }
           // check if new bar down is made 
           if(boxAmount<0)
            {
               lastHigh = lastLow;
               lastLow -= boxPointSize; 
             
               boxAmount++;
               
               d_open  = lastHigh;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastLow;
               d_volume = 1;
               //i_time =iTime(NULL,0,i)+ctime;
               i_time = Time[0];
               //ctime+=60;               
             }
           
            // write values to file
            FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
            FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
            FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
            FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
            FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
            FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);         
            last_fpos=FileTell(ExtHandle); //get last position in file      
            //clear the file buffer
            FileFlush(ExtHandle);   
            //---- refresh chart
            if(hwnd==0)
              {
               hwnd=WindowHandle(Symbol(),i_period);
               if(hwnd!=0) Print("Chart window detected");
              }
            //---- refresh window not frequently than 1 time in 2 seconds
            if(hwnd!=0 && cur_time-last_time>=2)
              {
               PostMessageA(hwnd,WM_COMMAND,33324,0);
               last_time=cur_time;
              }      
              // end refresh chart
           }  // end while box amount
        }  // end if refresh rates
      Sleep(50); 
     }// end while script is running
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void deinit()
  {
   if(ExtHandle>=0) { FileClose(ExtHandle); ExtHandle=-1; }
   Comment(""); // remove comment instructions
  }
//+------------------------------------------------------------------+


   
 
hmrt135: If anybody can change the following renko code
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
 
WHRoeder:
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.

So in the above code it will firstly write the historical data. If i could define a criteria for previous renko-bar, i can make it my self. Actually i want to know how can i define the previous up or down renko-bar in order to define current renko-bar HLOC.

 I define the below code but it did not work:

if the below definitions are wrong please help me.

 

Close[start_pos+1] > Close[start_pos+2]  // so it means that the previous renko-bar was a Up renko-bar 

Close[start_pos+1] < Close[start_pos+2]  // so it means that the previous renko-bar was a Down renko-bar 
 
Close[start_pos+1] > Close[start_pos+2]  // so it means that the previous renko-bar was a Up renko-bar 

Close[] is the source chart not the renko chart.


BoxAmount > 0 means the current box is an Up
double lastHigh = Close[start_pos],lastLow = Close[start_pos];
:
if(boxAmount>0)
{
   lastLow = lastHigh;
               lastHigh +=boxPointSize; 
    
               boxAmount--;
               
               d_open  = lastLow;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh;
You want the open to be the previous renko bar's close.
double lastHigh = Close[start_pos],lastLow = Close[start_pos];
double prevClose= Close[start_pos];
:
if(boxAmount>0)
{
   lastLow = lastHigh;
               lastHigh +=boxPointSize; 
    
               boxAmount--;
               
               d_open  = prevClose;
//             d_open  = lastLow;
               d_open  = lastLow;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh; prevClose = d_close

Same change for the down bar.
 
WHRoeder:

Close[] is the source chart not the renko chart.


BoxAmount > 0 means the current box is an Up
You want the open to be the previous renko bar's close.

Same change for the down bar.
where did you define lastclose for this Tag:
 d_open  = lastClose; // did you mean prevclose?
As i understand, i must define  prevclose on the top of script and for every new bar condition i must rewrite d_open=prevclose; and on the end of paragraph i must write prevclose=d_close so for the next renko bar we have prevclose as current open price bar? is it ture?
 
hmrt135: where did you define lastclose for this Tag:
Yes prevClose.
 
WHRoeder:
Yes prevClose.

I did your advise but the result seems like this picture and it does not draw reverse candles:

#property show_inputs
#include <WinUser32.mqh>
extern int boxSize = 50;

int        ExtHandle=-1;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int    i, start_pos, last_fpos, i_time;
   double d_open, d_low, d_high, d_close, d_volume;
  
//---- History header
   int    version=400;
   string c_copyright;
   string c_symbol=Symbol();
   int    i_period=boxSize+1; 
   int    i_digits=Digits;
   int    i_unused[13];
//----  
   ExtHandle=FileOpenHistory(c_symbol+i_period+".hst", FILE_BIN|FILE_WRITE);
   if(ExtHandle < 0) return(-1);
//---- write history file header
   c_copyright="(C) 4e, 4ebur@mail.ru";
   FileWriteInteger(ExtHandle, version, LONG_VALUE);
   FileWriteString(ExtHandle, c_copyright, 64);
   FileWriteString(ExtHandle, c_symbol, 12);
   FileWriteInteger(ExtHandle, i_period, LONG_VALUE);
   FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);
   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //timesign
   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //last_sync
   FileWriteArray(ExtHandle, i_unused, 0, 13);
//---- write history file
  
   start_pos=Bars-1;
   
 
   
   Comment("open offline ",c_symbol,"M", boxSize + 1);
   datetime time = iTime(NULL,0,i);
   double difference,x1,x2;
   double boxPointSize = boxSize*Point;
   int boxAmount;
   double lastHigh = Close[start_pos],lastLow = Close[start_pos], prevclose=Close[start_pos];
  
              
   for(i=start_pos-1;i>=0; i--)
     {
      
      x2 = Close[i];
      if((x2<=lastHigh)&&(x2>=lastLow)) continue;
      if(x2>lastHigh) {x1 = lastHigh;}
      if(x2<lastLow) {x1 = lastLow;}
      
      difference  = x2-x1;
      boxAmount =difference/boxPointSize;
      
   
     
       int ctime = 0;
       while(boxAmount != 0)
       {
    
         if(boxAmount>0 )
              
              {
               lastLow = lastHigh;
               lastHigh +=boxPointSize; 

               boxAmount--;         
            
               d_open  = d_close;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh; prevclose=d_close;
               d_volume = 2;
               i_time =iTime(NULL,0,i)+ctime;
               ctime+=60;

               }
               

    
        if(boxAmount<0)
               {
               

               lastHigh = lastLow;
               lastLow -= boxPointSize; 
             
               boxAmount++;
               
               
               d_open  = d_close;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastLow; prevclose=d_close;
               d_volume = 1;
               i_time =iTime(NULL,0,i)+ctime;
               ctime+=60;
             }
    

           
         last_fpos=FileTell(ExtHandle); //Ïîñëåäíÿÿ ïîçèöèÿ
      
         
         FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
         FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
         FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
         
         
         FileFlush(ExtHandle);
         
        }
     } 
     
     
     
     
     
   FileFlush(ExtHandle);
 
   
   
   
   
      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void deinit()
  {
   if(ExtHandle>=0) { FileClose(ExtHandle); ExtHandle=-1; }
  }
//+------------------------------------------------------------------+


   
 
hmrt135: I did your advise but the result seems like this picture and it does not draw reverse candles:
What you Just posted
 What I posted
d_open  = d_close;
d_high = lastHigh;
d_low = lastLow;
d_close = lastHigh; prevclose=d_close;
               d_open  = prevClose;
//             d_open  = lastLow;
               d_high = lastHigh;
               d_low = lastLow;
               d_close = lastHigh; prevClose = d_close

Can you read?
 
WHRoeder:
What you Just posted
 What I posted

Can you read?

Thank you for your response.

I have changed the code, but unfortunately the same problem occurs and the the chart seems like the above chart. 

 
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
  1. You didn't make any attempt so I gave you some code.
  2. You didn't make any attempt, the code you put in was wrong.
  3. You didn't make any attempt, where have you placed your print statements to find out why your changed code has the same problem.
Reason: