Quantcast
Channel: MQL5: MetaTrader 5 trading, automated systems and strategy testing forum
Viewing all 75046 articles
Browse latest View live

How To Get The Previous Days Pivot Lines Indicator Value From An EA ?

$
0
0
yassin.mokni:

Ok , How Can I  get these 3 days values  , like in the picture : 

 

It should be

DayBarNumber+23 

What if the World is Wrong?

$
0
0
bermaui314:

"High risk equal High return while Low risk equal Low return".......the word return here might mean gains or losses.


The reason that the Dis Martingale back test look much less risky is the lot-size was fixed to 0.01 from the beginning of the test until the end, that is why return was only 992$, if we increased the lot-size we will make more profit and draw-down will increase too

Take a look to the next example where I risk only 0.01 fixed lot size:

Profit Factor is 1.85 , Maximum DD is 3.13% or $315 but return is $559 or 5.59%


If 0.01 lot lead to $315 DD then 0.15 lot will lead to about $5000 DD (= 50% / 3.13 *0.01) but  profit will boost 15 times also , take a look to the back-test result with 0.15 fixed lot-size.

As you can see profit jumped to a new level but risk also jumped to an extreme, because high risk will mean always high gain/loss and vice verse.


So now what is the difference between using fixed lot and Martingale?

The difference is the risk to blow out your account is increased. Isn't clear ?

How to Trade the Gold Silver Ratio ?

$
0
0
Skansi:

Roman, I do not agree with you....

the insider guys do not know anything more than us... there are tons of examples of this, most notably the Lehman Bros and CL. Nobody knew anything.

 As for gold, I do not remember any CMT (myself included) claiming a break of 2000USD.

 Regarding bottoming, do you have any evidence that 1166 is a bottom? As far as I can see there is no sign whatsoever of bottoming, asides wishful thinking.

It is actually 1180, not 1166 (I am wrong). I was looked at minimum price on the right hand side of the chart.

I read hundreds of articles - they predicted that gold will break the $2000 level (Google it, you will find it).

You look at the wrong guys. Yes, there is someone that knew. 

Color candlesticks - what am I missing?

$
0
0
Should the color array be timeseries as well ... thank you so much.

Indicators: Astro Indicators

please i get access to mlq5 account

$
0
0

"Please help" gives no valuable information at all.

If the problem is with access to your mql5 account as the original title suggests, then you have already solved that problem.

You are already accessing it, you logged in and posted your message.

If there is some other problem, perhaps you could provide some details...

How to Edit Ex4 File

$
0
0
Forex-Profit:

hi everybody.

i want to know how to edit EX4 robot file ??? 

.ex4 is a compiled file, you are unable to edit those.

.mq4 is the source code file, this file you can edit.

VPS info

$
0
0
for win  server 2008 you need 2G of ram

Pending Order EA

$
0
0

Hello Forum, good day.

I'm trying to finish a Pending Orders Expert Advisor that takes the OHLC prices from the previous candle/bar right when a new bar/candle is created and +DI > -DI for Buy Orders and +DI < -DI for Sell Orders, but somehow there are times that it takes this values from two or more candles behind. Also I need that for Buy Orders only when the previous candle is Black the order is placed/filled and for Sell Orders only when the previous candle is White, but I don't know what I'm missing that this is being ignored sometimes. I'm new to MQL5 and would really appreciate if someone could help me out with this or point me in the right direction.

Here is what I have so far:

 

//+------------------------------------------------------------------+
//|                                                   Pending_EA.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#include <Trade\Trade.mqh>
CTrade  trade;
input double Lot=0.1;
double risk=0.1;//sl is equal ...$
input int ADXperiod=14;

int adx;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {adx=iADX(NULL,0,ADXperiod);
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {int total=0;
   bool newb=NewBar();
     for(int i=0;i<PositionsTotal();i++)
     {
      // position on our symbol
      if(Symbol()==PositionGetSymbol(i))
        {total=1;
         if(newb)Trail();//move sl everday(4.)
        }
      }
   if(total==0&&newb)//if no open positions and newbar (0.)- open
      {
       OpenOrder();
      }
//---

  }
//+------------------------------------------------------------------+
void OpenOrder()
{delete_all_limit_orders();//delete old limit orders
 double dipl[];
 double dimi[];
 CopyBuffer(adx,1,1,1,dipl);
 CopyBuffer(adx,2,1,1,dimi);
 if(dipl[0]>dimi[0])//di+>di-(1.,2.)
   {if(iClose(NULL,0,1)<iOpen(NULL,0,1))//bear candle 3.1
     {
     PlaceBuyStop();//3.1
     }
   }
 else//di+<di-(1.,2.)
   {if(iClose(NULL,0,1)>iOpen(NULL,0,1))//bull candle 3.2
     {
      PlaceSellStop();//3.2
     }
   }
}

void PlaceBuyStop()
{double val=_Point*risk/(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE),_Digits)*Lot);//+0.1 cent
   double pr=iLow(NULL,0,1);//low form previous bar
   double op_pr=iOpen(NULL,0,1);//open price


 MqlTradeRequest request={0};
   request.action=TRADE_ACTION_PENDING;         // pending order
   request.volume=Lot;                          // lot size
   request.symbol=_Symbol;
   request.price=op_pr;                          //open price
   request.sl=pr-val;                            // Stop Loss
   request.tp=0;
   request.type=ORDER_TYPE_BUY_STOP;            // ordertype
   MqlTradeResult result={0};
   int tic=OrderSend(request,result);


}
void PlaceSellStop()
{double val=_Point*risk/(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE),_Digits)*Lot);//sl value
   double pr=iHigh(NULL,0,1);
   double op_pr=iOpen(NULL,0,1);

   MqlTradeRequest request={0};
   request.action=TRADE_ACTION_PENDING;         // pending order
   request.volume=Lot;                          // lot size
   request.symbol=_Symbol;
   request.price=op_pr;                          //open price
   request.sl=pr+val;                            // Stop Loss
   request.tp=0;
   request.type=ORDER_TYPE_SELL_STOP;            // ordertype
   MqlTradeResult result={0};
   int tic=OrderSend(request,result);
}
void delete_all_limit_orders()
{int i;
ulong lv_ticket;

    int lv_total = OrdersTotal();
    for (i = 0; i < lv_total; i++ )
      {if ((lv_ticket = OrderGetTicket(i)) > 0)
        if (OrderGetString(ORDER_SYMBOL)==_Symbol)
        {
         if((OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT || OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_LIMIT ||
         OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP||OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP))
         {
          trade.OrderDelete(lv_ticket);
         continue;
         }
        }
      }
}


bool NewBar()//0. Know when a new bar/candle
{datetime tim[];
  CopyTime(Symbol(),0,0,1,tim);

static datetime lastbar = -1;
datetime curbar = tim[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else return(false);
}

//have access to the current and previous OHLC rates/prices.
double iClose(string symbol,ENUM_TIMEFRAMES timeframe,int index)

{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyClose(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}

double iOpen(string symbol,ENUM_TIMEFRAMES timeframe,int index)

{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyOpen(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}


double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)

{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyHigh(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}

double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)

{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyLow(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}


void Trail()
{MqlTradeRequest request={0};
MqlTradeResult  result={0};


      request.action=TRADE_ACTION_SLTP;
          request.symbol = Symbol();
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
           {double sl=iLow(NULL,0,1);

            if(NormalizeDouble(sl-PositionGetDouble(POSITION_SL),_Digits)>0)
              {

               request.sl=NormalizeDouble(sl,_Digits);
               request.tp=NormalizeDouble(PositionGetDouble(POSITION_TP),_Digits);

               int t=OrderSend(request,result);
              }
           }

         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
           {double sl=iHigh(NULL,0,1);

            if(NormalizeDouble(PositionGetDouble(POSITION_SL)-sl,_Digits)>0)

              {
               request.sl=NormalizeDouble(sl,_Digits);
               request.tp=NormalizeDouble(PositionGetDouble(POSITION_TP),_Digits);


              int t1= OrderSend(request,result);
              }
           }
}

 

Regards and thank you in advance,

codeMolecules 

For The Professionals

$
0
0
yassin.mokni:

Hi Guys 

Well , It's the first time I Create A topic in This Section ...  and I name it "For The Professionals" .. because I Want , And I have The Passion To Be A Professional MQL5 Programmer , And To ask The Professionals in this forum This Question : 

 What Is The Steps That You Advise Beginners like me .. To Be A Professional MQL5 Programmer ?


I Appreciate your Advises  

Regads  

Yassin

I would not consider myself a professional but I can share what may help you. Always try to keep things as simple as possible. Often even very complicated project can be simplified to a much more manageable task. This simplified version can then be used to get a thorough understanding of the actual project. This approach has saved me plenty of headaches :)

Experts: MMA_Breakout_strategy_Volume I - coded by WhooDoo22.

$
0
0

Hi WhooDoo22 , 

 

I am a novice in the EAs. I downloaded your EA and while backtesting was giving compilation issues in lines 9 & 10 so I removed the periods in those lines as follows

"extern string CodedByWhooDoo22="";

extern string ThanksToMQL4Comunity=""; "

After this change the EA compiles and tried doing the back testing with data for EURUSD from 2010 jan 1st to 2015 jan 1st. But I am getting the following errors in the journal tab and no orders are placed. 

" 3 06:53:38 2014.12.31 10:54  MMA_Breakout_strategy_Volume_I_-_coded_by_WhooDoo22 EURUSD,M1: invalid takeprofit for OrderSend function

3 06:53:38 2014.12.31 10:54  MMA_Breakout_strategy_Volume_I_-_coded_by_WhooDoo22 EURUSD,M1: OrderSend error 4107

3 06:53:38 2014.12.31 10:57  MMA_Breakout_strategy_Volume_I_-_coded_by_WhooDoo22 EURUSD,M1: OrderSend error 131"

 

There are lot of repetetions of the same error. Please guide me about how to solve these errors.

 I have attached the report along with this so that you can gete some more information.

Thanks in advance 

Discussion of article "How to Access the MySQL Database from MQL5 (MQL4)"

$
0
0

I got an idea on the tick value problem. I am running a multicurrency EA and I start out  getting a lot of info for each pair. So it gets a bit like "hammering". I will change that so

that the tickvalue will only be asked for when needed. (and saved)

-   Updated  --

Not completely in the green. Have made the change above. Optimization still works. No error messages when starting EA.  OK will be when the EA has taken a trade ok. Have to wait.

This is running a 32 bit version of the EA in a Windows 7 64 bit environment. It will at least temporarely solve the problem if it works.

I only fetch the Tickvalue when the first order is on its way and save it.

data gold

$
0
0

 

I think - it depends on the broker (some brokers do not have gold/xauusd for example).
Yes,i agree with you

How to Edit Ex4 File

$
0
0
Matija14:
He might be lieing when selling it to me....How can I protect my self?
Buy at mql5.com Market, you will be protected by the rules of the site.

Compiling EA: Why it becomes write protected?

$
0
0
KeithBunge:
Yes I did and it would not let me compile or copy it to notepad. Now getting a message on my computer that metatrader is not working right. Have downloaded it 5 times to try to get it right.

Why do you want to copy it to notepad ? Sorry but your issue is not clear.

It's very difficult to help you without details. What's do you mean by " a message on my computer that metatrader is not working right" ?


Order Failed Modify Buy [Position Already Closed]

$
0
0

I am using the below example code from Metaquote; however, I am getting the message [Position already closed]  and it would not enter the Stop Loss and Take Profit for my order. Below is my screen capture of the Trade Journal.

 

 

 

  sOP = "BUY";

      clOP = Aqua;

      l_cmd_36 =0;

      getT2 = ORDER_TYPE_BUY;

      l_price_0 = b1_symbol.Ask();

      l_price_8 = Ask - (b1_sl*b1_symbol.Point());

      l_price_16 = Ask + (b1_tp*b1_symbol.Point()); 

bool result = OrderSendMQ4(b1_symbol.Name(), l_cmd_36, OrderSize(), l_price_0, Slippage, l_price_8, l_price_16, sOP, Magic1);

 

 

bool OrderSendMQ4( string symbol_in, int cmd_in, double volume_in, double price_in, int slippage_in, 
                  double stoploss_in, double takeprofit_in, string comment_in=NULL, int magic_in=0) 
{
            MqlTradeRequest mrequest;  // To be used for sending our trade requests
            MqlTradeResult mresult;    // To be used to get our trade results
            MqlTradeCheckResult m_check_result;
            MqlTick latest_price; 
            
            
           if(!SymbolInfoTick(_Symbol,latest_price))
           {
            Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
            return(false);
           }
           
            ZeroMemory(mrequest);
            mrequest.action = TRADE_ACTION_DEAL;
            if(cmd_in==ORDER_TYPE_BUY)
            {                                  // immediate order execution
               mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // latest ask price         
               mrequest.type = ORDER_TYPE_BUY;               
            }
            if(cmd_in==ORDER_TYPE_SELL)
            {
               mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // latest ask price    
               mrequest.type = ORDER_TYPE_SELL;                                 
            }   
            mrequest.symbol = _Symbol;                                            // currency pair
            mrequest.volume = volume_in;                                                 // number of lots to trade
            mrequest.magic = magic_in;                                             // Order Magic Number
            mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
            mrequest.deviation=100;                                                // Deviation from current price
            mrequest.comment=comment_in;
            
            string action,result;
            //--- order check
            if(!OrderCheck(mrequest,m_check_result))
              {
               mresult.retcode=m_check_result.retcode;
               //printf(__FUNCTION__+": %s [%s]",FormatRequest(action,mrequest),FormatRequestResult(result,mrequest,mresult));
               Alert(__FUNCTION__ + " order check failed, " + mresult.retcode);               
               //--- copy return code
              }
              
              
               if (OrderSend(mrequest, mresult)==true)
               {
                  Alert("order has been successfully "); 
                  
                  if(takeprofit_in>0 && stoploss_in>0)
                  {
                     mrequest.action = TRADE_ACTION_SLTP;
                     mrequest.symbol = _Symbol;
                     mrequest.tp=takeprofit_in;
                     mrequest.sl=stoploss_in;
                     
                     if (OrderSend(mrequest, mresult)==true)
                     {
                        Alert("Order has been successfully set takeprofit/stoploss"); 
                     }           
                     else
                     {
                        Alert("Order failed to set takeprofit/stoploss, error:",GetLastError());
                        //orderSendFaildReason(mresult); 
                        ResetLastError();
                        return(false);    
                     }
                  }
               }           
               else
               {
                  Alert("order failed, error:",GetLastError());
                  ResetLastError();
                  return(false);    
               }
               
              return(true);
              
}

Traders Joking

$
0
0
Fillellin:

                                       Good night!

 

Any dog clips? 

How to Start with Metatrader 5

Missing signals icon in MT4

Filling types

$
0
0
kemalturgay:

On the specification window, the filling type of a pair is designated as "all" with my broker.

But, on the "new order" window, there are only two options: FOK and IOC.

Can I use "return" in this case?


Why not simply try ?

Additionally, if available, with which function I can see the used filling type for an opened position ... I could not find such a function?

You can't get this information for a position, only for orders.

OrderGetInteger(ORDER_TYPE_FILLING);
Viewing all 75046 articles
Browse latest View live