log in     sign up for free
 
In my opinion, you do not have a trading system unless you know exactly when you will get out of the market position at the time you enter it.
Van K. Tharp
 
 
Home
systems (285)
 
 
Special offer: buy MetaStock (try for free)   |   Reuters QuoteCenter Real-Time Data (get a free month)   |   EOD Data
 

Buy

MetaStock

     (special offer)
 
 
 

Buy

EOD data for MetaStock

     (special offer)
 
 
 

Buy

Realtime data for MetaStock

     (special offer)
 
 
Formula Library
 
AmiBroker
MetaTrader
MetaStock
TradeStation
Wealth-Lab
NinjaTrader
 
add your formula
System Library
 
 
Account login
Your email:
Password:
 
Log in
New to s4t? Sign up.
If you forgot your password click here.
Search the Web
 
Custom Search

Always In Play

System for: MetaTrader

 

 

Views:  2145

Added: November 16, 2008
 
Rate this code:  Rate: 1 Rate: 2 Rate: 3 Rate: 4 Rate: 5
This formula has not been rated yet
 
 

email this link

 
 
Tags: MetaTrader, system
 




Code:

/*[[
ALWAYS IN PLAY
Lots := 1.00
Notes := Best if use in H1 or higher timeframe
Update on every tick := Yes
Enable Alerts := Yes
Disable alert once hit := No
Lots := 1
Stop Loss := 999
Take Profit := 25
Trailing Stop := 999
]]*/

// =========================================================
// DECLARATION

defines: risk(25),mm(1);
vars: spread(0),
Slippage(5),
sl(0),tp(0),maxSimOpen(0),
mode(0),
buffer(0),
lastHigh(0),
target(0),
entryTS(0),
lastLow(0),
cnt(0),
first(0),
lotMM(0),
tHour(0);

cnt= 1;

// =========================================================
// VALIDATION

If CurTime - LastTradeTime < 300 Then Exit;
If Bars<100 or TakeProfit<10 then Exit;
If IsIndirect(Symbol)=TRUE then Exit;

// =========================================================
// DATE CHOKE - For testing purposes

If TimeYear(time[0]) < 2004 then {
Exit;
} else if
TimeMonth(time[0]) < 2 then {
Exit;
};

// =========================================================
// PYRAMIDING - LINEAR
//
// Money management risk exposure compounding

if mm<>0 then
{
lotMM=Ceil(Balance*risk/10000)/10;
if lotMM < 0.1 then {
lotMM = lots;
};
If lotMM > 1 then {
lotMM = Ceil(lotMM);
};
If lotMM > 100 then {
lotMM = 100;
};
} else {
lotMM=Lots;
};

// Adding simultaneously opened position

if mm = 1 then {
If balance < 1000000 then maxSimOpen=1;

If balance > 1000000 then {
maxSimOpen=(Balance*risk/10000)/1000;
} else {
maxSimOpen=1;
}
};

if mm = 2 then {
if balance < 1000000 then maxSimOpen=1;

if balance > 1000000 then {
maxSimOpen=(Balance*risk/10000)/1000;
if maxSimOpen > 20 then maxSimOpen=20;
} else {
maxSimOpen=1;
};
};

entryTS = 10*Point; //Entry trailing stop - points
buffer = 1.0*Point; //Filter/buffer above or below bar High/Low - points
target = TakeProfit*Point; //Profit target - points
lastHigh = High[1]; //Last bar high
lastLow = Low[1]; //Last bar low
spread = Bid-Ask; //Spread

// =========================================================
// TRADE ENTRY

tHour = GetGlobalVariable("tHour");

If TotalTrades
//SHORT TRADES ENTRY CRITERIA
If Open[1]>Close[1] and //Last bar bearish, open greater than close;
Ask-lastLow<10*Point and //if Bid rises or falls to within 10pips of Low [1] bar ago, allow order to set;
iSAR(0.05,0.5,0)>Bid and
tHour != TimeHour(time[0]) then
{
SetGlobalVariable("tHour",TimeMinute(time[0]));

// Set stoploss to last bar high + spread
sl = lastHigh+spread;

//place order to sell m-s equals Low[1]-1pip;
//Sell on stop, 1 lot,at:Low[1]-1pip,slip0,Target:Low[1]-1pip-25pip;
SetOrder(OP_SELLSTOP,
lotMM,
lastLow-buffer-spread,
Slippage,
sl,
lastLow-buffer-spread-target,
RED);
Exit;
};

//LONG TRADES ENTRY CRITERIA
If Open[1] lastHigh-Bid<10*Point and //if Bid rises or falls to within 10pips of High[1] bar ago, allow order to set;
iSAR(0.05,0.5,0) tHour != TimeHour(time[0]) then
{
SetGlobalVariable("tHour",TimeMinute(time[0]));

sl = lastLow+spread;

SetOrder(OP_BUYSTOP,
lotMM,
lastHigh+buffer+spread,
Slippage,
sl,
lastHigh+buffer+spread+target,
LIME);
Exit;
};

};

// =========================================================
// TRAILING STOP ADJUSTMENT

If TrailingStop<5 then {print("invalid Trailing Stop");Exit;};

For cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);

If mode=OP_BUY then
{
//if Bid-open price is now higher than 10pips profit....
If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(entryTS) then
{
//and the value of the stop loss order is lower than 10pips below the Bid...
If OrderValue(cnt,VAL_STOPLOSS)<(Bid-entryTS) then
{
//then adjust the stop loss part of the order to the Bid - 10pips
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
Bid-entryTS,
OrderValue(cnt,VAL_TAKEPROFIT),
BLUE);
Exit;
};
};

If OrderValue(cnt,VAL_STOPLOSS)>=OrderValue(cnt,VAL_OPENPRICE) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
OrderValue(cnt,VAL_STOPLOSS),
Ask+TakeProfit*Point,
BLUE);
Exit;
};
};

If mode=OP_SELL then
{
//if current Ask price dropped 10 pips or more below the open price
If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(entryTS) then
{
//and the stop loss order is greater than 10pips above the current Ask..
If OrderValue(cnt,VAL_STOPLOSS)>(Ask+entryTS) then
{
//then adjust the stop loss part of the order to Ask+10pips
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
Ask+entryTS,
OrderValue(cnt,VAL_TAKEPROFIT),
BLUE);
Exit;
};
};

If OrderValue(cnt,VAL_STOPLOSS)<=OrderValue(cnt,VAL_OPENPRICE) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
OrderValue(cnt,VAL_STOPLOSS),
Bid-TakeProfit*Point,
BLUE);
Exit;
};

// =========================================================
// CLEANING PENDING TRADES
// check how long it exists in the trading terminal - time is counted in seconds
// if the current time ignoring hours is greater than 58minutes cancel the open order(allowing new one to place).

If mode>OP_SELLSTOP then
{
If Minute>58 then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),INDIGO);
Exit;
};
};

If mode>OP_BUYSTOP then
{
If Minute>58 then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),INDIGO);
Exit;
};
};

};

};

Exit;



 




 

Code to difficult? Find somebody to help you with coding here.

 

 

View similar:

2EMA system
2EMA System-v03
2ways system
5min USDCHF
Always In Play
ASC Trend ++ Expert(v.2.1)
Awesome Oscillator auto Trader
Bolliger Breakout Ver 1.0
B % oscillator system
...
 
 
all systems for MetaTrader
all systems

 

 

Email to friend

Top

 

     
However we try to maintain hiqhest possible level of service - most formulas, oscillators, indicators
and systems are submitted by anonymous users.
Therefore S4T™ does not take any responsibility for it's quality.
If you use any of this information, use it at your own risk. You are responsible for your own trading decisions.
Be sure to verify that any information you see on these pages is correct, and is applicable to your particular trade.
In no case will S4T™ be responsible for your trading gains or losses.
PayPalSecure payments by PayPal S4T™ is a part of TAURO EDUCATION NETWORK
 
Privacy note | (c) copyrights systems4trading.com 2006-2009