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;
- //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 = 0.1;
- if(x >= -100 && x < -90) {
- y = 0.5;
- }
- if(x >= -90 && x < -80) {
- y = 0.4;
- }
- if(x >= -80 && x < -70) {
- y = 0.3;
- }
- if(x >= -70 && x < -60) {
- y = 0.2;
- }
- if(x >= -60 && x < -50) {
- y = 0.1;
- }
- if(x >= -50 && x < -40) {
- y = 0.1;
- }
- if(x >= -40 && x < -30) {
- y = 0.2;
- }
- if(x >= -30 && x < -20) {
- y = 0.3;
- }
- if(x >= -20 && x < -10) {
- y = 0.4;
- }
- if(x >= -10 && x < 0) {
- y = 0.5;
- }
- //return(0.1);
- return(y);
- }
- //+------------------------------------------------------------------+
- //| 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(Close[1] > Close[n] || Close[1] < Close[s]) {
- OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
- }
- }
- //EXIT SHORTS
- if(cmd==OP_SELL && OrderMagicNumber() == 21) {
- if(Close[1] < Close[n] || Close[1] > Close[s]) {
- OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
- }
- }
- }
- }
- //ORDER ENTRY
- if(OrdersTotal() < 1){
- //BUY
- if(Close[1] < Close[n] && Close[1] > Close[s]) {
- OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.3,0,0,NULL,11,0,Blue);
- }
- //SELL
- if(Close[1] > Close[n] && Close[1] < Close[s]) {
- OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.3,0,0,NULL,21,0,Red);
- }
- }
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement