Help Trouble Shoot Code

 

Hi


I found a video with an Indicator I liked and took a screenshot of the code. When I tried to replicate it in MetaEditor it wouldnt compile, asked the videos owner but havent heard back yet.

My plan is to make an Indicator from this that displays the up and down movement, ie subtracting the previous tick from the current one. I thought this would be a good start.

THanks :) /Bo

Heres the video:  https://youtu.be/Etc404dEJ6s 

Heres the code. Ive tried trouble shooting it myself so its 99% like the video:

#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2

double ask[], bid[];

int Oninit()
{
   SetIndexStyle(0,DRAW_LINE);   SetIndexBuffer(0,ask);
   SetIndexStyle(1,DRAW_LINE);   SetIndexBuffer(1,ask);   
   return(INIT_SUCCEEDED);
}

void ShiftArray()
{
   for (int n=WindowBarsPerChart()+2;n>0;n--)
   {
      if (ask[n] != EMPTY_VALUE); (ask[n+1] = ask[n]); (bid[n+1] = bid[n] )  //skip empty value on new candle
   }
}

int OnCalculate (const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[],
                 const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] )
{
   ShiftArray();
   
   ask[1]=Ask;
   bid[1]=Bid;
   
   return(rates_total);    
}
 
bodanerius: it wouldnt compile,
  1. Do not post code that will not compile.
    if (ask[n] != EMPTY_VALUE); (ask[n+1] = ask[n]); (bid[n+1] = bid[n] )
    An if statment is
    if (condition) statement;
    or
    if (condition){ statement1; … statementN; }
    It is not:
    Brackets {} are not Parentheses ().
    Statements end with a semicolon ;
     
    if (condition); (statement1); (statement2 )

    MT4: Learn to code it.

  2. You never make bid[] a buffer.