Color of closed trade lines - can they be changed from red/blue to something else? - page 2

 
RaptorUK:
I'm a little confused . . . you should be processing the Objects based on the OrderHistory not the Object list . . . I said "Keep track of the last order that you changed the colour of the line for " not the Object.

How could I retrieve the OrderHistory? I don't find this in the Trading functions. I can only find OrderHistoryTotal().

 
RaptorUK:
I'm a little confused . . . you should be processing the Objects based on the OrderHistory not the Object list . . . I said "Keep track of the last order that you changed the colour of the line for " not the Object.
Oh, do you mean by iterating through OrderSelect(i, SELECT_BY_POS, MODE_HISTORY ) ??
 
lingwuchung:
Oh, do you mean by iterating through OrderSelect(i, SELECT_BY_POS, MODE_HISTORY ) ??
Of course . . .
 

Raptor, thanks very much. I've done it.

static int lastCompletedObj=0;              // define this global var somewhere
static string lastCompletedOrder="0";       // define this global var somewhere

int drawTrendLines() {

   int i=0, trendlineNumber=0;
   color originalColor;
   double price1=0;
   double price2=0;
   string desc="";
   
   if (!OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY)) {
      return(0);
   }
   
   if (OrderTicket() > StrToInteger(lastCompletedOrder)) {     // new completed order arrived
         
      // !!!!!!!!!!! can only do one order, if two orders completed within the same tick, the 2nd order will need to be done in the next tick??????????
   
      for(i=ObjectsTotal()-1; i>=0; i--){

         string obj= ObjectName(i);

         if(StringSubstr(obj,0,StringLen(""+(StrToInteger(lastCompletedOrder)+1))+2) != "#"+(StrToInteger(lastCompletedOrder)+1)+" ")
            continue;   // not the completed order number

         // the complter order number is found      
         if(ObjectType(obj) == OBJ_TREND) {

            originalColor = ObjectGet(obj, OBJPROP_COLOR);
            price1 = ObjectGet(obj, OBJPROP_PRICE1);
            price2 = ObjectGet(obj, OBJPROP_PRICE2);      
            desc = ObjectDescription(obj);
            
            if (desc == "") {                 // first time setting this trendline
               if (originalColor == Blue) {     // buy
                  if (price2 >= price1) {
                     ObjectSet(obj,OBJPROP_COLOR,Lime);
                     ObjectSetText(obj, "Win");
                  } else {
                     ObjectSet(obj,OBJPROP_COLOR,Red);
                     ObjectSetText(obj, "Loss");
                  }
               } else if (originalColor == Red) {  // sell
                  if (price2 <= price1) {
                     ObjectSet(obj,OBJPROP_COLOR,Lime);
                     ObjectSetText(obj, "Win");
                  } else {
                     ObjectSet(obj,OBJPROP_COLOR,Red);      
                     ObjectSetText(obj, "Loss");
                  }
               }         
            }
   
            lastCompletedOrder = "" + (StrToInteger(lastCompletedOrder)+1);   
            break;
         }
                
      }  
   }

}
 
RaptorUK:
I'm a little confused . . . you should be processing the Objects based on the OrderHistory not the Object list . . . I said "Keep track of the last order that you changed the colour of the line for " not the Object.

Win lol


White is much better

 

I know this is a really old thread, but I am trying to do the same as the OP.  I have almost no coding experience at all, but am starting to learn the basics for MT4.  I have attempted to copy and complile the above into a script which generated the following errors.  If someone could help me that would be really appreciated.


'BackTestingColours.mqproj' BackTestingColours.mqproj 1 1

'BackTestingColours.mq4' BackTestingColours.mq4 1 1

'drawTrendLines' - function declarations are allowed on global, namespace or class scope only BackTestingColours.mq4 16 5

'lastCompletedOrder' - undeclared identifier BackTestingColours.mq4 28 37

implicit conversion from 'number' to 'string' BackTestingColours.mq4 28 37

implicit conversion from 'number' to 'string' BackTestingColours.mq4 36 59

implicit conversion from 'number' to 'string' BackTestingColours.mq4 36 78

implicit conversion from 'number' to 'string' BackTestingColours.mq4 36 107

implicit conversion from 'number' to 'string' BackTestingColours.mq4 36 126

possible loss of data due to type conversion BackTestingColours.mq4 42 27

implicit conversion from 'number' to 'string' BackTestingColours.mq4 67 53

implicit conversion from 'number' to 'string' BackTestingColours.mq4 67 72

implicit conversion from 'string' to 'number' BackTestingColours.mq4 67 37

'}' - not all control paths return a value BackTestingColours.mq4 74 1

3 errors, 9 warnings 4 10