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.
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 );
}
}