Please help with indicator based on stoch at close or open of a bar.

 

I have written an indicator that gives me an alert when Stochastic gets over 80 or under 20, but it alerts me the second it hits the parameters, and what I would like is for it to only alert me if over 80 or under 20 when the current timeframe bar closes. Can anyone help me out with that? Here is what I am using so far... (thanks fxfisherman). If anyone can help I would be very appreciative.

//+------------------------------------------------------------------+

//| Stochastic (with alert) |

//| Copyright © 2006 Scorpion@fxfisherman.com |

//| Sound-alert mod by FXSamurai |

//+------------------------------------------------------------------+

#property copyright "FxFisherman.com"

#property link "http://www.fxfisherman.com"


#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Teal

#property indicator_color2 Red

#property indicator_minimum 0

#property indicator_maximum 100


extern string ________General_______;

extern int K = 8;

extern int D = 3;

extern int Slowing = 3;

extern int MA_Mode = 0; // 0 = SMA, 1 = EMA,

extern int Shift_Bars=0;

extern int Bars_Count= 0;


extern string _________Alert________;

extern double Overbuy_Level = 76.4;

extern double Oversell_Level = 23.6;

extern bool Enable_Alert_1 = true;

extern double Crossover_Gap = 0;

extern bool Enable_Alert_2 = true;


//---- buffers

double v1[];

double v2[];

int init()

{


IndicatorBuffers(2);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);

SetIndexDrawBegin(0,K+Slowing);

SetIndexBuffer(0, v1);

SetIndexLabel(0,"K");

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);

SetIndexDrawBegin(1,K+D+Slowing);

SetIndexBuffer(1, v2);

SetIndexLabel(1,"D");

watermark();

return(0);

}


int start()

{

int i;

int shift;

int counted_bars = IndicatorCounted();

if (counted_bars > 0) counted_bars--;

if (Bars_Count > 0 && Bars_Count <= Bars)

{

i = Bars_Count - counted_bars;

}else{

i = Bars - counted_bars;

}

while(i>=0)

{

shift = i + Shift_Bars;

v1[i] = iStochastic(Symbol(), Period(), K, D, Slowing, MA_Mode, 0, 0, shift);

v2[i] = iStochastic(Symbol(), Period(), K, D, Slowing, MA_Mode, 0, 1, shift);

Print(v1[i]);

i--;

}

// Alert: Overbuy and Oversold

static int OBOS;

if (Enable_Alert_1 && v2[0] >= Overbuy_Level && OBOS != 1)

{

OBOS = 1;

PlaySound("alert.wav");

}else if (Enable_Alert_1 && v2[0] <= Oversell_Level && OBOS != -1){

OBOS = -1;

PlaySound("alert.wav");

}

// Alert crossover

static int Crossover;

if (Enable_Alert_2 && v1[1] < v2[0] + Crossover_Gap && v1[0] >= v2[0] + Crossover_Gap && Crossover != 1) {

Crossover = 1;

PlaySound("alert.wav");

}else if(Enable_Alert_2 && v1[1] > v2[0] - Crossover_Gap && v1[0] <= v2[0] - Crossover_Gap && Crossover != -1) {

Crossover = -1;

PlaySound("alert.wav");

}

return(0);

}

//+------------------------------------------------------------------+

void watermark()

{

ObjectCreate("fxfisherman", OBJ_LABEL, 0, 0, 0);

ObjectSetText("fxfisherman", "fxfisherman.com - Stochastic alert - D cross", 11, "Lucida Handwriting", RoyalBlue);

ObjectSet("fxfisherman", OBJPROP_CORNER, 2);

ObjectSet("fxfisherman", OBJPROP_XDISTANCE, 5);

ObjectSet("fxfisherman", OBJPROP_YDISTANCE, 10);

return(0);

}

 

don't check v1[0] or v2[0] check on v1[1] & v2[1]

 
qjol:

don't check v1[0] or v2[0] check on v1[1] & v2[1]


Awesome, I will do that, thanks!