Alternating buy and sell signals in indicator-how to

Post Reply
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Alternating buy and sell signals in indicator-how to

Post by fxprotrader »

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);
  }

You do not have the required permissions to view the files attached to this post.
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Alternating buy and sell signals in indicator-how to

Post by NeoTrader »

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

-
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: Alternating buy and sell signals in indicator-how to

Post by fxdaytrader »

i think that works:
You do not have the required permissions to view the files attached to this post.
User avatar
bourgenot
Trader
Posts: 159
Joined: Mon Aug 27, 2012 4:37 pm

Re: Alternating buy and sell signals in indicator-how to

Post by bourgenot »

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
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Re: Alternating buy and sell signals in indicator-how to

Post by fxprotrader »

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.
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: Alternating buy and sell signals in indicator-how to

Post by lucklogic »

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
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: Alternating buy and sell signals in indicator-how to

Post by fxdaytrader »

should work so:
You do not have the required permissions to view the files attached to this post.
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: Alternating buy and sell signals in indicator-how to

Post by lucklogic »

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
Post Reply

Return to “Coders Hangout”