for(i=0; i<=limit; i++){ ma48 = iMA(...
Count down to the present, not toward the past.
Hi WHRoeder,
Thanks for your quick response. Unfortunately, I do not understand! How do I change the code to count down from the past to the present? I thought it was doing this.
Thanks for your help.
#define PLOTUP 1 #define PLOTDOWN -1 #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Aqua #property indicator_color2 Orange extern int MA_Type = MODE_SMA; extern int App_Price = PRICE_CLOSE; extern int Period_MA_3 = 48; double ma12, ma24, ma48, Bull[], Bear[]; int iWaitFor = PLOTUP, Max_Bars = 100; int init() { SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 225); SetIndexBuffer(0, Bear); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 226); SetIndexBuffer(1, Bull); return(0); } int start() { int limit, counted_bars = IndicatorCounted(); if(counted_bars < 0)return(-1); limit = Bars - counted_bars; if (limit > Max_Bars)limit = Max_Bars; for(int i=0; i<limit; i++){ ma48 = iMA(Symbol(),0,Period_MA_3,0,MA_Type,Close[i+1],i); if ( iWaitFor==PLOTDOWN && Close[i+1] > ma48 && Close[i+1] > Open[i+1] ){ iWaitFor = PLOTUP; Bull[i] = High[i] + 0.0005; Alert("Bull"); } if ( iWaitFor == PLOTUP && Close[i+1] < ma48 && Close[i+1] < Open[i+1] ){ iWaitFor = PLOTDOWN; Bear[i] = Low[i] - 0.0005; Alert("Bear"); } } return(0); }Ok try this............seems to work ok, not sure what it does, so didn't test it.
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
Hello,
I am trying to create an indicator that requires the following three condition be satisfiec before producing an arrow:
if (
iWaitFor==PLOTDOWN && // A
Close[i+1] > ma48 && // B
Close[i+1] > Open[i+1] // C
)
{
iWaitFor = PLOTUP;
Bull[i] = High[i] + 0.0005;
Alert("Bull");
}
Note that there is also a "bear" version of this.
If I execute the code and include only condition A and B (and the equivalent bear) it works fine. When I try and nest them so that both conditions are satisfied it breaksdown. Can anyone provide some information as to what I am doing wrong? (Note that I am new to this)
I am pasting the complete code below.
Thanks for your help.
//+------------------------------------------------------------------+
//| 19151.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Orange
extern int MA_Type = MODE_SMA;
extern int App_Price = PRICE_CLOSE;
extern int Period_MA_3 = 48;
double ma12,
ma24,
ma48;
double Bull[];
double Bear[];
#define PLOTUP 1
#define PLOTDOWN -1
int iWaitFor = PLOTUP;
int init()
{
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 225);
SetIndexBuffer(0, Bear);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 226);
SetIndexBuffer(1, Bull);
return(0);
}
int start()
{
int counted_bars = IndicatorCounted();
int i;
int limit;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(i=0; i<=limit; i++)
{
ma48 = iMA(Symbol(),0,Period_MA_3,0,MA_Type,Close[i+1],i);
if (
iWaitFor==PLOTDOWN &&
Close[i+1] > ma48 &&
Close[i+1] > Open[i+1]
)
{
iWaitFor = PLOTUP;
Bull[i] = High[i] + 0.0005;
Alert("Bull");
}
if (
iWaitFor == PLOTUP &&
Close[i+1] < ma48 &&
Close[i+1] < Open[i+1]
)
{
iWaitFor = PLOTDOWN;
Bear[i] = Low[i] - 0.0005;
Alert("Bear");
}
}
return(0);
}