Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 Thread Tools Display Modes
  #191 (permalink)  
Old 08-04-2007, 04:58 AM
Iva Iva is offline
Junior Member
 
Join Date: Aug 2007
Posts: 6
Iva is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist View Post
The main problems with the code, I think, were that it didn't take spread and stop level into account, and then that the stop-loss for the SELL was placed below the open price. The following is a rehash of the code resolving those problems.

PHP Code:
void AdjustingPendingOrders()
{
    Print ( 
"Adjusting the MT pending orders" );
    
double spread MarketInfoSymbol(), MODE_SPREAD );
    
double level MarketInfoSymbol(), MODE_STOPLEVEL );
    
double offset MathMaxspreadlevel );
    
double price Bid offset Point;
    
double SL;
    for ( 
int N OrdersTotal() - 1>= 0N-- ) {
        if ( ! 
OrderSelectNSELECT_BY_POSMODE_TRADES ) )
            continue;
        if ( 
OrderType() != OP_BUYSTOP && OrderType() != OP_SELLSTOP )
            continue;
        
//---- working with pending orders only
        //---- modifying
        
if ( OrderType() == OP_BUYSTOP ) {
            
SL price StopLoss Point;
        } else {
            
SL price StopLoss Point;
        }
        
OrderModifyOrderTicket(), priceSLOrderTakeProfit(), 0CLR_NONE );
    }

Thank You, Ralph.ronquist, for Your helpful reply.
I ran my program and it not works, it does not move my pending orders.
I think that maybe the syntax of my pending orders does not correspond to this function.
Would You please check my pending orders here:
OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+10*Point,3,A sk-10*Point,Ask+20*Point," aaa ",0,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-10*Point,3,Bid+10*Point,Bid-20*Point," aaa ",0,0,Green);


Thanks a lot.

Last edited by Iva; 08-04-2007 at 05:02 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #192 (permalink)  
Old 08-04-2007, 08:19 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by Iva View Post
Would You please check my pending orders here:
OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+10*Point,3,A sk-10*Point,Ask+20*Point," aaa ",0,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-10*Point,3,Bid+10*Point,Bid-20*Point," aaa ",0,0,Green);
The BUYSTOP order requests a BUY when price has fallen down to the order price, which thus must be below current price.

The SELLSTOP order requests a SELL when price has risen up to the order price, which thus must be above current price.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #193 (permalink)  
Old 08-05-2007, 09:43 PM
iscuba11's Avatar
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 399
iscuba11 is on a distinguished road
Smile Code to close any Open Buy or Sell positions at Friday PM (Market Close)

I would like to include this with my ea, that not only stops the EA from Trading, but also closes all active buy or sell positions of that particular currency being traded before the market closes. I have a tendency to forget about the market close and end up having open positions after the market closes over the weekend - Risky!!!

Your expertise will be sincerely appreciated!!!


Dave
<><<<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #194 (permalink)  
Old 08-06-2007, 12:22 AM
Senior Member
 
Join Date: Dec 2006
Location: Ukraine
Posts: 491
Shinigami is on a distinguished road
No experts here.
Only code! Just compile it - works.
PHP Code:
#property copyright "Shinigami© 2007"
#property link      "shini1984@gmail.com"
extern int CloseHour 22;
extern int CloseDay 5;

int start()
{
if(
TimeDayOfWeek(TimeCurrent())==CloseDay)
{
if(
TimeHour(TimeCurrent())==CloseHour)
{
for(
int i=0;i<OrdersTotal();i++)
 {
  
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  if(
OrderType()==OP_BUY)
   {
    
OrderClose(OrderTicket(),OrderLots(),Bid,3);
   }
  if(
OrderType()==OP_SELL)
   {
    
OrderClose(OrderTicket(),OrderLots(),Ask,3);
   }
 }
}
}
return(
0);

It will close all orders on friday, 22:00
If you want a different day or different hour, just change parameters of the EA.
__________________
MQL4 programming is easy ^^
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #195 (permalink)  
Old 08-06-2007, 12:51 AM
Julia's Avatar
Junior Member
 
Join Date: Aug 2007
Posts: 17
Julia is on a distinguished road
Clarifications

#1: I will not post threads in the MQL4 section. Nobody goes there. I checked the date on people's questions, and the date or the right reply. 13 days, 7 days,4 days, sometimes even more.

#2: Codersguru, I think quit this forum. He never writes anymore.

Anyway,
this is the best section. Can some1 help me for the following?

If buystop triggered, then sellstop is deleted.


---Julia---
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #196 (permalink)  
Old 08-06-2007, 12:57 AM
Julia's Avatar
Junior Member
 
Join Date: Aug 2007
Posts: 17
Julia is on a distinguished road
Here is proof of what I have to a question.
Why does it modify both my sellstop and buystop, and suddenly, only my buystop?

PHP Code:
16:42:28 Expert Hawk GBPJPY,M1loaded successfully
16
:43:09 '574405'pending order buy stop 0.10 GBPJPY at 240.02 sl239.82 tp243.92
16
:43:09 '574405'request was accepted by server
16
:43:09 '574405'request in process
16
:43:09 '574405'order was opened #11688399 buy stop 0.10 GBPJPY at 240.02 sl: 239.82 tp: 243.92
16:43:10 '574405'pending order sell stop 0.10 GBPJPY at 239.74 sl239.94 tp235.84
16
:43:10 '574405'request was accepted by server
16
:43:10 '574405'request in process
16
:43:10 '574405'order was opened #11688400 sell stop 0.10 GBPJPY at 239.74 sl: 239.94 tp: 235.84
16:43:18 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 240.02 sl: 239.82 tp: 243.92 -> price: 240.01 sl: 239.81 tp: 243.91
16:43:18 '574405'request was accepted by server
16
:43:18 '574405'request in process
16
:43:18 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 240.01 sl: 239.81 tp: 243.91
16:43:18 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.74 sl: 239.94 tp: 235.84 -> price: 239.73 sl: 239.93 tp: 235.83
16:43:19 '574405'request was accepted by server
16
:43:19 '574405'request in process
16
:43:19 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.73 sl: 239.93 tp: 235.83
16:43:21 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 240.01 sl: 239.81 tp: 243.91 -> price: 240.00 sl: 239.80 tp: 243.90
16:43:21 '574405'request was accepted by server
16
:43:21 '574405'request in process
16
:43:21 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 240.00 sl: 239.80 tp: 243.90
16:43:21 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.73 sl: 239.93 tp: 235.83 -> price: 239.72 sl: 239.92 tp: 235.82
16:43:22 '574405'request was accepted by server
16
:43:22 '574405'request in process
16
:43:22 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.72 sl: 239.92 tp: 235.82
16:43:27 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 240.00 sl: 239.80 tp: 243.90 -> price: 240.01 sl: 239.81 tp: 243.91
16:43:27 '574405'request was accepted by server
16
:43:27 '574405'request in process
16
:43:27 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 240.01 sl: 239.81 tp: 243.91
16:43:27 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.72 sl: 239.92 tp: 235.82 -> price: 239.73 sl: 239.93 tp: 235.83
16:43:28 '574405'request was accepted by server
16
:43:28 '574405'request in process
16
:43:28 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.73 sl: 239.93 tp: 235.83
16:43:30 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 240.01 sl: 239.81 tp: 243.91 -> price: 239.99 sl: 239.79 tp: 243.89
16:43:31 '574405'request was accepted by server
16
:43:31 '574405'request in process
16
:43:31 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.99 sl: 239.79 tp: 243.89
16:43:32 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.73 sl: 239.93 tp: 235.83 -> price: 239.71 sl: 239.91 tp: 235.81
16:43:32 '574405'request was accepted by server
16
:43:32 '574405'request in process
16
:43:32 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.71 sl: 239.91 tp: 235.81
16:43:34 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.99 sl: 239.79 tp: 243.89 -> price: 239.97 sl: 239.77 tp: 243.87
16:43:34 '574405'request was accepted by server
16
:43:34 '574405'request in process
16
:43:34 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.97 sl: 239.77 tp: 243.87
16:43:35 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.71 sl: 239.91 tp: 235.81 -> price: 239.69 sl: 239.89 tp: 235.79
16:43:35 '574405'request was accepted by server
16
:43:35 '574405'request in process
16
:43:35 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.69 sl: 239.89 tp: 235.79
16:43:38 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.97 sl: 239.77 tp: 243.87 -> price: 239.99 sl: 239.79 tp: 243.89
16:43:39 '574405'request was accepted by server
16
:43:39 '574405'request in process
16
:43:39 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.99 sl: 239.79 tp: 243.89
16:43:39 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.69 sl: 239.89 tp: 235.79 -> price: 239.71 sl: 239.91 tp: 235.81
16:43:39 '574405'request was accepted by server
16
:43:39 '574405'request in process
16
:43:39 '574405'pending order #11688400 sell stop 0.10 GBPJPY was modified -> price: 239.71 sl: 239.91 tp: 235.81
16:43:43 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.99 sl: 239.79 tp: 243.89 -> price: 239.98 sl: 239.78 tp: 243.88
16:43:43 '574405'request was accepted by server
16
:43:43 '574405'request in process
16
:43:43 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.98 sl: 239.78 tp: 243.88
16:43:43 '574405'modify pending order #11688400 sell stop 0.10 GBPJPY at 239.71 sl: 239.91 tp: 235.81 -> price: 239.70 sl: 239.90 tp: 235.80
16:43:44 '574405'modification of pending order #11688400 sell stop 0.10 GBPJPY at 239.71 sl: 239.91 tp: 235.81 -> price: 239.70 sl: 239.90 tp: 235.80 failed [Invalid S/L or T/P]
16:43:47 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.98 sl: 239.78 tp: 243.88 -> price: 239.96 sl: 239.76 tp: 243.86
16:43:47 '574405'request was accepted by server
16
:43:47 '574405'request in process
16
:43:47 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.96 sl: 239.76 tp: 243.86
16:43:49 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.96 sl: 239.76 tp: 243.86 -> price: 239.97 sl: 239.77 tp: 243.87
16:43:49 '574405'request was accepted by server
16
:43:49 '574405'request in process
16
:43:49 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.97 sl: 239.77 tp: 243.87
16:44:00 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.97 sl: 239.77 tp: 243.87 -> price: 239.98 sl: 239.78 tp: 243.88
16:44:00 '574405'request was accepted by server
16
:44:00 '574405'request in process
16
:44:00 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.98 sl: 239.78 tp: 243.88
16:44:01 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.98 sl: 239.78 tp: 243.88 -> price: 239.97 sl: 239.77 tp: 243.87
16:44:02 '574405'request was accepted by server
16
:44:02 '574405'request in process
16
:44:02 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.97 sl: 239.77 tp: 243.87
16:44:03 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.97 sl: 239.77 tp: 243.87 -> price: 239.96 sl: 239.76 tp: 243.86
16:44:04 '574405'request was accepted by server
16
:44:04 '574405'request in process
16
:44:04 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.96 sl: 239.76 tp: 243.86
16:44:08 '574405'modify pending order #11688399 buy stop 0.10 GBPJPY at 239.96 sl: 239.76 tp: 243.86 -> price: 239.97 sl: 239.77 tp: 243.87
16:44:08 '574405'request was accepted by server
16
:44:08 '574405'request in process
16
:44:08 '574405'pending order #11688399 buy stop 0.10 GBPJPY was modified -> price: 239.97 sl: 239.77 tp: 243.87
16:44:11 Expert Hawk GBPJPY,M1removed 


PHP Code:
16:43:47 
Check this time, it is when it stops modifying the sellstop.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #197 (permalink)  
Old 08-06-2007, 12:59 AM
Iva Iva is offline
Junior Member
 
Join Date: Aug 2007
Posts: 6
Iva is on a distinguished road
Thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #198 (permalink)  
Old 08-06-2007, 01:17 AM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
To keep it simple, you have to count the orders which OrderType() == Op_BUY. and those which OrderType() == OP_BUYSTOP. If those counts are different from the previous, (OP_BUY -> +1 and OP_BUYSTOP -> -1) you can assume that a BuyStop has triggered.
If there is only one (or few) BuyStop, you can also keep in memory it's ticket from the OrderSend() and check the variation of it's OpenTime : when a pending is triggered, the OpenTime is modified according to the trigger time.
Then you just have to scan all the orders, and when you find a SellStop, delete it.
BTW, are you Dan ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #199 (permalink)  
Old 08-06-2007, 01:29 AM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Hi Iva, are you Dan too ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #200 (permalink)  
Old 08-06-2007, 08:34 AM
Iva Iva is offline
Junior Member
 
Join Date: Aug 2007
Posts: 6
Iva is on a distinguished road
Speed programming

1) When I run my program, usually sell stop and buy stop pop up. But, sometimes only one pending order pops up.When I was debugging, I noticed that one time first market tick created one pending order, and another tick created another pending order.
Strange??The market was not volatile.
2) The program also adjusts pending orders. It runs good until certain time (usually about 45 seconds) and then stops modifying some one pending order.

3)When market goes 1 tick down, then in about 1-2 seconds the pending orders go 1 tick down too.

It looks to me that the codes does not catch all market ticks.
My question is ; is there some available function (e.g. RefreshRates() that makes the code to catch all the ticks and process them
Thank you all.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
automated close order, close, eas, forex, learn mql4, learn mql4 video, mql4 learning, OrderCloseBy, profit, reach, secure profit function, T101_v1.11_orest_IBFXm.mq4, learning mql4

Thread Tools