| |
 |
B % oscillator system
|
 |
|
|
|
Views:
595 |
| Added: November 16, 2008 |
| |
|
|
|
| This formula has not been rated yet |
| |
| |
email this link
|
| |
| |
| Tags:
MetaTrader, system
|
| |
 |
% b oscillator system
Code:
/*[[
Name := % b
Author := Copyright © 2005, Lynndal Daniels, Nick Bilak
Link :=
Notes :=
Lots := 1
Stop Loss := 120
Take Profit := 800
Trailing Stop := 0
]]*/
Defines: mprd(200),bprd(5),bdev(1),bdays(3),bhi(0.8),blo(0.2),rule4(1),slippage(7),risk(10),mm(0);
var: i(0),buysig(false),sellsig(false),buyaddsig(false),selladdsig(false),exitlong(false),exitshort(false);
var: lotsi(0),orders(0);
Arrays: pb[5](0);
If Bars<1 or TakeProfit<10 then Exit;
If FreeMargin<200 then Exit;
If((CurTime-LastTradeTime)<10) then Exit;
if mm<>0 then
lotsi=Ceil(Balance*risk/10000)/10
else
lotsi=lots;
orders=0;
For i=1 to TotalTrades {
If Ord(i,Val_Symbol)=Symbol then {
orders++;
};
};
//get %b
//%b is defined as: %b= (Close - Lower Bollinger Band)/(Upper Bollinger Band - Lower Bollinger Band)
for i=1 to 4 {
pb[i]=(C[i]-iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_LOW,i))/(iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_HIGH,i)-iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_LOW,i));
};
/*
Rules for Long Entries:
1.) The market closes above its 200-day moving average. (SMA)
2.) The %b closes below 0.2 for 3 days in a row.
3.) Buy the market at the close (or at the next opening) when rules 1 & 2 are met
4.) Buy an additional unit if/when %b closes below 0.2 for 4 days in a row (1 additional day)
5.) Exit at the close when %b closes above 0.8
Rules for Shorts:
1.) The market closes below its 200 day MA
2.) The %b closes above 0.8 for 3 days in a row
3.) Sell the market at close (or at the next opening) when rules 1 & 2 are met
4.) Sell an additional unit if/when %b closes above 0.8 for 4 days in a row (1 additional day)
5.) Exit at the close when %b closes below 0.2
*/
if c[1]>iMA(mprd,MODE_SMA,1) and pb[1]
//if c[2]<=iMA(mprd,MODE_SMA,2) and c[1]>iMA(mprd,MODE_SMA,1) and pb[1]
buysig=true;
exitlong=false;
if rule4=1 and orders=1 and pb[4]
};
if c[1]bhi and pb[2]>bhi and pb[3]>bhi then {
//if c[2]>=iMA(mprd,MODE_SMA,2) and c[1]bhi and pb[2]>bhi and pb[3]>bhi then {
sellsig=true;
exitshort=false;
if rule4=1 and orders=1 and pb[4]>bhi then selladdsig=true;
};
if pb[1]>bhi then exitlong=true;
if pb[1]
if orders>0 then {
for i=1 to TotalTrades {
if ord(i,VAL_SYMBOL)=Symbol and ord(i,VAL_TYPE)=OP_SELL and exitshort then {
CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),ord(i,VAL_CLOSEPRICE),slippage,white);
exit;
};
if ord(i,VAL_SYMBOL)=Symbol and ord(i,VAL_TYPE)=OP_BUY and exitlong then {
CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),ord(i,VAL_CLOSEPRICE),slippage,white);
exit;
};
};
};
if orders=0 and buysig then {
buysig=false;
SetOrder(OP_BUY,lotsi,ask,Slippage,ask-StopLoss*point,ask+TakeProfit*point,blue);
exit;
};
if orders=0 and sellsig then {
sellsig=false;
SetOrder(OP_SELL,lotsi,bid,Slippage,bid+StopLoss*point,bid-TakeProfit*point,red);
exit;
};
if buyaddsig then {
buyaddsig=false;
SetOrder(OP_BUY,lotsi,ask,Slippage,ask-StopLoss*point,ask+TakeProfit*point,blue);
exit;
};
if selladdsig then {
selladdsig=false;
SetOrder(OP_SELL,lotsi,bid,Slippage,bid+StopLoss*point,bid-TakeProfit*point,red);
exit;
};
Code to difficult? Find somebody to help you with coding here.
Author: Lynndal Daniels, Nick Bilak
Source: www.xeatrade.com
all systems for MetaTrader
all systems
|