Hi, I would like to place a buy stop order if the price reaches the "lowerband" but the code I have buys me whether or not it reaches that level. On the other hand, I would like to close the position at the first profitable opening from the first trading day. For example, if it was opened on a Monday, it could be closed from the first profitable opening from Wednesday, including Wednesday.
Also, it does not make me well the closings, many times it does not make to the level that it should, I attach images. I have painted in orange the price at which it should close, as you can see in the image, the closing price goes down the band one candle, when it should stay at that level and close as I said above, at the first profitable opening from the second day, this one included.
This is the code I have:
//Bands
Lowerband = XXXXXXX;
Upperband = XXXXXXX;
// Bullish Set Up alcista
cond1 = L < Lowerband;
cond2 = xxxxx;
cond3 = xxxxx;
//bearish Set up
cond4 = H > Lowerband;
cond5 = xxxxx;
cond6 = xxxxx;
//Buy
BuySignal = cond1 AND cond2 AND cond3 ;
BuyLimitPrice = Lowerband;
// now we check if limit was hit
Buy = Ref(BuySignal,-1) AND Open < Lowerband;
BuyPrice = max( BuyLimitPrice, Open);
//Sell = BarsSince(Buy) >=2 AND Open>ValueWhen(BuySignal, Lowerband);
Sell = Open>ValueWhen(Buy, BuyPrice);
SellPrice = Open;
//ELIMINAR SENYALS EXTRA//
Buy = ExRem(Buy, Sell);
//Short = ExRem(Short, Cover OR Buy);
Sell = ExRem(Sell, Buy);
//Cover = ExRem(Cover, Short);
//StopLoss
ApplyStop(stopTypeLoss, stopModePercent, 5, 1, False);
//pantalla
Plot(Upperband, "Upperband", colorGreen, styleLine);
Plot(Lowerband, "Loweband", colorRed, styleLine);
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -15 );
PlotShapes( IIf( Buy , shapeHollowCircle, shapeNone ), colorGreen, 0, BuyPrice, 0 );
//PlotShapes( IIf( Short , shapeDownArrow, shapeNone ), colorBrown, 0, H, -15 );
//PlotShapes( IIf( Short, shapeHollowCircle, shapeNone ), colorBrown, 0, ShortPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, -15 );
PlotShapes( IIf( Sell, shapeHollowCircle, shapeNone ), colorRed, 0, SellPrice, 0 );
//PlotShapes( IIf( Cover AND NOT Buy, shapeUpArrow, shapeNone ), colorDarkGreen, 0, L, -15 );
//PlotShapes( IIf( Cover AND NOT Buy, shapeHollowCircle, shapeNone ), colorDarkGreen, 0, CoverPrice, 0 );
On the other hand, I have two doubts about stoploss, what exactly is stopModePoint? I would like to see or understand more examples since I don't know how to put them well.
Thank you very much in advance!!!