Download MetaTrader 5

Draw ARROW on open trade (manual trade open)

To add comments, please log in or register
Do you often publish source codes? Find out how to do that correctly!
rg144
47
rg144 2016.01.13 08:21 

Hi guys,

I am a beginner so please excuse my lack of coding skills!

First- I have created an EA to CLOSE all positions using a button on the chart (close all trades button)

In this same EA I also want it to draw arrows on the chart when I open new positions manually.
So I am trying to add an arrow on the chart next to where a position is opened (when opening manually via MT4's Order Window or the built-in Once-Click trading buttons on the chart)

Something wrong with my code but I don't know what it is, arrows do not appear when I open trades. 

 

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {  
  
   bool test;

   for (int i=0; i < OrdersTotal(); i++) 
   {
      
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         
         if (OrderSymbol() == Symbol()) 
         {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) 
               {     
                  ObjectCreate(1, "OrderArrow",OBJ_ARROW, 0, OrderOpenTime(), OrderOpenPrice());
                  ObjectSet(1, OBJPROP_ARROWCODE, 1);
                  ObjectSet(1, OBJPROP_COLOR, Red);
                  ObjectSetText(1, "BUY");
               }
         }
   }
}

 

Am I doing this right? Appreciate any help! 

Marco vd Heijden
Moderator
4700
Marco vd Heijden 2016.01.13 08:36  
rg144:

Hi guys,

I am a beginner so please excuse my lack of coding skills!

First- I have created an EA to CLOSE all positions using a button on the chart (close all trades button)

In this same EA I also want it to draw arrows on the chart when I open new positions manually.
So I am trying to add an arrow on the chart next to where a position is opened (when opening manually via MT4's Order Window or the built-in Once-Click trading buttons on the chart)

Something wrong with my code but I don't know what it is, arrows do not appear when I open trades. 

 

 

Am I doing this right? Appreciate any help! 

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {  
  
   bool test;

   for (int i=0; i < OrdersTotal(); i++) 
   {
      
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         
         if (OrderSymbol() == Symbol()) 
         {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) 
               {     
                  ObjectCreate(0, "OrderArrow",OBJ_ARROW, 0, OrderOpenTime(), OrderOpenPrice());
                  ObjectSet(0, OBJPROP_ARROWCODE, 1);
                  ObjectSet(0, OBJPROP_COLOR, Red);
                  ObjectSetText(0, "BUY");
               }
         }
   }
}
rg144
47
rg144 2016.01.13 08:46  
Marco vd Heijden:

thanks so much Marco. changed to 0.
Out of curiosity- may I ask why I have to use 0 and cannot use 1?

I also created a string variable (i.e "name") and that worked too, but dont understand why 1 didnt work

Marco vd Heijden
Moderator
4700
Marco vd Heijden 2016.01.13 08:52  
rg144:

thanks so much Marco. changed to 0.
Out of curiosity- may I ask why I have to use 0 and cannot use 1?

I also created a string variable (i.e "name") and that worked too, but dont understand why 1 didnt work


chart_id

[in]  Chart identifier.

 0 means the main chart window.

if you have another chart open with ID=1 then the object should show up on that chart..

rg144
47
rg144 2016.01.13 09:04  
Brilliant. thanks so much !
To add comments, please log in or register