Draw Moving Average by ObjectCreate

 
It should be easy to reach this, but i need help on the way.

I wonna just draw a moving average line on a Chart likes this. (Orange Line)

 



My result is just like this. The lines going are endless to the bottom instead connecting each point to a line. (Red) 



ObjectCreate( "movav" + mytime, OBJ_TREND, 0, Time[0], indicator );


Does Anybody has an easy example Code?
 
chry:
It should be easy to reach this, but i need help on the way.

I wonna just draw a moving average line on a Chart likes this. (Orange Line)

 



My result is just like this. The lines going are endless to the bottom instead connecting each point to a line. (Red) 



ObjectCreate( "movav" + mytime, OBJ_TREND, 0, Time[0], indicator );


Does Anybody has an easy example Code?

You are missing the second price and time for the trend line that you are using and you have to limit that trend line not to extend beyond the two points that you want it to draw from-to. For that you have to change the trend line ray property

Do something like this :

      ObjectCreate( "movav" + mytime, OBJ_TREND,0, Time[0], indicatorValueNow,Time[1], indicatorValuePreviousBar );
         ObjectSet( "movav" + mytime, OBJPROP_RAY,false);
 

ObjectCreate"movav" + mytime, OBJ_TREND0Time[0], indicator );

 

It must have 2 times and 2 prices coordinats. Like this.

 ObjectCreate"movav" + mytime, OBJ_TREND0Time[1], 1.2253 ,Time[0],1.2255);

 
Mladen Rakic:

You are missing the second price and time for the trend line that you are using and you have to limit that trend line not to extend beyond the two points that you want it to draw from-to. For that you have to change the trend line ray property

Do something like this :

      ObjectCreate( "movav" + mytime, OBJ_TREND,0, Time[0], indicatorValueNow,Time[1], indicatorValuePreviousBar );
         ObjectSet( "movav" + mytime, OBJPROP_RAY,false);

and for current bar he needs

ObjectMove"movav" + mytime,0, Time[0], indicatorValueNow);

 ObjectMove"movav" + mytime,1, Time[1], indicatorValuePreviousBar);

 
double  MA8_0;
double  MA8[];
int maNameNumber;
void OnTick()
  {
    drawMA();
    ChartRedraw(0);
}
int OnInit()
  {
  maNameNumber = 0;
  maNameNumber = "A";
  MA8_0 = iMA(_Symbol, timeframe, 8, 0, MODE_EMA, PRICE_CLOSE);
  ArraySetAsSeries(MA8,true);
}
void drawMA(){
    int MA_Thinkness = 3;
    CopyBuffer(MA8_0,0,0,3,MA8);
   
   if (NewBar() || maName == "A"){
   maNameNumber++;
   maName = IntegerToString(maNameNumber);
    }
   else{
    maName = maName;
    }
    ObjectCreate( 0,maName+"8" ,OBJ_TREND ,0, iTime(_Symbol,timeframe,1), MA8[1],iTime(_Symbol,timeframe,0), MA8[0] );
    ObjectSetInteger(0, maName+"8", OBJPROP_RAY,false);
    ObjectSetInteger(0, maName+"8", OBJPROP_COLOR,clrMagenta);
    ObjectSetInteger(0, maName+"8", OBJPROP_WIDTH,MA_Thinkness);
   
 }

enjoy ;)

Reason: