You are on page 1of 2

one candle has closed below the lower bollinger line and the next candle has

closed above that same line so thats what i am looking for and when that
happens at the begginig of the following bar yellow line i will set a buy stop
just above the top of the candle that have closed inside the bollinger band
if the caandle closes above the top bolinger band and then the next candle
closes below that upper bollinger line i will place a sell stop below that line
and if the following candle didnt reach the trade i will set expireses on
these trades and the take profits and the stoploss are based on your opinion

input int InpBandsPeriods;


input double InpBandsDeviation;
input ENUM_APPLIED_PRICE InpBandsAppliedPrice;
////////////////////////////////////////////////////////////////////////
THEN I WANT SOME INPUTS FOR MY TP AND SL DEVIATIONS they are both type double
////////////////////////////////////////////////////////////////////////
input double InpTPDeviations;
input double InpSLDeviations;
////////////////////////////////////////////////////////////////////////
lets add some standard inputs
////////////////////////////////////////////////////////////////////////
input double InpVolume; // the size of each trade
input int InpMagicNumber; //
input string InpTradeComment; //
////////////////////////////////////////////////////////////////////////
now on tick
if (!IsNewBar()) return;
// next i want to capture some values from tha candle that have just closed
// first i want the close price from that candle and here im caling iclose
// function passing in the symbol,period and im looking at bar number 1
// and also want the high and the kow values because if i do excute a trade
// remember that im trading buy just above the high of the bar that has
// closed and im trading sells just below the bar that have just closed
// so this will give me the high low and close values of the bar that have just
// closed

double close1 = iClose(Symbol(), Period(), 1);


double high1 = iHigh (Symbol(), Period(), 1);
double low1 = iLow (Symbol(), Period(), 1);
// next i wnat to get the value of the upper line of the bollinger band
// so im declaring a type double upper1 because its going to upper of
// bar that have just closed
/////////////////////////////////////////////////////////////////////////
based on the strategy i only want to trade at the beggining of each bar so
im calling this function IsNewBar wich will return true or false if this is
the first time ontick called in the bar
/////////////////////////////////////////////////////////////////////////
i have 2 variables inside this function first the open time for the cuurent
bar so its a typr datetime the current bar time and im using the i time
function passing in the current symbol from the current chart, period from
the current chart as the time fram asking for the open time of bar 0
and im aslo declaring adatetime variable called pervbartime and declaring
that as static so im isiilising this prevbartime to be currentbartime
but by calling it static that intiliation only happens the first time this
function is called after the expert advisor started each time we come to
this function after that pervbartime will have the same value it had when
we exited from this function earlear
if the prevbartime is less than the currentbartime then we have must
opend a new bar and in that case im updating prevbartime to be the new
currentbartime now remember this value is going to be stored and will
be the same next time we come into this loop so i updated to be the
currentbartime and i just return true and this tells me that we have
started a new bar
if prevbartime is not less than currentbartime then i just return
false
///////////////////////////////////////////////////////////////////
bool IsNewBar() {
datetime currentBarTime = iTime(Symbol(), Period(), 0);
static datetime prevBarTime = currentBarTime;
if(prevBarTime<currentBarTime) {
prevBarTime=currentBarTime;
return(true);
}
return(false);
}

You might also like