EA CODING ISSUE/HELP - closes trades and open new, on new bar - page 2

 
Yohana Parmi:

hi, what is that meant your requirement to check on each new candle was solved by my code above?

I tried here, and it works.


hi i tried your method too thanks, but my problem is that when trade is open it closes on new bar and opens a new trade. It should not do that it should wait for the trailing stop to be hit.

 
ztmalick:


hi i tried your method too thanks, but my problem is that when trade is open it closes on new bar and opens a new trade. It should not do that it should wait for the trailing stop to be hit.


yes, I understand what you meant :)

you should record (counted in a variable) your previous position before do something again at new candle to come.

maybe you need to create a flowchart before start writing your program.
 
Yohana Parmi:

yes, I understand what you meant :)

you should record (counted in a variable) your previous position before do something again at new candle to come.

maybe you need to create a flowchart before start writing your program.

but CheckOpenOrders should be returning true/false instead. then:

int start()
  {
//----
if(CheckOpenOrders() == true)
{
trail();
}
if(CheckOpenOrders() == false)
{
if(IsNewCandle())
{
trenddirection(); //find trend direction
logic(); //apply indicator logic
Lot_Volume(); //calc lotsize
buyorsell(); //trade - buy or sell
  return(0);
}
}
return(0);

}
 
ztmalick:


hi i tried your method too thanks, but my problem is that when trade is open it closes on new bar and opens a new trade. It should not do that it should wait for the trailing stop to be hit.

Btw, I can't find OrderClose() in your code :)

Can you please show me?

and also, you have some loops in a cycle.

example:

int trail()
{
   string Symb=Symbol();                        // Symbol
//------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type

should be :

int trail()
{
   string Symb=Symbol();                        // Symbol
   int total_order = OrdersTotal();
//------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=total_order; i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type

2 code above is looks the same, but actually both of them are different in results and performance :)

later you will understand that.

 
Yohana Parmi:

Btw, I can't find OrderClose() in your code :)

Can you please show me?

and also, you have some loops in a cycle.

example:

should be :

2 code above is looks the same, but actually both of them are different in results and performance :)

later you will understand that.


it doesnt have OrderCLose, just trailing stop and OrderSend. thanks for the extra info.....

 

Hi ztmalick,

This is what I am looking to do. Did you manage to fix your code in the end?