Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
Thierry F.
114
Thierry F. 2014.10.13 15:01 

Hi,


I've programmed a really simple expert advisor. The EA opens a long position when the slow stochastics closes below the value 86. 

 
extern double lot = 0.1;
extern double tp = 60; //for EURUSD M5
extern double sl = 1000; //for EURUSD M5


 
int start()
  { 
     double r1 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN,1);
     double r2 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN,2);
     
     {
 
     if (r2>86 && r1<86 && OrdersTotal()<1) 
     {  
     OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+sl*Point,Bid-tp*Point,"Stoch signal",0,0,clrRed);
     }
          
       }
    return(0);    
     }


The EA does it's job, but sometimes it opens a new position when the TP is hit inside the first candle. (check the image http://prntscr.com/4vrtlr )

How should I add to my code to repair this problem. Is there a parameter who stores the amount of orders inside a candle?


Thanks in advance,

Thierry

Carl Schreiber
5965
Carl Schreiber 2014.10.13 16:05  

you have to code that yourself.

The TP is triggered while the condition to open the trade is still true: wait a) for some time b) for a trade in the other direction c) ...

whroeder1
13649
whroeder1 2014.10.13 16:22  
xtractalpha: The EA opens a long position when the slow stochastics closes below the value 86. 

The EA does it's job, but sometimes it opens a new position when the TP is hit inside the first candle. (check the image http://prntscr.com/4vrtlr )

How should I add to my code to repair this problem. Is there a parameter who stores the amount of orders inside a candle?

extern double tp = 60; //for EURUSD M5
extern double sl = 1000; //for EURUSD M5

OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+sl*Point,Bid-tp*Point,"Stoch signal",0,0,clrRed);
  1. nope
  2. The stops of a sell are relative to the Ask. So your actual TP is tp - spread. 60 - 20 = 4 pips.
  3. If you don't want to open in the same bar remember the bar time when you open (global/static) and check for new/same bar.
Thierry F.
114
Thierry F. 2014.10.13 17:18  
     if (r2>86 && r1<86 && OrdersTotal()<1) 
     {  
     OrderSend(Symbol(),OP_SELL,lot,Ask,0,Ask+sl*Point,Ask-tp*Point,"Stoch signal",0,0,clrRed);
     Sleep(300000); //milliseconds
     }


Gooly & WHRoder thanks for your help!

You are right about the Ask price, I've edited it in my EA. 

I've added a sleep function after my "ordersend" function. That should do the job too (In my eyes).


Thanks

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.10.15 11:14  
F7 > Common > Allow live trading

Something like that.

Thierry F.
114
Thierry F. 2014.10.15 11:38  

Thank you, I feel so stupid.

/
To add comments, please log in or register