How to stop plotting consecutive buy, sell ,cover and short shape


#1

Date November 9th of 2018
NIFTY-FUT : 30 min Candel,

I have requirement where I want to plot a buy/sell/short/cover signals once at a time

what I did so far:

  1. Check the first bar high and low value then create horizontal line (Done )
  2. Buy and sell target will be 20 points + or - of first bar high/low (done)
  3. Now want to put the buy shape on those candles which going above the buy target (Step 1) and sell shape on those candle which going below the sell target (step 1) ( Done )

Here is the below logic for the same… how to stop plotting consecutive buy,sell , cover and short shape ( I read that we can use bflag but don’t know how in this below case )

I am getting to cover plot at 9.45am and 9.45am… :frowning:

_SECTION_BEGIN(“Price”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, “Close”, ParamColor(“Color”, colorDefault ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();

maxFir = ValueWhen(Day()!=Ref(Day(),-1),H);//,ValueWhen(Day()!=Ref(Day(),-1),H));//max value of first bar of the day
minFir = ValueWhen(Day()!=Ref(Day(),-1),L);//,ValueWhen(Day()!=Ref(Day(),-1),L));//Min value of first bar of the day

Plot(maxFir,“HB”,colorRed,styleDots,Null,Null,0,0,1);
Plot(minFir,“LB”,colorRed,styleDots,Null,Null,0,0,1);

buyExitTarget = maxFir + 20; // exit target is +20
sellExitTarget = minFir - 20; // exit target is -20

Plot(buyExitTarget,“BT:”,colorWhite,styleStaircase,Null,Null,0,0,1);
Plot(sellExitTarget,“ST:”,colorWhite,styleStaircase,Null,Null,0,0,1);

Buy = Cross(High,maxFir); // if true then plot buy shape
Sell= Cross(minFir,Low); // if true then plot sell shape

Buy = ExRem(Buy, Sell);
Sell= ExRem(Sell, Buy);

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes(shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
GraphXSpace = 5;

Plot(Buy,“B”,colorWhite,styleBar,Null,Null,0,0,1);
Plot(Sell,“S”,colorWhite,styleBar,Null,Null,0,0,1);

//If buy and sell target acheived then exit from the trade

Short=High>buyExitTarget;
Cover=Low<sellExitTarget;

Short=ExRem(Short,buy );
Cover=ExRem(Cover,Sell );

shape = Cover * shapeStar + Short * shapeStar;
PlotShapes( shape, IIf( Cover, colorWhite, colorWhite ), 0, IIf( Cover, Low, High ) );
GraphXSpace = 5;


#2

try to write buy/sell rules only (not short cover) in a loop, I will correct it.


#3

I wrote my code can you please check and correct on the same or share me any example if you have with comments so that I can understand easily…


#4

I think short cover is required when want to exit once you get the profit or target acheived.
I have already written the code for Buy/sell rule