stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

help with arrow-based indicator
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3607
Page 1 of 1
Author:  basch312 [ Wed May 07, 2014 12:40 pm ]
Post subject:  help with arrow-based indicator

hi all,

I want to write an indicator which prints 3 different types of signals, each signal can be up or down and I don't know how to do that. I know how to make an indicator that prints an Up arrow if some conditions are met and down if the complementary conditions are met.

Here's is the main code that I use to write that kind of indicators with only 1 type of signal:

Code: Select all

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 White

//extern string CornerSel = "0:topleft, 1:top-right, 2:bottom-left, 3:bottom-right";
extern bool limitarBarras = true;
extern int  limite		  = 15000;

int n_digits = 0, flagval1 = 0, flagval2 = 0;
double serieUp[], serieDown[];
bool SoundON = true;
datetime prevtime; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
	SetIndexArrow(0, 233);
	SetIndexBuffer(0, serieUp);
	
	SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
	SetIndexArrow(1, 234);
	SetIndexBuffer(1, serieDown);
	
	GlobalVariableSet("AlertTime"+Symbol()+Period(),CurTime());
	GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELLSTOP);
	
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   GlobalVariableDel("AlertTime"+Symbol()+Period());
   GlobalVariableDel("SignalType"+Symbol()+Period());
   
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() 
{
	static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0]; //Solo continua al comienzo de una barra nueva
	RefreshRates();
	WindowRedraw();
   	int limit, i, counter;
   	double tmp=0;
   	int MA_Mode = 1, PriceMode = 0;
   	double Range, AvgRange;
   	int counted_bars=IndicatorCounted();
   	if(counted_bars<0) return(-1);
   	if(counted_bars>0) counted_bars--;
   
	if(limitarBarras) counted_bars = Bars-limite;
 
   	limit=Bars-counted_bars;

   	for(i = limit; i >= 0; i--) {
      	counter=i;
      	Range=0;
      	AvgRange=0;
      	for (counter=i ;counter<=i+9;counter++) AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      	Range=AvgRange/10;
		
      	if(conditionsUp)
      	{
         	if (i == 1 && flagval1==0){  flagval1=1; flagval2=0; }
         	serieUp[i+2] = Low[i+2] - Range*0.4;
      	}
      	else if(conditionsDown)
      	{
         	if (i == 1 && flagval2==0) { flagval2=1; flagval1=0; }
         	serieDown[i+2] = High[i+2] + Range*0.4;
      	}
   	}
   
   	if (flagval1==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_BUY)
   	{
      	//if (SoundON) Alert(Symbol() );
      	tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
      	GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
      	GlobalVariableSet("SignalType"+Symbol()+Period(),OP_BUY);
   	}
   
   	if (flagval2==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_SELL) 
   	{
      	//if (SoundON) Alert(Symbol() );
      	tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
      	GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
      	GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELL);
   	}
   
   	return(0);
}

What can I do?

Regards!

Adrian
Author:  milanese [ Wed May 07, 2014 12:44 pm ]
Post subject:  help with arrow-based indicator

Hi Adrain,

could you more specify, where exactly your problem is?

Cheers :)

Tommaso
Author:  basch312 [ Wed May 07, 2014 1:05 pm ]
Post subject:  help with arrow-based indicator

Hi tommaso the omnipresent!! :smile:

what I want to do is, instead of:

- if(cond1) arrowUp
- if(!cond1) arrowDown

this:

- if(cond1) yellowArrowUp
- if(!cond1) yellowArrowDown
- if(cond2) greenArrowUp
- if(!cond2) greenArrowDown
- if(cond3) redArrrowUp
- if(!cond3) redArrowDown

I've tried to do this through the code I posted what it doesn't work properly, and I haven't been able to find a solution anywhere

Thank you for your time

Adrian
Author:  milanese [ Wed May 07, 2014 1:14 pm ]
Post subject:  help with arrow-based indicator

basch312 ยป Wed May 07, 2014 1:05 pm wrote:Hi tommaso the omnipresent!! :smile:

what I want to do is, instead of:

- if(cond1) arrowUp
- if(!cond1) arrowDown

this:

- if(cond1) yellowArrowUp
- if(!cond1) yellowArrowDown
- if(cond2) greenArrowUp
- if(!cond2) greenArrowDown
- if(cond3) redArrrowUp
- if(!cond3) redArrowDown

I've tried to do this through the code I posted what it doesn't work properly, and I haven't been able to find a solution anywhere

Thank you for your time

Adrian
Hi Adrain you need to change

Code: Select all

 #property indicator_chart_window
        #property indicator_buffers 6
        #property indicator_color1 White
        #property indicator_color2 White
        #property indicator_color3 Yellow
        #property indicator_color4 Yellow
        #property indicator_color5 Red
        #property indicator_color6 Red
         
        //extern string CornerSel = "0:topleft, 1:top-right, 2:bottom-left, 3:bottom-right";
        extern bool limitarBarras = true;
        extern int  limite        = 15000;
         
        int n_digits = 0, flagval1 = 0, flagval2 = 0;
        double serieUp_1[], serieDown_2[];
        double serieUp_3[], serieDown_4[];
        double serieUp_5[], serieDown_6[];
and so on ...

Cheers :)
Tommaso
Author:  basch312 [ Wed May 07, 2014 1:24 pm ]
Post subject:  help with arrow-based indicator

okeey, I'll try it and tell you if I can get it to work.

I feel like a fool right now... :lol:

Regards!
Adrian

EDIT: well, that worked perfectly. Thank you very much!
All times are UTC Page 1 of 1