Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

 
 
LinkBack Thread Tools
 
Old 05-30-2007, 06:14 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 400
iscuba11 is on a distinguished road
Smile StopLoss and Take Profit Script

Can someone debug the bug I have in this script?? Much appreciated!!

Dave


PHP Code:
//+------------------------------------------------------------------+
//|                                                       modify.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_confirm

//+------------------------------------------------------------------+
//| script "modify first market order"                               |
//+------------------------------------------------------------------+
int start()
  {
   
bool   result;
   
double stop_loss,point;
   
double take_profit;
   
int    cmd,total,error;
//----
   
total=OrdersTotal();
   
point=MarketInfo(Symbol(),MODE_POINT);
//----
   
for(int i=0i<totali++)
     {
      if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         
//---- print selected order
         
OrderPrint();
         
cmd=OrderType();
         
//---- buy or sell orders are considered
         
if(cmd==OP_BUY || cmd==OP_SELL)
           {
            
//---- modify first market order
            
while(true)
              {
               if(
cmd==OP_BUYstop_loss=(Bid-10*point) && take_profit=(Ask+50*point);
               else            
stop_loss=(Ask+10*point) && take_profit=(Bid-50*point);
               
result=OrderModify(OrderTicket(),0,stop_loss,take_profit,0,CLR_NONE);
               if(
result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
               else 
error=0;
               if(
error==135RefreshRates();
               else break;
              }
             
//---- print modified order (it still selected after modify)
             
OrderPrint();
             break;
           }
        }
      else { Print( 
"Error when order select "GetLastError()); break; }
     }
//----
   
return(0);
  }
//+------------------------------------------------------------------+ 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
 
Old 05-31-2007, 03:38 PM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 439
ryanklefas is on a distinguished road
What kind of problem were you having with it?
__________________
"Don't work harder, work smarter." -- my Java professor

Coder for Hire:
http://www.firecell-fx.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
 

Bookmarks
Thread Tools

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
Virtual StopLoss Flytox Metatrader 4 1 05-17-2007 01:43 AM
autotrade - stoploss sminic Metatrader 4 1 02-05-2007 10:05 AM


All times are GMT. The time now is 07:36 PM.



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