Serious problem with Logic of trade entry point - page 2

 

What i think you are trying to do is load an EA onto a chart which then asks you for a trade entry point (TEP). So your code outline like would look something like

extern double TEP ; 



//The EA then looks at the previous prices timewise to determine the current price direction of up or down.
if (Close[1]>Close[2]) 
{

//price is moving up so use a BUY order 
  if (Ask>TEP) 
    {
     //Place  buy order  
    }

}

else

{

//use a SELL order
  if (Bid<TEP) 
  {
   //Place sell order
  } 
 }// end if statement

However there is more to consider like the price bounces up and then back down below the TEP then the EA would place another order so you place another if before placing an order and count the number of orders you already have but you then need to identify if it is your order for this chart. Now you begin to see why there are so many checks before placing an order?

 

Thankyou for that

well I was using

int orders = OrdersTotal();

if (orders==0)

then proceeding with the code. At the moment I only want one order on at a time.

.

.

couldn't using the close as an indicator of price movement show a false result ? I see what you are meaning, but I wonder if there is a better indicator of previous movement.

 

Moving Average for the last n bars is probably better but the code sample I gave you was just dumped straight out of my head. Correct on using OrdersTotal()

 
Ickyrus:

Moving Average for the last n bars is probably better but the code sample I gave you was just dumped straight out of my head. Correct on using OrdersTotal()


thanks, now I need to be correct on getting the market entry at price.

Do you maybe know of an EA that I could use to learn from perhaps ?

I was wondering if it is possible ?

 

Now add in a take profit value, stop loss value and a watch to see if Ask or Bid have reached Entry Price plus/minus take profit value and or stop loss value so that you can send a CloseOrder at which point you will have to get the EA so quit. so you call the following function.

/////////////////////////    
void commitSuicide() //Don't forget to use at the top of the EA the line #include <WinUser32.mqh> for this function to work.
{
  int h = WindowHandle(Symbol(), Period());
  if (h != 0) PostMessageA(h, WM_COMMAND, 33050, 0);
}
///////////
 
Ickyrus:

Now add in a take profit value, stop loss value and a watch to see if Ask or Bid have reached Entry Price plus/minus take profit value and or stop loss value so that you can send a CloseOrder at which point you will have to get the EA so quit. so you call the following function.


thats great thanks.

part of the reason I was wanting the EA to decide where the price is, direction of movement and decision to trade

is because I though once the TP was taken, it would have to wait again for a suitable time to re-enter

If the SL is taken, I want to open an order in the other direction

 

The MACD sample code is well commented and when you feel you can understand it then alter it to get ideas then find a system and attempt to code it all this will build the needed experience.

 

Also the code base on this forum is full of bad to very good code, by looking at the code and trying to understand it you gain experience of other coders.

 
Ickyrus:

The MACD sample code is well commented and when you feel you can understand it then alter it to get ideas then find a system and attempt to code it all this will build the needed experience.


yes, thankyou Ickyrus, I read that EA last night and I find it understandable. It is the first EA I have read, and I feel I have came on a lot in the last week considering I knew nothing about programming a week ago. Im also encouraged that the simple MACd EA also uses two "branches" of programming, one for the long trades and one for the short, which is how my own EA is developing. I was wondering if this was the right approach.

I can use some of the material from that EA and I will also have a go at hacking it. I can see the trailing stop is pretty basic too but all the same I will learn from that.

.

I have one question from it you may be able to answer if you could. I understand the for (loop ?) and the counter it contains. I have come across two pieces of code where the integer of the counter in the for loop is also in the first line of the next piece of code.

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

why is the integer cnt included in the order select function ?

 
MickGlancy:

I looked at other Ea's but they seem to specify lots of conditions, but not a specific price, as the only condition for market entry

Mick -

you need to have your EA monitor the current Bid & Ask. When the Ask or Bid goes to or above your strike price, you then throw a Market Order to the server.

I dont like having my pending orders sitting there either. Nor do i like having my stop loss sitting on the brokers server. many brokers will screw you "hunting stops".

Another thing that can happen with Stop Orders is that the spread can stretch wide open. A BUY Stop Order will open on the Ask price. So as soon as the Ask hits your

strike price, YOU ARE BOUGHT. Even if the Bid is 10pips lower. I got Stretched for 7.4 pips this week on the GBPUSD which has a "normal" spread of 1.5p.

The order immediately went South (Touch & Reverse). This has happened too often! Bottom line is, YOU need to decide which price to follow, Bid or Ask.

You could also throw a Limit order at your strike price AFTER Bid gets above your strike, but you could miss a fast mover.

Let me know what you want to do, i may be able to help you with coding.....

Reason: