Short signal does not execute after Buy

Hello there,

I'm having problems and need help from all of you, I plan to go short after the price drops -1% of the buy.

Plot ( C, "close", colorwhite, styleline);

EMA1 = EMA(C, 10);
EMA2 = EMA(C, 20);
Plot(EMA1, "", colorAqua, styleLine );
Plot(EMA2, "", colorYellow, styleLine );

//Buy-Rule
Buy1  = Cross(EMA1,EMA2);
PlotShapes (IIf (Buy1, shapeHollowStar, shapeNone), colorred, 0,L, -15 );

//Short-Rule
short1 = ValueWhen(Buy1,C)/1.01;
Short1 = ExRem(short1, Buy1);
PlotShapes (IIf (short1,  shapeSmallUpTriangle, shapeNone), colorWhite, 0,L, -15 );

Buy = buy1 ;
Sell = 0;
Short = Short1 ;
Cover = 0;

ApplyStop(stopTypeProfit,
         stopModePercent,
         Optimize( "max. loss stop level", 3, 2, 30, 1 ),
         True );

a

b

Buy/Long in the begining is 3230 and short 3240, its suppose to be short is 3198 righ ?

thank you

Not tested..

//short1 = ValueWhen(Buy1,C)/1.01;
vw = ValueWhen(Buy1,C)/1.01;
short1 = Cross(vw, Close);
Plot(vw, "vw", colordefault); // use for debug
2 Likes

thank you very much....for the solution

more question please:smile:

c

  1. when the position is buying, and turns into short, the trade will automatically sell long postion.

  2. is it possible not to sell (hold) long positions and open new short executions? so long and short is still opn in the same time ?

See here

  1. SetOption("ReverseSignalForcesExit", False );

  2. SetBacktestMode(backtestRegularRawMulti);

1 Like

thank you fxshrat

other questions if you don't mind, what if we want to add lots like short1 3x the number of lots from buy1 ?

buy_size = 1;
size = IIf(Buy, buy_size, 3*buy_size);
SetPositionSize(size, spsShares);
1 Like

q

Hey awilson,
the short arrow appears many times, i used short=exrem(short, Buy); to remove signal but not working and short is not perform in the backtest, another advise maybe.

thank you

thank you for your answer. do it soon.

I will add some information, that ValueWhentriggers a lot of signals, for that there might be some other way, i try using if......else, but not really undestand how to code it,

Short1  = Null ;
for( i = 0; i < BarCount; i++ )
{
  if( Close[ i ] < (Close[ i ] /1.01)
       Buy2[ i ] = 1;
  else
       Buy2[ i ] = 0; 

Thank you for the help

Rephrase your question and post full code

the problem is solved. Thank you for your attention. appreciate it!:slight_smile: