MQL4 - automated forex trading   /  

Code Base

Code Base  Expert Advisors  RUBBERBANDS_2 EA To post a new code, please log in or register

Library of programs in the new MQL5
Prepare for the Championship

This Expert Advisor is for
MetaTrader 4
Download MT 4 - 5.5 Mb

Mobile trading!
Buy a license and be mobile in your trading!

Name:
RUBBERBANDS_2 EA
Author: StJojo (2009.08.17 11:30)
Rating: 9.6
Downloaded: 5434
Download:
 RUBBERBANDS_2.mq4 (8.1 Kb) View

RUBBERBANDS_2 EA

Version 1.2

DON'T USE THIS EA FOR LIVE TRADING. I don't want to see anybody lose his/her account. I just wanted to give you some new idea.

- The external variable "quiescenow" has been added to quiesce this EA when the current session ends.

-- The logic for the closure of all outstanding orders has been modified.

-- Some external variables have been renamed to be more meaninghful:

useequityprofitcut -> use_sessionTP
dollareqprofitcut -> sessionTP
useequitylosscut -> use_sessionSL
dollareqlosscut -> sessionSL

(The older version still works fine when used in a single currency pair and no other orders are outstanding in other currency pairs.)

This EA is an enhanced version of the original RUBBERBANDS EA. Just like RUBBERBANDS EA, it works in any timeframe for any currency pair, including gold and silver. Its logic, again, is based on the fact that any price movement may accompany rebound ("Delapsus Resurgam") and the maxim of "Sell high, buy low".

It opens orders in both directions (BUY & SELL) at a time initially, then opens an additional SELL order everytime the price goes up by multiples of "pipstep" above the initial SELL order, and opens an additional BUY order everytime the price goes down by multiples of "pipstep" below the initial BUY order.

It closes all the outstanding orders when the specified profit "sessionTP" (in dollars) is reached, which functions as TAKEPROFIT, or, if set so ("use_sessionSL"==true), when the specified loss "sessionSL" (in dollars) is reached, which functions as STOPLOSS.

The opening of the initilal orders through the closure of all outstanding orders constitutes one "session".

The external variable "maxcount" limits the number of orders per session.

Use Strategy Tester to see how this EA performs.

Preferred currency pairs are four major pairs: EUR/USD, GBP/USD, USD/JPY, and USD/CHF. To avoid big drawdowns, smaller "sessionTP" may help.

External variables are:

Lots = 0.02 (number of lots for each order)

maxcount = 10 (maximum number of orders allowed in one session)

pipstep = 50 (pip distance to place additional BUY or SELL orders)

quiescenow = false (if true, quiesces this EA when the current session ends)

donow = false (if true, opens orders immediately)

stopnow = false (if true, stops this EA)

closenow = false (if true, closes all outstanding orders)

use_sessionTP = true (don't change this)

sessionTP = 1000 (profit in dollars per lot to close all outstanding orders; functions as TAKEPROFIT)

use_sessionSL = false (If true, uses "sessionSL" below)

sessionSL = 300 (loss in dollars per lot to close all outstanding orders; functions as STOPLOSS)

The following three external variables are for restarting this EA after, say, the weekend, when there are outstanding orders. "inmax" and "imin" are displayed as "GLBmax" and "GLBmin" on the chart.

useinvalues = false (set to true on restart)

inmax = 0 (set former max on restart)

inmin = 0 (set former min on restart)

45 comments: 1 2 3 4 5   To post a new comment, please log in or register
ForExDRH wrote:

Hi St Jojo etal,

I’m a new comer to the ForEx, but have used computers for over 30 years and have done a little bit of programming along the way. I have read your description of your RubberBands EA and understand how and why it works and think it is a good approach as well. From the little bit I have learned this is a type of Martingale system like PipMaker though I may be mistaken about it being an apt description of your approach.

They both are great profit makers, but their downfall is that the losing trades don’t get canceled out EARLY. A tight Stop Loss on the losing trade of hedging pairs makes it very profitable. I also have a great little commercial utility from PipBoxer.Com that is a 2 stage Trailing Stop Loss (PBTS) that helps these systems and is very reasonably priced. It works with your RubberBands AE but unfortunately not with PipMaker.

When I use these programs more in a Scalping mode, which they are great for as they recognize and place a lot of trades very quickly (when your AE is in ‘Safety Mode’) and manually close out the losing trade very early as soon it is clear which of the trades is definitely losing money and the other one of the pair is making money both of these approaches are VERY profitable.

I have no experience programming MT4 and I don’t know if personal circumstances will permit me to undertake programming in this area. At this stage if I am going to do it I will wait till MT5 comes out very soon.

I appeal to you as well as other programmers to put an adjustable Stop Loss and preferably a Trailing Stop Loss as well onto both your RubberBands AND PipMaker and these systems will be GREAT and VERY profitable EAs.

Thanks for sharing. (8 >) Prosperous Trading (< 8)

DougRH


What settings and which revision do you prefer when using the PBTS and Rubberbands as a scalper?

I like the PBTS. Thanks for the idea.

rsqzjek

27.05.2010 20:38 rsqzjek

I have a new Idea, but i dont know how to code it:

If we have a hedged Situation (f.e.: 10 Buy and 10 Sell) and the profit reached a minium of a specific level---> close all order


Is someone able to code that?


UPDATE:

I have a first idea but it doenst work fine. The EA opens a hedget Position at the beginning, so i tried to define that the EA only closes all Positions if there were more than 5 Sell and Buy orders.

BUT: The EA closes at the beginning about 10x the first hedget Position and after that he clothes nothing even if its hedget and we have more than 5 Sell/5 Buy. Does someone know how to solve this?


CODE:

int BuyCnt = 0;
int SellCnt = 0;

int abo = OrdersTotal();


for (int i=0; i < abo; i++)


{


if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;



int type = OrderType();


if (type == OP_BUY) BuyCnt++;


if (type == OP_SELL) SellCnt++;


}


if (BuyCnt<5 && SellCnt<5 && BuyCnt-SellCnt==0)


{


GLBcloseall=true;
}
08.12.2009 22:59 Daldrar

best expert thanks .

05.12.2009 21:09 btherichb

Okay i have an automatic lot increase now:

500$->0.01

1000$->0.02

1500$->0.03


Works great. But still the DD kills me in some Periods. Does anybody have an Idea how to avoid this big DD?

I have tried to use an 50% Equity Stop to avoid the ultimate DD but i get not as heavy DD as before but more small DD.

Maybe a counter order?

And does someone have tried to usw TP?


Killing Dates between 2009.06.01 and 2009.25.11

2009.09.04 - 2009.09.15

and

2009.11.03 - 2009.11.11


Both times only short trades and only 1 long trade.

Maybe its possible to code: 5 short after another: 1 long and the other way round

Does someone know how to`?

25.11.2009 22:33 Daldrar


Can someone add a automatic lot increasment based on the accountbalance?

For example every 250$ add 0.01 lot.

I tried it for days now, but I´m not a coder and so failed!


25.11.2009 18:12 Daldrar

Hi St Jojo etal,

I’m a new comer to the ForEx, but have used computers for over 30 years and have done a little bit of programming along the way. I have read your description of your RubberBands EA and understand how and why it works and think it is a good approach as well. From the little bit I have learned this is a type of Martingale system like PipMaker though I may be mistaken about it being an apt description of your approach.

They both are great profit makers, but their downfall is that the losing trades don’t get canceled out EARLY. A tight Stop Loss on the losing trade of hedging pairs makes it very profitable. I also have a great little commercial utility from PipBoxer.Com that is a 2 stage Trailing Stop Loss (PBTS) that helps these systems and is very reasonably priced. It works with your RubberBands AE but unfortunately not with PipMaker.

When I use these programs more in a Scalping mode, which they are great for as they recognize and place a lot of trades very quickly (when your AE is in ‘Safety Mode’) and manually close out the losing trade very early as soon it is clear which of the trades is definitely losing money and the other one of the pair is making money both of these approaches are VERY profitable.

I have no experience programming MT4 and I don’t know if personal circumstances will permit me to undertake programming in this area. At this stage if I am going to do it I will wait till MT5 comes out very soon.

I appeal to you as well as other programmers to put an adjustable Stop Loss and preferably a Trailing Stop Loss as well onto both your RubberBands AND PipMaker and these systems will be GREAT and VERY profitable EAs.

Thanks for sharing. (8 >) Prosperous Trading (< 8)

DougRH

17.09.2009 18:59 ForExDRH
hulspas wrote:
StJojo wrote:
hulspas wrote:

thank you i cant't wait this ea have a good potential.!!! great work

look at exp amstell combine somethings of it that is a great ea too.


I have looked at "exp amstell" and it is indeed very neat !

i have bin busy 2 days to get something of the ground some combine of rubberbands and amstell

im not a coder but the ea is working.....:-)

//+------------------------------------------------------------------+
//|                                                  exp_Amstell.mq4 |
//|                                   Copyright © 2009, Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

//òîðãîâëÿ áåç ñòîï ëîñîâ,ïåðèîä day,ïîêóïàòü ,åñëè öåíà îòêðûòèÿ ïîñëåäíåãî 
//îòêðûòîãî îðäåðà âûøå òåêóùåé öåíû,è çàêðûâàòü îðäåð ïî äîñòèæåíèè 1000 ïóíêòîâ,
//òî æå è ñ ïðîäàæåé.îòêðûâàòü îðäåð sell,åñëè ïîñëåäíèé îòêðûòûé sell íèæå òåêóùåé 
//öåíû. îòêðûâàòü ïîçèöèè ïî öåíàì îòêðûòèÿ
extern double My_Money_Profit_Target=10;     //The amount of money profit at which you want to close ALL open trades.
extern int    Test             = 300;
extern int    Distancebuy         = 500;
extern double Lotsbuy             = 0.02; 
extern int    TakeProfitbuy       = 10000;
extern int    Distancesell         = 500;
extern double Lotssell             = 0.01; 
extern int    TakeProfitsell       = 10000;            // Ðàçìåð òåéêà â ïóíêòàõ
extern bool UseTrailing        = true; //enabling/disabling T-SL
extern int TrailingStopsell        = 500;   //Trailing Stop Loss level
extern int TrailingStopbuy      = 0;   //Trailing Stop Loss level
extern int TrailingStep        = 500;    //Trailing Stop Loss step
extern double    priceAlert;
int Slippage=5;
int i;
extern int    StopLoss         = 50000;
 
  
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int Magic=0;
  
for(int cnt=0;cnt<OrdersTotal();cnt++)// Ïåðåáèðàåì âñå îðäåðà
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);//îðäåð âûáèðàåòñÿ ñðåäè îòêðûòûõ è îòëîæåííûõ îðäåðîâ
      if( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)// Ñîâïàäàåò ëè ñèìâîë îðäåðà( Çäåñü ïî íàäîáíîñòè åù¸ ìàãèê ìîæíî ïðîâåðèòü)
        {
         if(OrderType()==OP_BUY)//Îòáèðàåì ïîçèöèþ áàé
           {
            if(Bid-OrderOpenPrice()>TakeProfitbuy*Point || OrderOpenPrice()-Ask>StopLoss*Point)//
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet); //çàêðûâàåì îðäåð
               return(0); // âûõîäèì
              }//StopLoss
           }
          if(OrderType()==OP_SELL)//Îòáèðàåì ïîçèöèþ ñåëë
           {
            if(OrderOpenPrice()-Ask>TakeProfitsell*Point || Bid-OrderOpenPrice()>StopLoss*Point)//
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet); //çàêðûâàåì îðäåð
               return(0); // âûõîäèì
              }
           }
         }
      }
//----
 int buy = 0, sell = 0;
//----
   if(!ExistPositions(NULL,OP_BUY))buy=1;
   else if(PriceOpenLastPos(NULL,OP_BUY)-Ask>Distancebuy*Point)buy=1; 
   
   if(!ExistPositions(NULL,OP_SELL))sell=1;
   else if(Bid-PriceOpenLastPos(NULL,OP_SELL)>Distancesell*Point)sell=1;   
//----
    if(buy==1)
    OrderSend(Symbol(),OP_BUY,Lotsbuy,Ask,3,0,0,"",0,0,Green);
   
    if(sell==1)
    OrderSend(Symbol(),OP_SELL,Lotssell,Bid,3,0,0,"",0,0,Red); 
     

//----
   return(0);
  }
//+------------------------------------------------------------------+
//|  Îïèñàíèå : Âîçâðàùàåò ôëàã ñóùåñòâîâàíèÿ ïîçèöèé                          |
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    sy - íàèìåíîâàíèå èíñòðóìåíòà   (""   - ëþáîé ñèìâîë,                   |
//|                                     NULL - òåêóùèé ñèìâîë)                 |
//|    op - îïåðàöèÿ                   (-1   - ëþáàÿ ïîçèöèÿ)                  |
//|    mn - MagicNumber                (-1   - ëþáîé ìàãèê)                    |
//|    ot - âðåìÿ îòêðûòèÿ             ( 0   - ëþáîå âðåìÿ îòêðûòèÿ)           |
//+----------------------------------------------------------------------------+
bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (ot<=OrderOpenTime()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
}
//+----------------------------------------------------------------------------+
//|  Âåðñèÿ   : 19.02.2008                                                     |
//|  Îïèñàíèå : Âîçâðàùàåò öåíó îòêðûòèÿ ïîñëåäíåé îòêðûòîé ïîçèöèé.           |
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    sy - íàèìåíîâàíèå èíñòðóìåíòà   (""   - ëþáîé ñèìâîë,                   |
//|                                     NULL - òåêóùèé ñèìâîë)                 |
//|    op - îïåðàöèÿ                   (-1   - ëþáàÿ ïîçèöèÿ)                  |
//|    mn - MagicNumber                (-1   - ëþáîé ìàãèê)                    |
//+----------------------------------------------------------------------------+
double PriceOpenLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   r=0;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) {
                t=OrderOpenTime();
                r=OrderOpenPrice();
              }
            }
          }
        }
      }
    }
  }
   
//+-------------------------------------------------------------------------------------------------+ 
//|                                      trail of open orders                                       |
if (UseTrailing)
{ 
  for (int trall=0; trall<OrdersTotal(); trall++) {
    if (!(OrderSelect(trall, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;       
 
    if (OrderType() == OP_BUY ) {
      if (Bid-OrderOpenPrice() > TrailingStopbuy*Point) {
        if (OrderStopLoss() < Bid-(TrailingStopbuy+TrailingStep-1)*Point || OrderStopLoss() == 0) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Bid-TrailingStopbuy*Point, OrderTakeProfit(), 0, Blue);
       }
      }
    }
 
    if (OrderType() == OP_SELL) {
     if (OrderOpenPrice()-Ask > TrailingStopsell*Point) {
        if (OrderStopLoss() > Ask+(TrailingStopsell+TrailingStep-1)*Point || OrderStopLoss() == 0) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStopsell*Point, OrderTakeProfit(), 0, Blue);
        }
     }
    }
  }
 }
//|                                      trail of open orders                                       |
//+-------------------------------------------------------------------------------------------------+

if (AccountProfit()>= My_Money_Profit_Target)
{
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
               
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
                          
          }
          
       if(result == false)
          {
            Sleep(3000);
          }  
       }
      Print ("Account Profit Reached. All Open Trades Have Been Closed");
      return(0);
   }  
   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",My_Money_Profit_Target);
   
  return(r);
}
  


17.09.2009 18:56 ForExDRH
hulspas wrote:

<figure>

look in the left side on my live account

ea rubberbands 3.3 here in the form the profit/loss in not the same as a demo on alpari lol can we fix it whats the reason....


......it is my kediet....lol

can we fix it


Your result is amazng! The displayed profit/loss value is an approximate one, calculated just before closing.

03.09.2009 10:27 StJojo

rubber bands 3.3 with some ajustments.......

extern double Lots_up_when_losing=0.01;//

...........

........

return(NormalizeDouble(OrderLots()+Lots_up_when_losing,2));

2 times in the code 3.3


tester on 3000eur

2 years steady grow almost 100 percent

max trades 10

pipstep 50

profit take 1200

im not sure thats not working on a live account help me with credit see down

eur/chf 1 hour

on alpari 5digits every tick

Strategy Tester Report
RUBBERBANDS_tester
AlpariUK-Micro-2 (Build 225)

SymboolEURCHF (Euro vs Swiss Franc)
Periode1 Uur (Uur1) 2006.11.28 00:00 - 2009.07.31 22:00 (2006.11.28 - 2009.08.01)
ModelElke tik (gebaseerd op alle beschikbare minste tijd frames met fractal interpolatie)
ParametersMagic_Number_Buy=111111; Magic_Number_Sell=222222; Progression_Allowed=true; Initial_Lots=0.01; Lots_Multiply_Factor=0.01; Max_Trades=10; Pip_Step=50; Use_Equity_Profit_Take=true; Dollar_Equity_Profit_Take=1200; Use_Equity_Loss_Cut=false; Dollar_Equity_Loss_Cut=57400; Time_Control=false; Start_Time="08:00"; End_Time="16:00"; Act_Now=false; Stop_Now=false; Close_Now=false; Use_In_Values=false; In_Max_Price_Level=0; In_Min_Price_Level=0;

Staven in test17435Gemodelleerde tikken11663239Modellering kwaliteit90.00%
Mismatched charts errors0




Initiële storting3000.00



Totale netto winst2765.10Brutto winst6669.01Brutto verlies-3903.91
Winst factor1.71Verwachte uitbetaling2.63

Absolute vermindering856.36Maximale vermindering1128.64 (20.31%)Relative drawdown30.33% (933.04)

Totale handelingen1053Short posities (won %)527 (61.10%)Long posities (won %)526 (57.98%)

Winst handelingen (% van totaal)627 (59.54%)Verlies handelingen (% van totaal)426 (40.46%)
Grootstewinst transactie116.67verlies transactie-67.31
Gemiddeldwinst transactie10.64verlies transactie-9.16
MaximumOpeenvolgende winst trades (winst in geld)5 (259.18)Opeenvolgende verlies trades (verlies in geld)6 (-142.85)
MaximaalOpeenvolgende winst (telling van winst transacties)259.18 (5)Opeenvolgende verliezen (telling van verlies transacties)-268.10 (5)
GemiddeldOpeenvolgende winsten2Opeenvolgende verliezen1


follow in demo:

http://hulspas.mt4stats.com/







27.08.2009 18:29 hulspas


look in the left side on my live account

ea rubberbands 3.3 here in the form the profit/loss in not the same as a demo on alpari lol can we fix it whats the reason....


......it is my kediet....lol

can we fix it



27.08.2009 04:51 hulspas