Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1631 (permalink)  
Old 03-06-2009, 08:58 PM
Junior Member
 
Join Date: Aug 2008
Posts: 4
BeepBoop is on a distinguished road
Post Deleted

Last edited by BeepBoop; 03-09-2009 at 05:38 PM. Reason: detailed info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1632 (permalink)  
Old 03-06-2009, 09:51 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
You'd better use
MathAbs(NormalizeDouble(Bid,4)-NormalizeDouble(pivot,4))<Delta*Point,
Where Delta=2...5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1633 (permalink)  
Old 03-07-2009, 02:02 PM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,451
MiniMe is an unknown quantity at this point
Quote:
Originally Posted by jdun View Post
Could someone tell me the code for stop loss and tp. I need to add it to this EA.
this hidden SL and TP


PHP Code:


 
int TakeProfit
=20// 20 pips take profit 
int StopLoss  =40// 40 pips stoploss
int Slippage  3;
int MagicNumber=1
int i

int start(){
//----- exit @ TP
if((ScanTrades()>=1)&& (ProfitInPips()>=TakeProfit)){
//----- This part will close all open orders and delete pending trades
     
for(OrdersTotal()-1>=0i--)
      {     
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if (
OrderSymbol() == Symbol()&& OrderMagicNumber()==MagicNumber )
              { 
               if (
OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Plum);
               if (
OrderType()==OP_SELLOrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Plum); 
               if (
OrderType() == OP_SELLLIMITOrderDelete(OrderTicket());
               if (
OrderType() == OP_BUYLIMITOrderDelete(OrderTicket());   
               if (
OrderType() == OP_BUYSTOPOrderDelete(OrderTicket());
               if (
OrderType() == OP_SELLSTOPOrderDelete(OrderTicket());    
           }  
      }        
  }

//------exit @ SL
if((ScanTrades()>=1)&& (ProfitInPips()<= -StopLoss)){
//----- This part will close all open orders and delete pending trades 
     
for(OrdersTotal()-1>=0i--)       
      {     
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if (
OrderSymbol() == Symbol()&& OrderMagicNumber()==MagicNumber )
              { 
               if (
OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Plum);
               if (
OrderType()==OP_SELLOrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Plum); 
               if (
OrderType() == OP_SELLLIMITOrderDelete(OrderTicket());
               if (
OrderType() == OP_BUYLIMITOrderDelete(OrderTicket());   
               if (
OrderType() == OP_BUYSTOPOrderDelete(OrderTicket());
               if (
OrderType() == OP_SELLSTOPOrderDelete(OrderTicket());    
           }  
      }        
  }


return (
0);
}   
//----------- Call functions    
int ScanTrades()
{   
 
int Tot OrdersTotal();
 
int Numb 0;
    
   for(
int cnt=0cnt<=Tot-1cnt++) 
   {        
   
OrderSelect(cntSELECT_BY_POS);            
   if (
OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberNumb++;

   }   
   return(
Numb);
}



double ProfitInPips()
{
   
RefreshRates();
   
double Prof=0;
   
int i;
   
int totalOrders=OrdersTotal();        
   for(
i=0;i<totalOrders;i++)
   {
      if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(
OrderMagicNumber()==MagicNumber)
      {
         if(
OrderType()==0)
         {
            
Prof+=(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);  
         }
         if(
OrderType()==1)
         {
            
Prof+=(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT);
         }   
      }  
   }
   
  return(
Prof);  

__________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1634 (permalink)  
Old 03-07-2009, 02:07 PM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,451
MiniMe is an unknown quantity at this point
Lets say I have a few Buy orders and Sell orders

What I want do is :
- Exit all the trades " Basket" at 5 pips more than the breakeven price of the open trades

What I am trying to do in the first for loop is find the value of open trades + swap and convert it to pips , and this is the part where I am getting stuck

I have tried few ideas but I have reached a dead end, I know the problem is in the first for statement but I can't solve it, any help is highly appropriated




PHP Code:
 SymbolPL 0;
 
OrdLots  0;
 
Equity   0
 
MinPro   5;
 for(
0OrdersTotal(); i++)
   {
OrderSelect(iSELECT_BY_POSMODE_TRADES);
      if (
OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
      {if(
OrderType() == OP_BUY)  OrdLots += OrderLots();
       if(
OrderType() == OP_SELLOrdLots -= OrderLots();      
       
Equity += OrderProfit() +  OrderSwap();
      }
   } 
   
MinProMathRound (MathAbs(Equity /OrdLots)+MinPro); 

//--- Count the open trades 
   
int i;
   
int count=0;   
   for(
i=0;i<OrdersTotal();i++)
    { if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(
OrderMagicNumber()==MagicNumber && OrderType()<2)
       { 
count++;
        }
    }

//--- find the profit in pips of the open trades 
  
RefreshRates();
   
double profits=0,openPrice=0,points=0;
   
string sym="";
   
int i;
   
int totalOrders=OrdersTotal();        
   for(
i=0;i<totalOrders;i++)
   {
      if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(
OrderMagicNumber()==MagicNumber)
      {
         
sym=OrderSymbol();
         
openPrice=OrderOpenPrice();
         if(
OrderType()==0)
         {
            
profits+=(MarketInfo(sym,MODE_BID)-openPrice)/MarketInfo(sym,MODE_POINT);  
         }
         if(
OrderType()==1)
         {
            
profits+=(OrderOpenPrice()-MarketInfo(sym,MODE_ASK))/MarketInfo(sym,MODE_POINT);
         }   
      }  
   }
 
//--- Close when the open trades are 5 pips more than the breakeven price


     
if (count>&& profits>MinPro 

   for(
OrdersTotal()-1>=0i--)
      {
         
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if (
OrderSymbol() == Symbol()&& OrderMagicNumber()==MagicNumber )
         {
           
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Plum);
               
          }
      }    

__________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1635 (permalink)  
Old 03-07-2009, 09:28 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
I think you can use an "equity_per_lotpoint" constant, which would be computed as:
PHP Code:
double equity_per_lotpoint =  MarketInfoSymbol(), MODE_TICKVALUE ) / MarketInfoSymbol(), MODE_TICKSIZE ); 
and then you'd have what you need after the first loop, with:
PHP Code:
if ( Equity >  equity_per_lotpoint MathAbsOrdLots ) ) { ... 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1636 (permalink)  
Old 03-07-2009, 10:02 PM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,451
MiniMe is an unknown quantity at this point
Thanks Ralph but I would be missing the swap , and I want to include the swap profit/loss in the close of the orders decision
__________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1637 (permalink)  
Old 03-07-2009, 10:08 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by MiniMe View Post
Thanks Ralph but I would be missing the swap , and I want to include the swap profit/loss in the close of the orders decision
But the first loop accumulates both profit and swap, doesn't it?

I was thinking that the Equity figure is the one to compare against what 5 pips would mean for the open lots.... and you then don't need to actually compute the break-even price.

Last edited by ralph.ronnquist; 03-07-2009 at 10:11 PM. Reason: added sentence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1638 (permalink)  
Old 03-07-2009, 11:06 PM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,451
MiniMe is an unknown quantity at this point
Hi Ralph
I have 3 variables
OrdLots ; in lots and represent the open lots but this will skip the swap
Equity ; this is the total profit loss and this one will include the swap
MinPro ; this is my take profit which is 5 pips + the breakeven point


I can't use OrdLots to find the profit/loss in pips as this will skip the swap
I can't use Equity to find the profit/loss in pips because for that I need to know how much lots,are used but my calculation for the lots skip the swap
Somehow I need to use a function of both OrdLots and Equity to know how many pips are opened
There might be something ready in MT4 that relate the account balance or account equity but I didn't find any

The solution you proposed with thanks will find the profit/loss in pips without considering swap, but I have already put a function for that ... I want to exit at 5 pips above the breakeven with the swap
__________________


Last edited by MiniMe; 03-07-2009 at 11:33 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1639 (permalink)  
Old 03-08-2009, 07:01 AM
PipStalking's Avatar
Junior Member
 
Join Date: Jan 2009
Posts: 1
PipStalking is on a distinguished road
Post Compare Times and do loop

Hi Everybody.

I`m very inexperienced with the Mql4 language. I want to compare the openordertime with a Int var and if it meats a certain amount of time and the orders are still open I want to increase the amount of open orders allowed so that I can try to reach a Breakeven situation or Maybe a profit situation and then close all open orders at the same time and set the max orders back to its originally allowed max. Can some one help me or show me code on another post that already does something like this.

I`m using this code but it seems as if it does not work.

// If orders is open for a long time close the orders and try to break even
void TimeProtection()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
if ( OrderSymbol()==Symbol() )
{
prTime = OrderOpenTime();
prTime = prTime * CallTime;
if (prTime >= TimeCurrent())
{
MaxAllowable_Trades = MaxAllowable_Trades + 3;
flag = 1;

break;
}

}
}
return;
}

I really would like your help on this.
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1640 (permalink)  
Old 03-08-2009, 08:06 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by MiniMe View Post
Hi Ralph
I have 3 variables
OrdLots ; in lots and represent the open lots but this will skip the swap
Equity ; this is the total profit loss and this one will include the swap
MinPro ; this is my take profit which is 5 pips + the breakeven point


I can't use OrdLots to find the profit/loss in pips as this will skip the swap
I can't use Equity to find the profit/loss in pips because for that I need to know how much lots,are used but my calculation for the lots skip the swap
Somehow I need to use a function of both OrdLots and Equity to know how many pips are opened
There might be something ready in MT4 that relate the account balance or account equity but I didn't find any

The solution you proposed with thanks will find the profit/loss in pips without considering swap, but I have already put a function for that ... I want to exit at 5 pips above the breakeven with the swap
Ah... maybe I understand... So if you also accumulate profit without swap into EquityNoSwap in the first loop, then you could use that rather than Equity in my "if" statement. (?) Because then the test would be "is there 5 pips profit relative the breakeven+swap price?" which actually is the same as "is there 5 pips profit ignoring the swap?" (or maybe I still don't understand)
Basically "profits+swap" is relative "breakeven", and thus "profits" is relative "breakeven+swap", and "profits" is distributed over "OrdLots". All in all you still don't need to determine an actual pips price for "breakeven".
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 11:46 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.