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
image
image


Maxi = HHV (Close, 52);
distanciamax = abs (C - Maxi)/ C *100;
Minim = LLV (Close, 52);
distanciamin = abs(C - Minim)/ C *100;

//Segunda variable Riesgo Stop.

RSStop=abs(Close-WMA(Close,30))/Close*100;

//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);


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


WeinstenLargoEntrada=WMA(C,30) > Ref(WMA(C,30),-1) AND distanciamax<=2 AND RSStop<=9 AND RSStop>3 AND SMA5>0 AND SMA20>-15  and IIf(mercado=="AMERICANO",MA(CPM,52)>40000000,MA(CPM,52)>3000000);


Buysetup=WeinstenLargoEntrada;
Buystop=Close;
Buy=Buysetup;
BuyPrice=Buystop;

WeinstenLargoSalida=SMA20<-15 OR RSStop>30;

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


	

WeinstenCortoEntrada=WMA(C,30) < Ref(WMA(C,30),-1) AND distanciamin<=0.9 AND  RSStop<=9 AND RSStop>3 AND SMA5<0 AND SMA20>10  AND IIf(mercado=="AMERICANO",MA(CPM,52)>40000000,MA(CPM,52)>3000000);


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

WeinstenCortoSalida= SMA20>0 OR RSStop>30;


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


Buy = exrem(Buy, Sell );
Sell = exrem(Sell, Buy);
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(Buy*shapeUpArrow,colorBlue,0,Graph0,-12);


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?

Thanks for your answer but the variable "mercado" is assigned.

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)
{
	mercado="AMERICANO";
}

if (MarketID()==3)
{
	mercado="EUROPEO";
}

if (MarketID()==4)
{
	mercado="NORDICO";
}

if (MarketID()==5)
{
	mercado="SUIZO";
}

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);
sell=sellsetup AND BuyPrice>0;

Here is example of how you can avoid first sell signal.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.