# more accurate SMA

hello,

so my idea for an algo is pretty simple: I want to buy if two sma cross and i want to close my position and open a sell when the 2 sma cross from the other direction. My probleme here is now that, my algo is not very accurate. The sell or buy happens after one or two candles after the crossover. Is there a way to make it more accurate, so that the bot buys/sells right after the crossover?

``` // 7 sma
static int handlesevenMa = iMA(_Symbol,PERIOD_CURRENT,7,0,MODE_SMA,PRICE_CLOSE);
double SevenMaArray[]; // create an array
CopyBuffer(handlesevenMa,0,1,3,SevenMaArray); // defined 7 SMA, one buffer, current candle, 3 candles, store result
ArraySetAsSeries(SevenMaArray,true); // sort the array from the current candle downwards

// 2 sma
static int handletwoMa = iMA(_Symbol,PERIOD_CURRENT,2,0,MODE_SMA,PRICE_CLOSE);
double TwoMaArray[]; // create an array
CopyBuffer(handletwoMa,0,1,3,TwoMaArray); // defined 7 SMA, one buffer, current candle, 3 candles, store result
ArraySetAsSeries(TwoMaArray,true); // sort the array from the current candle downwards

if(TwoMaArray[1] < SevenMaArray[1] && TwoMaArray[0] > SevenMaArray[0]) // 2 sma is bigger than 7 sma
{
{
Print("TwoMaArray = ",TwoMaArray[0]," > ","SevenMaArray = ",SevenMaArray[0]);
}
{
CloseAllPositions();
Print("SELL is closed");

Print("After closing a sell position: TwoMaArray = ",TwoMaArray[0]," > ","SevenMaArray = ",SevenMaArray[0]);
}
}

if(TwoMaArray[1] > SevenMaArray[1] && TwoMaArray[0] < SevenMaArray[0]) // 7sma is bigger than 2sma
{
if(PositionsTotal()<1) // o trade open --> Sell
{
Print("Sell");
Print("TwoMaArray = ",TwoMaArray[0]," < ","SevenMaArray = ",SevenMaArray[0]);
}

else //if(PositionsTotal()==1) // if a trade is open --> close trade first and than sell
{
CloseAllPositions();