Using PlotIndexSetInteger to change arrow code on the fly

To add comments, please log in or register
Tom Clayson
215
Tom Clayson  

From the documentation I thought it would be possible, but so far I haven't manage to make it work. I have included my code below, could someone please take a look and show me where I've gone wrong. As you can see from the commented out sections, I originally was going to do what I wanted with 9 separate buffers, but one is better if I can manage it.

I am sure there are other errors as well, I am just getting started with mql5 so if you could suggest any improvements that would be greatly appreciated as well.


//+------------------------------------------------------------------+
//|                                              CandleSentiment.mq5 |
//|                                                   whitebloodcell |
//|                                              tmclayson@gmail.com |
//+------------------------------------------------------------------+
#property copyright "whitebloodcell"
#property link      "XYZ"
#property version   "1.00"
#property indicator_separate_window

#property indicator_buffers 1
#property indicator_plots   1
#property indicator_maximum 5
#property indicator_minimum -5
#property indicator_width1 2 

/*
#property indicator_label1  "HighCloseBullPattern"
#property indicator_label2  "MidCloseBullPattern"
#property indicator_label3  "LowCloseBullPattern"
#property indicator_label4  "HighCloseRangePattern"
#property indicator_label5  "MidCloseRangePattern"
#property indicator_label6  "LowCloseRangePattern"
#property indicator_label7  "HighCloseBearPattern"
#property indicator_label8  "MidCloseBearPattern"
#property indicator_label9  "LowCloseBearPattern"


double HighCloseBullPattern[];
double MidCloseBullPattern[];
double LowCloseBullPattern[];
double HighCloseRangePattern[];
double MidCloseRangePattern[];
double LowCloseRangePattern[];
double HighCloseBearPattern[];
double MidCloseBearPattern[];
double LowCloseBearPattern[];
*/

double CandleSentiment[];

//#include<\Indicators\CandleSentiment.mqh>

bool   FirstRun = true;

double RangePercent;

//+------------------------------------------------------------------+
//| Initialization
//+------------------------------------------------------------------+
int OnInit() {
   IndicatorSetString(INDICATOR_SHORTNAME,"CandleSentiment("+_Symbol+")");
   RangePercent = 1.0/3.0;
/*
//--- indicator buffers mapping
   SetIndexBuffer(0,HighCloseBullPattern,INDICATOR_DATA);
   SetIndexBuffer(1,MidCloseBullPattern,INDICATOR_DATA);
   SetIndexBuffer(2,LowCloseBullPattern,INDICATOR_DATA);
   SetIndexBuffer(3,HighCloseRangePattern,INDICATOR_DATA);
   SetIndexBuffer(4,MidCloseRangePattern,INDICATOR_DATA);
   SetIndexBuffer(5,LowCloseRangePattern,INDICATOR_DATA);
   SetIndexBuffer(6,HighCloseBearPattern,INDICATOR_DATA);
   SetIndexBuffer(7,MidCloseBearPattern,INDICATOR_DATA); 
   SetIndexBuffer(8,LowCloseBearPattern,INDICATOR_DATA);     

//--- indicator arrow styles
   PlotIndexSetInteger(0,PLOT_ARROW,241);//Up
   PlotIndexSetInteger(1,PLOT_ARROW,246);//Diagonal Up   
   PlotIndexSetInteger(3,PLOT_ARROW,240);//Sidewards
   PlotIndexSetInteger(4,PLOT_ARROW,244);// Up Down
   PlotIndexSetInteger(5,PLOT_ARROW,244);// Up Down
   PlotIndexSetInteger(5,PLOT_ARROW,244;// Up Down
   PlotIndexSetInteger(6,PLOT_ARROW,240);//Sidewards
   PlotIndexSetInteger(7,PLOT_ARROW,248);//Diagonal Down
   PlotIndexSetInteger(8,PLOT_ARROW,242);//Down

    //---- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);  
   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,EMPTY_VALUE);  
   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,EMPTY_VALUE);    
   PlotIndexSetDouble(8,PLOT_EMPTY_VALUE,EMPTY_VALUE);   
*/
   SetIndexBuffer(0,CandleSentiment,INDICATOR_DATA); 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);      
//--- return if completed successfully.    
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Main Indicator Logic
//+------------------------------------------------------------------+
int OnCalculate(const int _BarsTotal,
                const int _BarsCalculated,
                const datetime &T[],
                const double &O[],
                const double &H[],
                const double &L[],
                const double &C[],
                const long &TV[],
                const long &V[],
                const int &S[]) {
   
   int StartIndex = MathMax(_BarsCalculated-1,1);
   int FinishIndex =_BarsTotal-1;
   int Sentiment; 
   
   if(_BarsTotal<FinishIndex) {
      return(0);
   }
   else {
      if(FirstRun) {
         ArrayInitialize(CandleSentiment,EMPTY_VALUE);
         /*
         ArrayInitialize(HighCloseBullPattern,EMPTY_VALUE);
         ArrayInitialize(MidCloseBullPattern,EMPTY_VALUE);
         ArrayInitialize(LowCloseBullPattern,EMPTY_VALUE);
         ArrayInitialize(HighCloseRangePattern,EMPTY_VALUE);
         ArrayInitialize(MidCloseRangePattern,EMPTY_VALUE);
         ArrayInitialize(LowCloseRangePattern,EMPTY_VALUE);
         ArrayInitialize(HighCloseBearPattern,EMPTY_VALUE);
         ArrayInitialize(MidCloseBearPattern,EMPTY_VALUE);
         ArrayInitialize(LowCloseBearPattern,EMPTY_VALUE);
         */
         // Set the price arrays to match with the indicator arrays
         ArraySetAsSeries(T,true);
         ArraySetAsSeries(O,true);
         ArraySetAsSeries(H,true);
         ArraySetAsSeries(L,true);
         ArraySetAsSeries(C,true);
         ArraySetAsSeries(TV,true);
         ArraySetAsSeries(V,true);
         ArraySetAsSeries(S,true);         
         FirstRun=false;
      }
   }
   
   for(int Bar=StartIndex; Bar<FinishIndex; Bar++) {
      
      Sentiment = CandleSentiment(Bar,Bar-1,RangePercent,RangePercent,O,H,L,C);
      
      switch(Sentiment) {
         case 4:  
         PlotIndexSetInteger(0,PLOT_ARROW,241);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGreen);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case 3:  
         PlotIndexSetInteger(0,PLOT_ARROW,246);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGreen);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case 2:  
         PlotIndexSetInteger(0,PLOT_ARROW,240);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGreen);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case 1:  
         PlotIndexSetInteger(0,PLOT_ARROW,244);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGreen);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case 0:  
         PlotIndexSetInteger(0,PLOT_ARROW,244);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrGray);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case -1: 
         PlotIndexSetInteger(0,PLOT_ARROW,244);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case -2: 
         PlotIndexSetInteger(0,PLOT_ARROW,240);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case -3: 
         PlotIndexSetInteger(0,PLOT_ARROW,248);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         case -4: 
         PlotIndexSetInteger(0,PLOT_ARROW,242);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
         CandleSentiment[Bar]=Sentiment;
         break;
         
         default: Print("Unexpected Sentiment"); break;
      }
   }

//--- return value of prev_calculated for next call
   return(_BarsCalculated);

}
Alain Verleyen
38078
Alain Verleyen  
You have to use 1 buffer by arrow. Or use Objects.
Tom Clayson
215
Tom Clayson  
angevoyageur:
You have to use 1 buffer by arrow. Or use Objects.
You mean one buffer per arrow type?
Alain Verleyen
38078
Alain Verleyen  
whitebloodcell:
You mean one buffer per arrow type?
Of course.
To add comments, please log in or register