Draw ARROW on open trade (manual trade open)

 

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! 

 
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");
               }
         }
   }
}
 
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

 
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..

 
Brilliant. thanks so much !