Can someone please tell me what i am doing wrong in this loop.
The loop works only when i have one trade open. ???? But does not do what i think should happen when more than one trades are open.?
OMG. That is the most unreadable code I have ever seen. Your indenting is all over the place.
You need to test if the OrderSelect() worked.
I would format it more like this ...
bool Use_TP1; string stp2; int Neworder_b[2000]; void Function2_b(){ if( Use_TP1==false ) return; bool tp1_allowed= true; for( int i = OrdersTotal()-1; i >= 0 ; i-- ){ if( !OrderSelect(i,SELECT_BY_POS) ) continue; int MAGIC2 = OrderMagicNumber(); // WTF? You just set MAGIC2 equal to OrderMagicNumber() so why are you testing it? if( OrderMagicNumber() == MAGIC2 ){ if( OrderSymbol()==Symbol() ){ if( OrderType()==OP_SELL ){ double stoplevel = (MarketInfo(Symbol(),MODE_STOPLEVEL)*Point); double stp2x = ObjectGet(stp2, OBJPROP_PRICE1); double CloseLot = 0.1; int handleA=FileOpen("neworders.dat_b", FILE_BIN|FILE_READ); if( handleA>0 ){ int gA=FileReadArray(handleA,Neworder_b,0,1000); FileClose(handleA); } Print(Neworder_b[i]); if( Neworder_b[i]==OrderMagicNumber() ){ tp1_allowed= false; } if( (tp1_allowed==true) && MarketInfo(OrderSymbol(),MODE_ASK)<=stp2x ){ // stuff to do } } } } } }
OMG. That is the most unreadable code I have ever seen. Your indenting is all over the place.
You need to test if the OrderSelect() worked.
. . . and this is pointless . . .
MAGIC2 = OrderMagicNumber(); if (OrderMagicNumber() == MAGIC2)
Can someone please tell me what i am doing wrong in this loop.
The loop works only when i have one trade open. ???? But does not do what i think should happen when more than one trades are open.?
The weird part is where you read an array from a file and then use the SAME INDEX as from the main loop. It is highly unlikely that these will line up if any orders have been changed since the file was written.
int handleA=FileOpen("neworders.dat_b", FILE_BIN|FILE_READ); if( handleA>0 ){ int gA=FileReadArray(handleA,Neworder_b,0,1000); FileClose(handleA); } Print(Neworder_b[i]); if( Neworder_b[i]==OrderMagicNumber() ){ tp1_allowed= false; } if( (tp1_allowed==true) && MarketInfo(OrderSymbol(),MODE_ASK)<=stp2x ){ // stuff to do
Ok, i removed the magic number and tidied up the code as per your example. Still not working.
The magic numbers are all writting to the file, so that part is working!
And so the magic numbers are in the file AND the file is compared to the current magic number(s) going through the loop. (which are the same numbers which are in the file)
THEN why is tp1_allowed comming back as true????????????
Maybe you might know what i should be doing here? thanks.
Ok, i removed the magic number and tidied up the code as per your example. Still not working.
The magic numbers are all writting to the file, so that part is working!
And so the magic numbers are in the file AND the file is compared to the current magic number(s) going through the loop. (which are the same numbers which are in the file)
THEN why is tp1_allowed comming back as true????????????
Maybe you might know what i should be doing here? thanks.
Any helpers in here?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can someone please tell me what i am doing wrong in this loop.
The loop works only when i have one trade open. ???? But does not do what i think should happen when more than one trades are open.?