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

Alternating buy and sell signals in indicator-how to
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1541
Page 1 of 1
Author:  fxprotrader [ Mon Feb 25, 2013 12:43 pm ]
Post subject:  Alternating buy and sell signals in indicator-how to

What I need to do is alternate the buy and sell signals. Even if there are multiple Buy signals before there is another Sell signal I need a way of not allowing another Sell signal until I have another Buy.

In this screenshot there is a Buy signal at 11.13+ three more Buy signals before there is a Sell signal at 12.05. I need a way of not allowing the second, third and fourth Buy signal and only allow a Sell signal at 12.05
I'm not a newbie by any stretch. This one looked easy enough but I'm coming up empty.
advfrac.PNG

Code: Select all

//+------------------------------------------------------------------+
//|                                             AdvancedFractals.mq4 |
//|                               Copyright © 2012, Gehtsoft USA LLC |
//|                                            http://fxcodebase.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Gehtsoft USA LLC"
#property link      "http://fxcodebase.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 LimeGreen

extern int Frames=2;

double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0,ExtUpFractalsBuffer);
    SetIndexBuffer(1,ExtDownFractalsBuffer);   
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW,0,2);
    SetIndexArrow(0,234);
    SetIndexStyle(1,DRAW_ARROW,0,2);
    SetIndexArrow(1,233);
//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
//---- initialization done   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nCountedBars;
   bool   bFound;
   double dCurrent;
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted    
   if(nCountedBars<=2)
      i=Bars-nCountedBars-3;
   if(nCountedBars>2)
     {
      nCountedBars--;
      i=Bars-nCountedBars-1;
     }

   while(i>=Frames+1)
     {
      bool FrUp=true;
      bool FrDn=true;
      int ii;
      for (ii=1;ii<=Frames;ii++)
      {
       if (High[i+ii]>=High[i] || High[i-ii]>=High[i]) FrUp=false;
       if (Low[i+ii]<=Low[i] || Low[i-ii]<=Low[i]) FrDn=false;
      }
     
      //----Fractals up
      if (FrUp)
        {
         ExtUpFractalsBuffer[i]=High[i];
        }
      //----Fractals down
      if (FrDn)
        {
         ExtDownFractalsBuffer[i]=Low[i];
        }
      i--;
     }

   return(0);
  }

Author:  NeoTrader [ Mon Feb 25, 2013 1:18 pm ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

Hi fxprotrader,
fxprotrader wrote:What I need to do is alternate the buy and sell signals. Even if there are multiple Buy signals before there is another Sell signal I need a way of not allowing another Sell signal until I have another Buy.

In this screenshot there is a Buy signal at 11.13+ three more Buy signals before there is a Sell signal at 12.05. I need a way of not allowing the second, third and fourth Buy signal and only allow a Sell signal at 12.05

I'm not a newbie by any stretch. This one looked easy enough but I'm coming up empty.
I haven't looked in your code.

But the easiest way to achieve this is to have a variable where you save the state of the last signal and compare this signal state with the current signal before you set it.
If they are the same don't set the signal otherwise do it.

Just a fast thought.


happy trading,

Robert

-
Author:  fxdaytrader [ Mon Feb 25, 2013 1:23 pm ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

i think that works:
Author:  bourgenot [ Mon Feb 25, 2013 4:16 pm ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

hello, I'm looking your indicator with alert pop up if the ace ty thank you for the deposit here. I add this indicator factale with yours: http://fxcodebase.com/code/download/file.php?id=7371. thank you, Pierre
Author:  fxprotrader [ Wed Feb 27, 2013 4:16 am ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

NeoTrader wrote:Hi fxprotrader,
fxprotrader wrote:What I need to do is alternate the buy and sell signals. Even if there are multiple Buy signals before there is another Sell signal I need a way of not allowing another Sell signal until I have another Buy.

In this screenshot there is a Buy signal at 11.13+ three more Buy signals before there is a Sell signal at 12.05. I need a way of not allowing the second, third and fourth Buy signal and only allow a Sell signal at 12.05

I'm not a newbie by any stretch. This one looked easy enough but I'm coming up empty.
I haven't looked in your code.

But the easiest way to achieve this is to have a variable where you save the state of the last signal and compare this signal state with the current signal before you set it.
If they are the same don't set the signal otherwise do it.

Just a fast thought.


happy trading,

Robert

-
Robert-
Yes that's what I had originally tried but apparently I didn't get something quite right and it didn't work as expected. This being a small part of a bigger project I was hoping once I got the alternating of signals figured out the rest would fall into place but that is not how it's working out.
fxdaytrader wrote:i think that works:
Thanks. Yes it does.
Author:  lucklogic [ Wed Feb 27, 2013 11:34 am ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

fxdaytrader wrote:i think that works:

Interesting indicator ...............so simple :D

I wonder if you could you put an Alert on a new arrow formation :ugeek:

Thanks in advance
Author:  fxdaytrader [ Wed Feb 27, 2013 11:49 am ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

should work so:
Author:  lucklogic [ Wed Feb 27, 2013 3:24 pm ]
Post subject:  Re: Alternating buy and sell signals in indicator-how to

fxdaytrader wrote:should work so:

Hi,

Thank you for this but unfortunately this fix does not work.
Alert or sound occurs every tick on both Fractal UP and Fractal DOWN

Ideally it would be nice to just get a single alert (rather than multiple) at every new bar

Thanks
All times are UTC Page 1 of 1