Forex
Google
New signals service!

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


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

Reply
 
LinkBack (2) Thread Tools Display Modes
  #301 (permalink)  
Old 08-30-2006, 07:45 AM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Smile

[quote=phoenix]then add this maybe better[/QUOTE

This is the latest backtester run. So close yet so far. Reminds me of my Vietnam days. Check out the .gif of the results attached. I owe you for having the goodness of your heart to help me through this tribulation moment! It still seems as if there is a loop that is not exiting as showing in the sell trade.

Dave
<><<
Attached Images
File Type: gif darn close to having it working right!.gif (54.5 KB, 80 views)

Last edited by iscuba11; 08-30-2006 at 07:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #302 (permalink)  
Old 08-30-2006, 07:53 AM
phoenix's Avatar
Senior Member
 
Join Date: May 2006
Posts: 289
phoenix is on a distinguished road
Quote:
Originally Posted by iscuba11
I owe you for having the goodness of your heart to help me through this tribulation moment!
Dave
<><<
you are wellcome
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #303 (permalink)  
Old 08-30-2006, 08:25 AM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Exclamation

I still have a loop - darn it. I am going to crash. Tomorrow is another day. This low level language is the pits to learn.

Dave
<><<<

///////////////////MODIFY STOP LOSS & TAKE PROFIT AT START OF SLEEP CYCLE /////////////////


for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)

OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))
{
if(OrderOpenPrice()-Ask>=TrailingStop*Point)
{
if(OrderStopLoss()>Ask+Point*15||OrderStopLoss()== 0)

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit
}
return(0);
}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))
{
if(Bid-OrderOpenPrice()>=TrailingStop*Point)
{

if(OrderStopLoss()<Bid-Point*15 ||OrderStopLoss()==0)

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit
}
return(0);
}
return(0);
}
}
//////////////////////////////////////////////////////////////////////////////////////



My coding as it stands above. There is a bug in it that causes a modification loop. Many bugs or additions have brought it to this stage. Please help find the loop bug somebody!
Attached Images
File Type: gif so close yet still a problem with it!.gif (54.5 KB, 76 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #304 (permalink)  
Old 08-30-2006, 10:44 AM
phoenix's Avatar
Senior Member
 
Join Date: May 2006
Posts: 289
phoenix is on a distinguished road
or may it was my missunderstood of you purpose

what do you want the OrderModify() function to do so?

to do trailling stop or something else?

pls clearify it again
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #305 (permalink)  
Old 08-30-2006, 03:11 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Thumbs up

The original design is to tighten up the stop losses and take profits on any open buy or sell orders when the program is about to go into its sleep mode.

Instead of a large 40 - 50 pip stop loss and a large 100 pip take profit in each open trade, I wanted each open trades be reduced to a 15 pip stop loss, and the take profit of 100 be reduced to a 25 pip take profit.

Then the program would sleep (stop) and the open trades would run their course without any further program intervention (sleep mode) - Each open trade would then make either a 25 pip profit or make a 15 pip loss and close themselves out.

I hope this helps clarify the purpose of the stop loss and take profit modification. I am sorry for the misunderstanding. Please help if you will to accomplish these modifications! Thanks so much for your help up to now!

Boy, did need the sleep last night myself!

Dave
<><<<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #306 (permalink)  
Old 08-30-2006, 04:34 PM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
Quote:
Originally Posted by iscuba11
I am piece mealing this program together. I am close to completing it. Unfortunately, there are no schools on this language and the documentation leaves a lot to be desired. In that being said, I do not have a clue what you are talking about. No offense intended!

Dave
<><<<
When you are going to copy and paste a code snippet, select that little "php" button on top of the edit screen. Alternatively, you can first type "[ PHP ]"
and then end your code by typing "[ /PHP ]" without the quotes and remove the spaces within the square brackets. See what you get
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #307 (permalink)  
Old 08-30-2006, 05:17 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Red face

Quote:
Originally Posted by Maji
When you are going to copy and paste a code snippet, select that little "php" button on top of the edit screen. Alternatively, you can first type "[ PHP ]"
and then end your code by typing "[ /PHP ]" without the quotes and remove the spaces within the square brackets. See what you get

The PHP button? Is this located on the forum side or the MetaEditor from which I am copying the code from?? I cannot find a PHP button on the MetaEditor.

Dave
<><<<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #308 (permalink)  
Old 08-30-2006, 05:20 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Smile

PHP Code:
if (FirstRun==1) {
FirstRun=0;
prevtime=Time[0];
}
if ((
prevtime == Time[0]) &&  (CurTime()-prevtime)>MaxTradeTime) {
NewBar=0;
}
else {
prevtime 
I found it! Will do this in future - We learn with the help of others that have more knowledge and wisdom than we do in areas of our lack of understanding! Thank You Very Much!

Dave
<><<<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #309 (permalink)  
Old 08-30-2006, 05:27 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Smile

PHP Code:
   for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)
   
   
OrderSelect(cnt1SELECT_BY_POSMODE_TRADES);
   
   if (
OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))
   {
   if(
OrderOpenPrice()-Ask>=TrailingStop*Point)
   {
   if(
OrderStopLoss()>Ask+Point*15||OrderStopLoss()==0)
   
   
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit
   
}
   return(
0);
   }

   if (
OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))
   {
    if(
Bid-OrderOpenPrice()>=TrailingStop*Point)
   { 
    
   if(
OrderStopLoss()<Bid-Point*15 ||OrderStopLoss()==0
    
   
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit
   
}
   return(
0);
   }
   return(
0);
   }
   } 
With right format now, would one of you very generous coders help me resolve this SL and TP issue above. Back to my original request. My sleep program deactivates the EA at various times. The EA created open trades prior to the sleep mode with 40 - 50 pip Stop Loss, and Take Profit of 100. Just prior to the EA being put to sleep, I want the Stop Loss on each open ticket to change to 15 pips, and the take profit changed to 25 pips. The stoploss is not to be a trailing stop, but a hard stop below(buy) or above(sell) its present trading price (likewise the Take Profit). Lend me your expertise and make my day!!

Last edited by iscuba11; 08-30-2006 at 05:33 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #310 (permalink)  
Old 08-30-2006, 05:39 PM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
For trailingstops, use the following function. I think it is written in a way that can be understood easily. Sometimes programming geeks write code, that may be efficient by a fraction of a millisecond, but makes it a darn difficult job to read and debug.

PHP Code:
void TrailingAlls(int start,int stop)
{
 
int profit;
 
double stoptrade;
 
double stopcal;
 
 if(
stop==0)
  return;
 
 
int trade;
 for(
trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(!
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
   continue;

  if(
OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if(
OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)   
  {
   if(
OrderType()==OP_BUY)
   {
    
profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
    if(
profit<start)
     continue;
    
stoptrade=OrderStopLoss();
    
stopcal=Bid-(stop*Point);
    if(
stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
     
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
   }
//Long
  
   
if(OrderType()==OP_SELL)
   {
    
profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
    if(
profit<start)
     continue;
    
stoptrade=OrderStopLoss();
    
stopcal=Ask+(stop*Point);
    if(
stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
     
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
   }
//Shrt
  
}
 }
//for

Call it in your start using the following:
TrailingAlls(TrailStartPips,TrailStopPips);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram, forex, ZUP_v1.mq4

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 10:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 12:46 PM


All times are GMT. The time now is 06:26 AM.



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