// -----------------------------------------------------------------
// bias line used for deciding whether to go long or short
function rule01Bias()
{
rule01Bias = series(SMA(series(priceClose()),100)) ;
}
// -----------------------------------------------------------------
// rule01_Buy bar pattern definition for going Long
function rule01_Buy()
{
rule01_Buy = priceClose(1) > rule01Bias(1) && priceHigh(1) < priceHigh(2) && priceLow(1) < priceLow(2) ;
}
// -----------------------------------------------------------------
// rule01_Sell bar pattern definition for going Short
function rule01_Sell()
{
rule01_Sell = priceClose(1) < rule01Bias(1) && (priceHigh(1) > priceHigh(2) && priceLow(1) > priceLow(2) ;
}
// -----------------------------------------------------------------
// setting a stop loss by ATR
function rule01_loss_Exit()
{
rule01_loss_Exit = 1*ATR(100) ;
}
// -----------------------------------------------------------------
// setting a profit target in PIPS
function rule01_profit_Exit()
{
rule01_profit_Exit = 50*PIPS ;
}
// -----------------------------------------------------------------
// setting a trailing stop by ATR
function rule01_profit_Trail()
{
rule01_profit_Trail = 4*ATR(100) ;
}
// -----------------------------------------------------------------
// used for setting target entry price for Long
function market_Long()
{
market_Long = (priceHigh(1) + 3*PIPS) ;
}
// -----------------------------------------------------------------
// used for setting target entry price for Short
function market_Short()
{
market_Short = (priceLow(1) - 3*PIPS) ;
}
// -----------------------------------------------------------------
// logic execution
function run()
{
Stop = rule01_loss_Exit ;
TakeProfit = rule01_profit_Exit ;
Trail = rule01_profit_Trail ;
vars Price = series(priceClose()) ;
if (rule01_Buy)
enterLong(market_Long) ;
else if (rule01_Sell)
enterShort(market_Short) ;
}
// -----------------------------------------------------------------