# Short signal Short position

I am trying to design a strategy based on entry and exit conditions for both long and short positions.
For long trades, it seems that the chart generates the correct signals but when opening short positions the system does not give me "short" signals at all.

On the other hand, I also don't understand why the system gives me a Sell or Cover signal if there is no Buy or Short signal previously.

I've been looking in the forum to see if the problem comes from the exrem but I haven't finished solving the problem.
Thanks  ``````
Maxi = HHV (Close, 52);
distanciamax = abs (C - Maxi)/ C *100;
Minim = LLV (Close, 52);
distanciamin = abs(C - Minim)/ C *100;

//Segunda variable Riesgo Stop.

//Calculo del Capital Proporcionado Medio (CPM)

CPM=Volume*Close;

volmax=HHV(CPM,52);
vol=((cpm*100/volmax)*4/5);
volpmed=EMA(vol,52);
CPM2=(vol-volpmed);

//Tercera variable Media simple de 5 semanas del CPM.

SMA5 = MA (CPM2, 5);

//Cuarta variable: Media simple de 20 semanas del CPM

SMA20 = MA (CPM2, 20);

Sell=0;
Short=0;
Cover=0;

sellsetup=WeinstenLargoSalida;
sellstop=Close;
sell=sellsetup;
sellPrice=sellstop;

Shortstop=Close;
Short=Shortsetup;
ShortPrice=Shortstop;

Coversetup=WeinstenCortoSalida;
Coverstop=Close;
Cover=Coversetup;
CoverPrice=Coverstop;

Short = exrem(Short, Cover);
Cover = exrem(Cover, Short);

// Damos salida a las señales

fntsize = 8;// font size
dist = 35;// y-offset

bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
dt = DateTime();

dtformat = "\n%d-%m-%y\n";
bkcolor = 5;// text background color, -1 means default color (transparent)

PlotTextSetFont( "", "ARIAL", fntsize, BarCount-1, 0, -1 );

PlotShapes(Sell*shapeDownArrow,colorRed);

PlotShapes(short*shapeDownArrow,colorRed);

PlotShapes(Cover*shapeSquare,colorRed);

for ( i = fvb; i <= lvb; i++ ) {

if( Buy[i] || Sell[i] || Short[i] || Cover[i] )	{

var = "\n" + DateTimeFormat(dtformat, dt[i]) ;

if( Buy[i]  )  PlotText( "Buy " + var + BuyPrice , i, L[i], colorGreen, 5, -dist+2*fntsize );

if( Sell[i] AND !Short[i] ) PlotText( "Sell " + var + sellPrice, i, H[i], colorRed, 7, dist  );

if( Short[i] ) PlotText( "Short " + var + ShortPrice , i, H[i], colorRed, 5,  -dist+2*fntsize    );

if( Cover[i] AND !Buy[i]) PlotText( "Cover " + var + CoverPrice , i, L[i], colorRed, 7, dist  );

}
}
``````
1. There is an error in your code, variable "mercado" is not assigned.
2. It seems that the sell/cover signals you are seeing are in beginning of the chart.
Exrem removes excessive signals, so whatever your first signal is exrem will not prevent that.
After that, you will always need a buy signal for a sell signal to occur.
3. As for short signals, when i change logic i see short signals...
Can check How do I debug my formula?

On the other hand, I do not see the point of the chart giving a Sell or Cover signal if there is no previous signal.

``````mercado="AMERICANO";
sector="SPX";

if (MarketID()==1 OR MarketID()==2)
{
}

if (MarketID()==3)
{
}

if (MarketID()==4)
{
}

if (MarketID()==5)
{
}
``````

Maybe you have it assigned, but not in the piece of code you initially posted. So if anyone wants to help and copy your code they get an error.

AB cannot think for you, it's you who writes the code.

``````BuyPrice=ValueWhen(Buy,Close);