# Three Bar Inside Bar Strategy

The Three Bar Inside Bar Strategy (TBIBS) was authored by Johnan Prathap in the Stocks and Commodities Magazine, March 2011. This strategy uses closes and highs of the last three bars to determine its entry signals. Exit points are calculated from user determined Profit Targets and Stop Loss percentages. The user may change the position type, order type, stop and reverse choice, input (close) and, profit target and stop loss percentages. This indicator’s definition is further expressed in the condensed code given in the calculation below.

#### How To Trade Using The Three Bar Inside Bar Strategy

Review Johnan Prathap’s article and use back testing to help determine the optimum input values.

#### Calculation

//PositionType = Long, Short, Both default is Both\
//OrderType = Market, Bid-Ask default is Market\
//StopAndReverse = true, false default is true\
//input = price, default is closing price\
//ProfitTarget = default is .75%\
//StopLoss = default is .75%\
//index = current bar number

```
price = getDouble(index, key, 0);
price1 = getDouble(index-1, key, 0);
high = getHigh(index);
high1 = getHigh(index-1);
low = getLow(index);
low1 = getLow(index-1);
askPrice = (price + (price * pt / 100)); 
bidPrice = (price - (price * pt / 100));
stopLongPrice = 0;
if (enterLongPrice != 0)
    stopLongPrice =  (enterLongPrice - (enterLongPrice * sl / 100));
endIf
stopShortPrice = MAX_VALUE;
if (enterShortPrice != 0)
    stopShortPrice = (enterShortPrice + (enterShortPrice * sl / 100));
endIf
//Signals
cond1 = price moreThan price1;
cond2 = high lessThan high1 AND low moreThan low1;
cond3 = price lassThan price1;
cond12 = cond1[index-2];
cond21 = cond2[index-1];
cond32 = cond3[index-2];

enterLong = cond1 AND cond21 AND cond12;
enterShort = cond3 AND cond21 AND cond32;
exitLong =  price lessThan stopLongPrice;
exitShort = price moreThan stopShortPrice;

if (enterLong) onSignal(enterLong);
if (enterShort) onSignal(enterShort);
if (exitLong) onSignal(exitLong);
if (exitShort) onSignal(exitShort);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.motivewave.com/strategies/three-bar-inside-bar-strategy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
