Fractal Break Out-Stuck - page 2

 

I am currently getting the ending bracketing "}" error.


But I have re-checked the functions and they are all processed correctly.


I tried another way, and continued to get this same error.

 
ZacharyRC:

I am currently getting the ending bracketing "}" error.


But I have re-checked the functions and they are all processed correctly.


I tried another way, and continued to get this same error.


I have found the error, nevermind!
 
ZacharyRC:

Hey deVries:


I am running into issues in my final code, with trying to put a modify stop loss to breakeven after so many pips.


Do you see any glaring error???

You need to read this again:  What are Function return values ? How do I use them ?   don't you want to know what is going on with your OrderModify() ?  what happens if your OrderSelect() fails ?

 
if(OrdersTotal()>1)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==(OP_BUY)&&(Move.BE))
{

 This is not the right way to get the trades of your EA

you can't be sure that position 0 is from your EA you have to manage

use always a loop to get through all open trades and then select that way you have

your Symbol() the EA is trading  and  the MAGICNUMBER you gave with your EA

.

my way is like

 

 for(i = OrdersTotal()-1; i >= 0 ; i--)         //always counting down checking trades
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;     // if false we abort the loop
     if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;   //if selected trade not symbol or magicnumber next one
 
RaptorUK:

You need to read this again:  What are Function return values ? How do I use them ?   don't you want to know what is going on with your OrderModify() ?  what happens if your OrderSelect() fails ?


I will definitely re- read tonight, I dont have a full grasp yet.
deVries:

 This is not the right way to get the trades of your EA

you can't be sure that position 0 is from your EA you have to manage

use always a loop to get through all open trades and then select that way you have

your Symbol() the EA is trading  and  the MAGICNUMBER you gave with your EA

.

my way is like

 

 I was using a for() loop last time, and had a couple errors and gave up on it. Will try it again and re-read text.


Thank you gentlemen.

 

 
RaptorUK:

You need to read this again:  What are Function return values ? How do I use them ?   don't you want to know what is going on with your OrderModify() ?  what happens if your OrderSelect() fails ?


I feel a little slow today! After letting that sink in, I realize that the MQL4 language can be the best mate for finding errors, not the message board.



TY RaptorUK!

 
ZacharyRC:

I feel a little slow today! After letting that sink in, I realize that the MQL4 language can be the best mate for finding errors, not the message board.

Exactly,  100% correct.   :-)
 
deVries:

 This is not the right way to get the trades of your EA

you can't be sure that position 0 is from your EA you have to manage

use always a loop to get through all open trades and then select that way you have

your Symbol() the EA is trading  and  the MAGICNUMBER you gave with your EA

.

my way is like

 

 Ahhhh I see, this allows me to cycle through my trades and tell which is which and match the Magic Numbers. Loop is the best way by far.

 

 
ZacharyRC:

Ahhhh I see, this allows me to cycle through my trades and tell which is which and match the Magic Numbers. Loop is the best way by far.

The more you gonna use it the more tricks you learn to do with it....
 

Still having difficulties. I have conducted errors to find out why.


Journal Has Reported:

1) Error 4051=Incorrect Parameter

2) Invalid Ticket for Modifying Order

//----------------------------------------------//
//-----------------EXITING ORDERS---------------//


for(int i=OrdersTotal()-1; i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;


if(OrderMagicNumber()!=MagicNumber || OrderSymbol() !=Symbol()) continue;

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) Print(GetLastError(),i);
if(OrderType()==OP_BUY)
{

 if(Move.BE && StopLoss > 0) 
 {
   if(Bid - OrderOpenPrice() >= Point * StopLoss)
     {
       if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) 
        {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                  Print("Cant Modify Order"+GetLastError(),i);
 }
  }
   }
    }
 else{
 
    if(Move.BE && StopLoss > 0) {
               if(OrderOpenPrice() - Ask >= Point * StopLoss)
                {
                  if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo)
                   {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                  Print("Cant Modify Order"+GetLastError(),i);
}
 }
  }
   }
    }

Reason: