Checking Order Satus/State

 
Hello all,

I'm want to monitor an order in a way so I can know when it changes from pending to open and from open to closed. I don't use price to check this because I must have sure that the order was hit, so I use ticket number (Fractal_Buy[4] has the ticket number).

if (OrderSelect(Fractal_Buy[4], SELECT_BY_TICKET) == true) { if (OrderType() == OP_BUY && OrderCloseTime() == 0) { Alert("Fractal Buy Hit - ", Fractal_Buy[4], " - ", OrderComment()); } else if (OrderType() == OP_BUYSTOP && OrderCloseTime() == 0) { Alert("Fractal Buy Not Hit - ", Fractal_Buy[4], " - ", OrderComment()); } else if (OrderCloseTime() > 0) { Alert("Fractal Buy Closed - ", Fractal_Buy[4], " - ", OrderComment()); } } else { Alert("No Fractal Buy Yet"); }


My questions are:
1 - Is there a more simple or easy way to do this?
2- Does MQL have something like events? So when a position is open or hit by SL we can check?

Thank you. Cleon
 
What I have done in the past was to have the order numbers on the screen along with a bullet. The color of the order nume and the bullet lets me know what the status of the order is. In the code be low if the order number is white and the bullet is white as well the order is active but not triggered (pending), white numers are active orders gray numbers are closed orders. the color of the bullets are green in profit red at a loss yellow is at even profits. dark green or dark yellow stoploss is at break even with a profit or zero profits. when the numbers are gray the orders are inactive and the bullet color shows if the orders are closed at profit at a loss or at break even. This may sound complicated but will show some screen shots.

I also have develop a way to have the screen information rotate with different information on an ongoing bases. In this case there are 6 different screens runtime screens and two debuging screens. some of the screen info was still under construction when this shot was taken. the two booms at current bar are trailing stops.


//«« <<<< Segment 930 >>>> »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» // Changes display colors in real time with changes in positons. for( Index = One; Index <= Four; Index = Index + One ) { // DB!{change to One}: Record = Order[ Index ]; if( Record == Empty ) continue; NumberColor = WhiteSmoke; BulletColor = WhiteSmoke; if( OrderSelect( Record, SELECT_BY_TICKET, MODE_TRADES ) == True ) { if( OrderType() == BuyLong || OrderType() == SellShort ) { if( OrderProfit() < Zero ) { BulletColor = Red; } else if( OrderProfit() > Zero ) { BulletColor = Lime; if( OrderStopLoss ()== OrderOpenPrice() ) BulletColor = MediumSeaGreen; } else if( OrderProfit() == Zero ) { BulletColor = Yellow; if( OrderStopLoss() == OrderOpenPrice() ) BulletColor = Goldenrod; } // End If, OrderProfit: } // End If, OrderType: if( OrderCloseTime() != Empty ) { NumberColor = LightSlateGray; if( OrderClosePrice() != OrderOpenPrice() && OrderProfit() == Zero ) { BulletColor = LightSlateGray; } // End If, OrderClosePrice: } // End If, OrderCloseTime: } else { // RD!{Install ErrorHanler}: Print( "An error occurred in processing trade records in Segment 930" ); } // End If, OrderSelect: PlaceRange = Time[ Zero ] + ( Three * hour ); if( PlaceRange > TradeQuitingTime + ( Three * hour )) { PlaceRange = TradeQuitingTime + ( Three * hour ); } // End If, PlaceRange: UpDateGraphics( Index, Record ); } // End For Loop, Record:
Files:
 
Hi CockeyedCowboy,

Thank you. Your code gave me the confirmation I needed about this topic. That rotating information is a very good way to keep important data without filling all screen. Very nice idea. Thank you.

Regards,
Cleon
 
cleon

This is some code that alternates the out put between different screens, you will have to convert it for your needs. This has seven screens to rotate through and if you trow a switch at the begining of the EA (not shown) it will show debuging screen information as well. The debuging screens are useful for when your writing the the oringinal code. It is turned off but not removed as it will be needed to make future changes and up dates to the code. The first code block is the rotating engine.

//«« LABEL 900 »» GRAPH DISPLAY AND COMMENTARY: »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» //«« <<<< Segment 910 >>>> »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» // Display Graph's title and screen information selected. TitleLine = StringConcatenate( FillerLine( Eight ),Author, FillerLine( Sixteen, Dot ), ProducedFor, NewLine, FillerLine( ThirtyTwo ), eMail ); BiLine = StringConcatenate( SkipLine, FillerLine( Ten ), LicenseTo, NewLine, "System\'s RunTime ", "Serial Number", FillerLine( Six ), SystemIdentity ); switch( Alternate( ScreenInformation, Seven ) ){ case Zero: ExposeScreen( TitleLine, BiLine ); break; case One: ExposeScreen( TitleLine, BiLine, RunTimeInfo() ); break; case Two: ExposeScreen( TitleLine, BiLine, TimeSchedulePageOne() ); break; case Three: ExposeScreen( TitleLine, BiLine, TimeSchedulePageTwo() ); break; case Four: ExposeScreen( TitleLine, BiLine, SystemTradeInfo() ); break; case Five: ExposeScreen( TitleLine, BiLine, FinancialTracking() ); break; case Six: ExposeScreen( TitleLine, BiLine, TrailingStopInfo() ); break; case Seven: ExposeScreen( TitleLine, BiLine, SystemPerformance() ); break; default: ExposeScreen( TitleLine ); break; } // End Switch, Alternate:




The next two code blocks are the functions that displays two of the seven sceens, these are the two displaying time information.


//«« <<<< Time Schedule Page One Screen, Function >>>> »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» string TimeSchedulePageOne() { return( StringConcatenate( SkipLine + "Current System Times Values", NewLine + Tab + "Dealer Time ... " + TimeToStr( CurTime(), TIME_MINUTES ), NewLine + Tab + "GMT Time ..... " + TimeToStr( CurrentGMTime, TIME_MINUTES ), NewLine + Tab + "Local Time ..... " + TimeToStr( TradersLocalTime, TIME_MINUTES ), SkipLine + "System Scheduled Ending Time", NewLine + Tab + "System Quiting Time ... " + TimeToStr( OrderExpires, TIME_MINUTES ), Tab + "( Broker )", NewLine + Tab + "Pending Orders Expire .. " + TimeToStr( OrderExpires, TIME_MINUTES ), Tab + "( Broker )", NewLine + Tab + "System Ending Time .... " + TimeToStr( TradeQuitingTime, TIME_MINUTES ), Tab + "( GMT )", NewLine + Tab + "Local Ending Time ........ " + TimeToStr( LocalQuitingTime, TIME_MINUTES ), Tab + "( Local )", SkipLine + "Miscellaneous System Time Information", NewLine + Tab + "Dealer OffSet to GMT", Tab + "[ " + ( DealerTimeOffSet / hour ) + " hours ]", NewLine + Tab + "Local OffSet to GMT ", Tab + "[ " + ( LocalTimeOffSet / hour ) + " hours ]", NewLine + Tab + "System Started Up ", Tab + "[ " + SystemStartTime + " ] ( Local )" )); // End return string: } // End Function, TimeSchedulePageOne:


and the second time screen;


//«« <<<< Time Schedule Screen Page Two, Function >>>> »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» string TimeSchedulePageTwo() { return( StringConcatenate( SkipLine + "The Asian Market Session Start Time", NewLine + Tab + "Order Entry .... " + "00:00", // RD!{variable not defind, code stub}: Tab + "( Broker )", NewLine + Tab + "Data Input ...... " + "00:00", // RD!{variable not defind, code stub}: Tab + "( GMT )", NewLine + Tab + "Local Start ...... " + "00:00", // RD!{variable not defind, code stub}: Tab + "( Local ) ", SkipLine + "The Europe Market Session Start Time", NewLine + Tab + "Order Entry .... " + TimeToStr( OrderTimeSession1, TIME_MINUTES ), Tab + "( Broker )", NewLine + Tab + "Data Input ...... " + TradeTimeSession1, Tab + "( GMT )", NewLine + Tab + "Local Start ...... " + TimeToStr( LocalTimeSession1, TIME_MINUTES ), Tab + "( Local ) ", SkipLine + "The US Market Session Start Time", NewLine + Tab + "Order Entry .... " + TimeToStr( OrderTimeSession2, TIME_MINUTES ), Tab + "( Broker )", NewLine + Tab + "Data Input ...... " + TradeTimeSession2, Tab + "( GMT )", NewLine + Tab + "Local Start ...... " + TimeToStr( LocalTimeSession2, TIME_MINUTES ), Tab + "( Local )", )); // End return string: } // End Function, TimeSchedulePageTwo:



Hope this will give you some idears for your own work.


The CockeyedCowboy
Reason: