MA ( Close,500) need help

global B1;


Buy = Cross( Close,   MA( Close, 500) );
Sell = Cross( MA( Close,500),  Close    );

B1 = IIf( Close >  MA( Close, 199) , 7, 111 ); 
 

printf("Value Of B1 is = %g\n",B1 );

if (LASTVALUE(B1)==7)

ShellExecute("NOTEPAD.EXE", "", "" );

B1 = IIf( Close > MA( Close, 199) , 7, 111 );

Notice the number 199, this is the maximum number i can have.
if i put 200 or more ( i need 500), the result will be like this:
Value Of B1 is = -1e+010

I would like to know, what is the workaround for my problem.

Thanks

How many bars do you see in your chart ?

I have historical data from 2016-Sep, with 1H or 30M, i believe the charts have more than 500 bars.

image

The first valid value for MA(C,500) won't be produced until the 501st bar. All previous bars (0-500) will be NULL and won't chart.

1 Like

@paulchivers I believe @ab-ami was using 1 hour intra-day data, so that would create enough bars for a 500 bar moving average.

I would suggest running a simple Explore to see what your variables are doing. Perhaps something like this,

Buy = Cross( Close,   MA( Close, 500 ) );
Sell = Cross( MA( Close, 500 ),  Close );

B1 = IIf( Close >  MA( Close, 500 ) , 7, 111 );


Filter = 1;
Buy_color = IIf( Buy, colorLime, colorDefault );
SELL_color = IIf( Sell, colorRose, colorDefault );

AddColumn( Close, "Close" );
AddColumn( Buy, "Buy", 1.0, colorDefault, Buy_color );
AddColumn( Sell, "Sell", 1.0, colorDefault, SELL_color );
AddColumn( B1, "B1", 1.0, colorDefault, colorLightYellow );
AddColumn( MA( Close, 500 ), "MA( Close,500)", 1.2 );

Producing an Exploration output something like this,
image

2 Likes