Stochastic system - Error
  #1 (permalink)  
Old 07-20-2006, 08:10 PM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default Stochastic system - Error

I created a simple EA based on 15 minutes chart..The sistem is the seguent:

- when Stochastic cross over its Moving Average then buy a lot
- when Stochastic cross under its Moving Average then close the long position
- when Stochastic cross under its Moving Average then sell short a lot
- when Stochastic cross over its Movinga Average then close the short position

But I saw that when it close a position, it attend the next bar to open a contrary position...It's possibile to make that it close the position and AT THE SAME MOMENT it open a contrary position? (Stop and Reverse)
Where is my error in the code?
Reply With Quote
  #2 (permalink)  
Old 07-21-2006, 03:04 AM
scorpion's Avatar
Administrator
 
Join Date: Aug 2004
Posts: 1,974
Thanks: 119
Thanked 383 Times in 152 Posts
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Send a message via MSN to scorpion Send a message via Yahoo to scorpion
Default

It's possible to close and then open another order, provided that you give 6 seconds pause before opening. If you open immediately after you close then Metatrader will give "too frequent" error.

Code like this:
1. Close the order
2. Sleep(6000)
3. Open another order
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #3 (permalink)  
Old 07-21-2006, 09:00 AM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default

I tried to modify my EA with your suggestion, but it doesn't work..I attached the original EA and the modified EA: can you tell me where is my error?
Attached Files
File Type: mq4 EA.mq4 (9.6 KB, 24 views)
File Type: mq4 EAsleep.mq4 (9.6 KB, 15 views)
Sponsored Links Shark EA Ultimate
Actual Profits on Live Account: +1064%
Since Jan 2007. View Live Statements.
Reply With Quote
  #4 (permalink)  
Old 07-22-2006, 02:29 PM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default

I'm working on it, but I can't solve the problem..I don't understand why it doesn't reverse the position..The code seems ok, isn't it?
Reply With Quote
  #5 (permalink)  
Old 07-24-2006, 09:11 PM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default

Quote:
Originally Posted by tradetrade
I tried to modify my EA with your suggestion, but it doesn't work..I attached the original EA and the modified EA: can you tell me where is my error?
I add a new question..Hoping someone answer to me..(it's very difficult to me, these are my first steps with EAs..): how can I modify the attached file (in precedent post named EA.mq4) if I want open 2 lots and close the first lot when profit is 10 pips and leave run other lot?

I tried to write:
if (Bid > (OrderOpenPrice()+TakeProfit2*Point)&& ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OneLot, Bid, Slippage, MediumSeaGreen);

where TakeProfit2 = 10, but it doesn't work..When I open Metatrader it is "grey"...Can anyone help me?
Reply With Quote
  #6 (permalink)  
Old 07-25-2006, 06:49 AM
gazuz's Avatar
Senior Trader and Moderat
 
Join Date: Aug 2004
Posts: 768
Thanks: 1
Thanked 8 Times in 5 Posts
gazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to all
Default

What I am about to say reminds of computer tech support when they ask you if you turned on the computer... Now as basic as this may sound, did you try clicking the debug function in the MT4 Editor?... I noticed a lot of people skip that step, it will point out if you mis-wrote something.
__________________
____________________________\¦/
___________________________(ò ó)
______________________o0o___(_)___o0o__
___¦_____¦_____¦_____¦_____¦_____¦_____¦
¦_____¦_____¦_____¦_____¦_____¦_____¦__
___¦_____¦_____¦_____¦_____¦_____¦_____¦
¦_____¦_____¦_____¦_____¦_____¦_____¦__
Reply With Quote
  #7 (permalink)  
Old 07-25-2006, 08:01 AM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default

Quote:
Originally Posted by gazuz
What I am about to say reminds of computer tech support when they ask you if you turned on the computer... Now as basic as this may sound, did you try clicking the debug function in the MT4 Editor?... I noticed a lot of people skip that step, it will point out if you mis-wrote something.
Sorry but I don't understand..What does it mean?

I usually write an ea and then I save the file as metatrader file..I miss some steps? (others eas work..)

Last edited by tradetrade : 07-25-2006 at 08:04 AM.
Reply With Quote
  #8 (permalink)  
Old 07-25-2006, 02:27 PM
scorpion's Avatar
Administrator
 
Join Date: Aug 2004
Posts: 1,974
Thanks: 119
Thanked 383 Times in 152 Posts
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Send a message via MSN to scorpion Send a message via Yahoo to scorpion
Default

Hey

If sleep() doesn't work, you should replace all standard ordering functions with my extended functions. Just add Ex after SelectOrder, OrderSend, OrderClose, OrderDelete, OrderModify. Example: SelectOrderEx, OrderSendEx, etc. This will eliminate many ordering problems.

And, add below code to your expert:
PHP Code:
//+------------------------------------------------------------------+
//| Extended order execution functions for used in multiple pairs    |
//| with automatic retry attempts.                                   |
//+------------------------------------------------------------------+
int OrderSendEx(string symbolint cmddouble volumedouble priceint slippagedouble stoplossdouble takeprofitstring commentint magicdatetime expiration=0color arrow_color=CLR_NONE) {
  if(!
WaitWhileBusy())
  {
    Print(
"Error in OrderSendEx(): Timeout encountered");
    return(-
1);
  }
  
SetBusyState();
  
int ticket OrderSend(symbolcmdvolumepriceslippagestoplosstakeprofitcommentmagicexpirationarrow_color);
  
Sleep(6000);
  
ReleaseBusyState();  
  return(
ticket);
}


bool OrderCloseEx(int ticketdouble lotsdouble priceint slippagecolor Color=CLR_NONE)
{
  if(!
WaitWhileBusy())
  {
    Print(
"Error in OrderCloseEx(): Timeout encountered");
    return(
false);
  }
  
SetBusyState();
  
bool ret OrderClose(ticketlotspriceslippageColor);
  
Sleep(6000);
  
ReleaseBusyState();  
  return(
ret);
}

bool OrderDeleteEx(int ticket)
{
  if(!
WaitWhileBusy())
  {
    Print(
"Error in OrderDeleteEx(): Timeout encountered");
    return(
false);
  }
  
SetBusyState();
  
bool ret OrderDelete(ticket);
  
Sleep(6000);
  
ReleaseBusyState();  
  return(
ret);
}

bool OrderModifyExint ticketdouble pricedouble stoplossdouble takeprofitdatetime expirationcolor arrow_color=CLR_NONE)
{
  if(!
WaitWhileBusy())
  {
    Print(
"Error in OrderModifyEx(): Timeout encountered");
    return(
false);
  }
  
SetBusyState();
  
bool ret OrderModify(ticketpricestoplosstakeprofitexpirationarrow_color);
  if(
ret)
  {
    
Sleep(6000);
  }else{
    Print(
"Error in OrderModifyEx(): "LastErrorText());
  }
  
ReleaseBusyState();  
  return(
ret);
}


bool OrderSelectEx(int indexint selectint pool MODE_TRADES)
{
  if (
OrderSelect(index,select,pool)==true)
  {
    return(
true);
  }else{
    Print(
"Error: Order #"index ," cannot be selected. "LastErrorText());
  }
}


//+------------------------------------------------------------------+
//| Calling state functions                                          |
//+------------------------------------------------------------------+
bool WaitWhileBusy()
{
   
datetime OldCurTime;
   
int timeoutsec=6;
   
   
OldCurTime=CurTime();
   while (
GlobalVariableCheck("InTrade") || !IsTradeAllowed()) {
      if(
OldCurTime timeoutsec <= CurTime()) {
         return(
false); 
      }
      
Sleep(1000);
   }
   return(
true);
}


void SetBusyState()
{
  
GlobalVariableSet("InTrade"CurTime());  // set lock indicator
}

void ReleaseBusyState()
{
  
GlobalVariableDel("InTrade");   // clear lock indicator

__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #9 (permalink)  
Old 07-25-2006, 02:34 PM
scorpion's Avatar
Administrator
 
Join Date: Aug 2004
Posts: 1,974
Thanks: 119
Thanked 383 Times in 152 Posts
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Send a message via MSN to scorpion Send a message via Yahoo to scorpion
Default

Quote:
Originally Posted by tradetrade
I add a new question..Hoping someone answer to me..(it's very difficult to me, these are my first steps with EAs..): how can I modify the attached file (in precedent post named EA.mq4) if I want open 2 lots and close the first lot when profit is 10 pips and leave run other lot?

I tried to write:
if (Bid > (OrderOpenPrice()+TakeProfit2*Point)&& ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OneLot, Bid, Slippage, MediumSeaGreen);

where TakeProfit2 = 10, but it doesn't work..When I open Metatrader it is "grey"...Can anyone help me?
The sequence of the code is:
OrderSelectEx(...)
If (Bid > OrderOpenPrice() + (TakeProfitPips * Point))
{
OrderClose(ticket, OneLot, Price, Slippage, Color);
}

Look at the bold text, especially Price. For buy order, it's Bid. For sell order, it's Ask.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #10 (permalink)  
Old 07-25-2006, 07:45 PM
Freshman
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
tradetrade is on a distinguished road
Default

Quote:
Originally Posted by scorpion
The sequence of the code is:
OrderSelectEx(...)
If (Bid > OrderOpenPrice() + (TakeProfitPips * Point))
{
OrderClose(ticket, OneLot, Price, Slippage, Color);
}

Look at the bold text, especially Price. For buy order, it's Bid. For sell order, it's Ask.
Sorry but I can't apply this to my EA..For example, I didn't find "OderSelecEx"..what is it? The code I use to close position is the seguent: how I have to modify it in order to your suggest?

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+

if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;

I tried this, but obviously it doesn't work (...):

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+

if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), 1, Bid, Slippage, MediumSeaGreen);
If (Bid > OrderOpenPrice() + (Range6 * Point))
{OrderClose(ticket, 1, Bid, 3, Red);}
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;

Last edited by tradetrade : 07-25-2006 at 07:56 PM.
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Great System! FxOverEasy scorpion Trading Systems 9 08-30-2008 03:57 PM
CCI + Stochastic gazuz Trading Systems 19 03-10-2008 10:14 AM
Weekly breakout system ! amarnath Trading Systems 6 09-29-2007 12:15 AM
ANALYTICAL SOFTWARE for Traders (March 2006) max777 Classified Ads 2 08-20-2007 10:42 PM
ANALYTICAL SOFTWARE for Traders (June 2006) max777 Classified Ads 0 06-18-2006 11:32 PM


All times are GMT. The time now is 10:13 PM.
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0

Registered members have access to special online forex currency trading tools, software, mt4 expert advisors and indicators. Register now

Main Menu

Economic Forecast