problem on reading from a binary file ?

 
void function()
{

       int i; 
  
       for(i = OrdersTotal()-1; i >= 0 ; i--) 
            { 
         OrderSelect(i,SELECT_BY_POS); 
         
          bool tp1_allowed= true; 
          
          if(OrderSymbol()==Symbol())
                  {
           if(OrderType()==OP_SELL)
                     {
                     

         int handleA=FileOpen("neworders.dat_b", FILE_BIN|FILE_READ);
         if (handleA>0)
                   {   
         int gA=FileReadArray(handleA,Neworder_b,0,1000);     
               FileClose(handleA);         
                     } 
                     
                Print("file magic",Neworder_b[i]);  
                Print("magic",OrderMagicNumber()); 
                  

          if (OrderMagicNumber()==Neworder_b[i]) 
                {  
            tp1_allowed= false; 
                  }    
     
          if (tp1_allowed==true) //do more stuff with the trade..........
          //....................
     }     
   }
  }
}
//+----------------

I am comparing the current open trade(s) magic numbers to the magic numbers stored in the "Neworders_b" file.

If the current magic number exists in the Neworders_b file then i want the bool (tp1_allowed=false);

file magic and magic are printing as the same! But tp1_allowed is still coming back as false.

Can someone correct this code for me.. Please....

 
gavin:

Can someone correct this code for me.. Please....

A guess . . . .

Chnage . . .

double Neworder_b[xxx]

to 

int Neworder_b[xxx]
 
RaptorUK:

A guess . . . .


no that is not the problem, but i dont know what is.
 
Can't tell from your code snippet . . .
 
RaptorUK:
Can't tell from your code snippet . . .

if (OrderMagicNumber()==Neworder_b[i]) 
                {  
            tp1_allowed= false; 
                  }    

This piece is the problem i think.

What i need here is >>>>

>> if magic number exists in the Neworder_b file, bool tp1 allowed = false;

But is this code asking this question?? Is the [i] wrong?

 

You said . . . . " file magic and magic are printing as the same! "

I assume from this code . . .

Print("file magic",Neworder_b[i]);  

Print("magic",OrderMagicNumber()); 

So then tp1_allowed must equal false.

 
gavin:

This piece is the problem i think.

What i need here is >>>>

>> if magic number exists in the Neworder_b file, bool tp1 allowed = false;

But is this code asking this question?? Is the [i] wrong?

Yes, finally, because this is the same code you had in your other thread. It is not possible to debug your code for you if you don't explain what the required function is!

I told you before the [i] looked fishy. You need to put in an extra loop so you can loop through all the entries in Neworder_b. For this value if [i] check all the values of Neworder_b for a match.

 
dabbler:

Yes, finally, because this is the same code you had in your other thread. It is not possible to debug your code for you if you don't explain what the required function is!

I told you before the [i] looked fishy. You need to put in an extra loop so you can loop through all the entries in Neworder_b. For this value if [i] check all the values of Neworder_b for a match.


//+----------------
void function()
{

       int i; 
  
       for(i = OrdersTotal()-1; i >= 0 ; i--) 
            { 
         OrderSelect(i,SELECT_BY_POS); 
         
          bool tp1_allowed= true; 
          
          if(OrderSymbol()==Symbol())
                  {
           if(OrderType()==OP_SELL)
                     {
                     
         int handleA=FileOpen("neworders.dat_b", FILE_BIN|FILE_READ);
         if (handleA>0)
                   {   
         int gA=FileReadArray(handleA,Neworder_b,0,1000);     
               FileClose(handleA);         
                     } 
                     
                                  

          if (OrderMagicNumber()==Neworder_b[i]) 
                {  
            tp1_allowed= false; 
                  }
                      
     
          if ((tp1_allowed==true) && MarketInfo(OrderSymbol(),MODE_ASK)<=sell_tp)
               {

///part 1   OrderClose(OrderTicket(),CloseLot,MarketInfo(OrderSymbol(),MODE_ASK),0,CLR_NONE); /////part 1/////
           Neworder_b[i] = OrderMagicNumber();
                                                 
            int handle=FileOpen("neworders.dat_b",FILE_BIN|FILE_WRITE);
            int f=FileWriteArray(handle, Neworder_b,0,1000);if(f<0)
                  {
            Print("Write file Error_1:  ",GetLastError());
                  }
            FileClose(handle);
            if(handle<0)
                   {
            Print("Write file Error_1:  ",GetLastError());
                }
              }   
                                                         
         } 
  return;
}
//+------------------------------------------------------------------+ 

There is the code and you can see what i am trying to do.

I have spent alot of time trying to figure this and not getting very far.

This function works perfect if i do not do an orderclose!!!!!!!! Meaning if i change the function to simply print the magic number at "part 1" everything works and the magic numbers are only printed once.

Problem lies when the orderclose happens........

Hopefully someone with more brains than me can put this right for me.

 
Where does CloseLot come from ? are you doing a partial close ? if not why not use OrderLots() ?
 
RaptorUK:
Where does CloseLot come from ? are you doing a partial close ? if not why not use OrderLots() ?


YEA ITS PARTIAL CLOSE! Please focus on the problem i am trying to resolve. the ea closes partail close of the trade once and writes the magic to a file. The file is then read and if the macic number exists in the file the function should be unable to close partial profit a second time. My probelm is that its closing partial profit over and over.

 
Have a read of this thread: https://www.mql5.com/en/forum/122462
Reason: