Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+------------------------------------------------------------------+
- //| Confidence.mq4 |
- //| Copyright © 2010, Sina Sadeghi. |
- //| http://www.launchpad.net/~sina-sa |
- //+------------------------------------------------------------------+
- #property copyright "Copyright © 2010, MetaQuotes Software Corp."
- #property link "http://www.metaquotes.net"
- //
- //Params
- int n=2;
- int s=120;
- bool trend=true;
- bool volfilter=true;
- //State
- double cmd;
- bool newBar()
- {
- static datetime lastbar;
- datetime curbar = Time[0];
- if(lastbar!=curbar)
- {
- lastbar=curbar;
- return (true);
- }
- else
- {
- return(false);
- }
- }
- //+------------------------------------------------------------------+
- //| expert initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- //----
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| expert deinitialization function |
- //+------------------------------------------------------------------+
- int deinit()
- {
- //----
- //----
- return(0);
- }
- double calculatePosSize()
- {
- double x = iWPR(NULL,0,s,1);
- double y = 1;
- if(x >= -100 && x < -90) {
- y = 3;
- }
- if(x >= -90 && x < -80) {
- y = 2.5;
- }
- if(x >= -80 && x < -70) {
- y = 2;
- }
- if(x >= -70 && x < -60) {
- y = 1.5;
- }
- if(x >= -60 && x < -50) {
- y = 1;
- }
- if(x >= -50 && x < -40) {
- y = 1;
- }
- if(x >= -40 && x < -30) {
- y = 1.5;
- }
- if(x >= -30 && x < -20) {
- y = 2;
- }
- if(x >= -20 && x < -10) {
- y = 2.5;
- }
- if(x >= -10 && x < 0) {
- y = 3;
- }
- //;
- //if(AccountFreeMargin() < 10000) { return(0.1); }
- //return( NormalizeDouble(y*(AccountFreeMargin()/100000),2) );
- return(0.01);
- }
- //+------------------------------------------------------------------+
- //| expert start function |
- //+------------------------------------------------------------------+
- int start()
- {
- //----
- if(!newBar()) return(0);
- //ORDER MAINTENANCE
- for(int cnt=OrdersTotal();cnt>=0;cnt--) {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if( OrderSymbol()==Symbol() ) {
- cmd=OrderType();
- //EXIT LONGS
- if(cmd==OP_BUY && OrderMagicNumber() == 11){
- if(trend == true && (Close[1] > Close[n] || Close[1] < Close[s]) ) {
- OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
- }
- if(trend == false && Close[1] > Close[n]) {
- OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
- }
- }
- //EXIT SHORTS
- if(cmd==OP_SELL && OrderMagicNumber() == 21) {
- if(trend == true && (Close[1] < Close[n] || Close[1] > Close[s]) ) {
- OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
- }
- if(trend == false && (Close[1] < Close[n]) ) {
- OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
- }
- }
- }
- }
- double atr=iATR(NULL,0,10,1);
- double atr2=-1;
- if(volfilter==true){
- atr2=iATR(NULL,0,s,1);
- }
- double fact=1;
- //ORDER ENTRY
- if(OrdersTotal() < 1 && atr > atr2){
- //BUY
- if(trend ==true && Close[1] > Close[s] && Close[1] < Close[n]) {
- OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.00003,0,0,NULL,11,0,Blue);
- }
- if(trend == false && Close[1] < Close[n]) {
- OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.00003,0,0,NULL,11,0,Blue);
- }
- //SELL
- if(trend == true && Close[1] < Close[s] && Close[1] > Close[n]) {
- OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.00003,0,0,NULL,21,0,Red);
- }
- if(trend == false && Close[1] > Close[n]) {
- OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.00003,0,0,NULL,21,0,Red);
- }
- }
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement