Trade Management - page 3

 

OK, I'll do an other test. With pleasure.

Just that we speak the same language, I copy the sequence of the code here. If something doesn't add up for you, please let me know.


I removed NormalizeDouble for OrderOpenPrice_TM and OrderStopLoss_TM

//================================================================
// Loop to find Pending Orders and Open Positions
//================================================================   

for(int OrderPosition = OrdersTotal()-1; OrderPosition >= 0; OrderPosition--) 
   {
   if (OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES) == false)
       { 
             Alert(Symbol(),"  OrderSelect Error, value FALSE returned");
             
             Error_text_A = "  OrderSelect  ";
             Error_trade_mgmt();
       
       }else       
       {
            
            
     
//----------------------------------------------------------------
// Filter criteria
//----------------------------------------------------------------
               if(OrderSymbol()!=Symbol()) continue;
               
               OrderType_TM = OrderType();
               OrderOpenPrice_TM = OrderOpenPrice();
               OrderStopLoss_TM = OrderStopLoss();
               OrderTakeProfit_TM = OrderTakeProfit();
               OrderTicket_TM = OrderTicket();
               
//----------------------------------------------------------------
// Related to the Error code 1, I will round manually the
// following fields
//----------------------------------------------------------------               
//               NormalizeDouble(OrderOpenPrice_TM,4);
//               NormalizeDouble(OrderStopLoss_TM,4);
               NormalizeDouble(OrderTakeProfit_TM,4);
 

Flat function:

//****************************************************************
// Raptors flat function, replaces NormalizeDouble
//****************************************************************
int Flat(double ValueToFlatten)
   {
    int Power = MathPow(10, Digits);
   
    return(MathFloor(Power * (ValueToFlatten + (1/(Power*10)))) );
   }


If-statement for initial Stop Loss move to Break even

If OrderOpenPrize = OrderStopLoss, this If-statement should not be executed again.


//================================================================
// General and main routine for Stop Loss move
//================================================================

//----------------------------------------------------------------
// BUY Position
//----------------------------------------------------------------


               if(OrderType_TM == 0 && Flat(OrderStopLoss_TM) < Flat(OrderOpenPrice_TM) ) 
//               if(OrderType_TM == 0 && OrderStopLoss_TM < OrderOpenPrice_TM)
                 {
Alert("  OrderType_TM  "+OrderType_TM,"  OrderStopLoss_TM  "+OrderStopLoss_TM,"  OrderOpenPrice_TM  "+OrderOpenPrice_TM);
                              
                  Move_stop = OrderOpenPrice_TM + Break_even_pips;                     // Calculate Price limit to move Stop

                  .......
 

Just performed the test.

No problems using the Tester. The results are as desired and expected.

What is missing, is the results in a demo environment and subsequntly in Live.

At the first glance Raptor it's looking good...... Well donne.

If you like, have a look at the log:

2012.01.07 17:34:06     2012.01.04 23:59  Sun V.Test EURUSD,H1: EURUSD   H1    FTM trading monitor STOPED
2012.01.07 17:34:05     2012.01.03 21:15  Tester: stop loss #1 at 1.30562 (1.30561 / 1.30581)
2012.01.07 17:34:05     2012.01.03 20:57  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   20:00:00  Global Variable free for trading            810 ATR-SL  TL 2
2012.01.07 17:34:05     2012.01.03 20:57  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   20:00:00  Order  1 ATR Trailing Stop moved OK
2012.01.07 17:34:05     2012.01.03 20:57  Sun V.Test EURUSD,H1: modify #1 buy 2.81 EURUSD at 1.30380 sl: 1.30562 tp: 0.00000 ok
2012.01.07 17:34:05     2012.01.03 20:57  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   20:00:00  Modification 1. ATR Trailing Stop, Awaiting response..
2012.01.07 17:34:05     2012.01.03 17:16  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   17:00:00  Global Variable free for trading            180 SL  TL 2
2012.01.07 17:34:05     2012.01.03 17:16  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   17:00:00  Order  1 Stop Loss moved to Break Even
2012.01.07 17:34:05     2012.01.03 17:16  Sun V.Test EURUSD,H1: modify #1 buy 2.81 EURUSD at 1.30380 sl: 1.30380 tp: 0.00000 ok
2012.01.07 17:34:05     2012.01.03 17:16  Sun V.Test EURUSD,H1: Alert: EURUSD  H1   17:00:00  Modification 1. SL Move, Awaiting response..

2012.01.07 17:34:05     2012.01.03 17:16  Sun V.Test EURUSD,H1: Alert:   OrderType_TM  0  OrderStopLoss_TM  1.30200000  OrderOpenPrice_TM  1.30380000

Thanks.