# BrekoutMediaMobile

160

Hello guys, the following function that I created should draw a green line if the "[i] n-1 [/ i]" candle is less than the average and if the candle [i] n [/ i] is greater than the average (in other words, if the average cuts from below to above the candle) and on the contrary a red line if the "[i] n-1 [/ i]" candle is greater than the average and if the [i] n [ i] is less than the average (in other words, if the average cuts from above to below the candle)
To reassume
If n -1 closes below the average and n closes above the average, then green line on the n + 1 candle
reverse
If n -1 closes above the average and n closes below the average, then red line on n + 1 candle

can anyone tell me how to set it up?

```int BrekoutMediaMobile(int MediaPer)
{
double Mmoblie;
Mmoblie = iMA(Symbol(),Period(),MediaPer,0,MODE_EMA,PRICE_CLOSE,1);

if((Close[2]< Mmoblie)&& (Close[1]>Mmoblie))
{
ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,clrDarkGreen);
}
else if((Close[2] > Mmoblie)&& (Close[1]< Mmoblie))
{
ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,clrDarkRed);
}

return 0;
}
```