You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Could some kind soul please explain what is wrong with the following code.
1. It sort of works but does not update once chart is loaded
2. If I try to change timeframe on chart then the application hangs?
Any help appreciated.
My code.........
#property indicator_chart_window
double mR1, mS1;
int mH = 0, mL = 0;
extern int mPeriod = 11,
mHist = 100 ;
//-----------------------------------------------+
int init()
{
mR1 = High[0];
mS1 = Low[0];
return(0);
}
//-----------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit= MathMin(Bars, mHist) - counted_bars;
for(int i = limit; i > 0; i--)
{
if (High[i+mPeriod+1] >= High[iHighest(NULL,0,MODE_HIGH, mPeriod, i)]
&& High[i+mPeriod+1] >= High[iHighest(NULL,0,MODE_HIGH, mPeriod, i+mPeriod+2)] )
{
mH++;
mR1 = High[i+mPeriod+1];
// ObjectDelete("mRes");
ObjectCreate("mRes"+mH, OBJ_TREND, 0, Time[i+mPeriod+1], mR1, Time, mR1);
ObjectSet("mRes"+mH,OBJPROP_RAY, false);
ObjectSet("mRes"+mH, OBJPROP_WIDTH,1);
ObjectSet("mRes"+mH, OBJPROP_STYLE,0);
ObjectSet("mRes"+mH, OBJPROP_COLOR, Blue);
}
if (Low[i+mPeriod+1] <= Low[iLowest(NULL,0,MODE_LOW, mPeriod, i)]
&& Low[i+mPeriod+1] <= Low[iLowest(NULL,0,MODE_LOW, mPeriod, i+mPeriod+2)] )
{
mL++;
mS1 = Low[i+mPeriod+1];
//ObjectDelete("mRes");
ObjectCreate("mSupp"+mL, OBJ_TREND, 0, Time[i+mPeriod+1], mS1, Time, mS1);
ObjectSet("mSupp"+mL,OBJPROP_RAY, false);
ObjectSet("mSupp"+mL, OBJPROP_WIDTH,1);
ObjectSet("mSupp"+mL, OBJPROP_STYLE,0);
ObjectSet("mSupp"+mL, OBJPROP_COLOR, Red);
}
}
return(0);
}
//-----------------------------------------------+
int deinit()
{
for(int z = 1; z <= mH; z++)
{
ObjectDelete("mRes"+z);
}
for(int y = 1; z <= mL; y++)
{
ObjectDelete("mSupp");
}
return(0);
}
//-----------------------------------------------+
TIA