void OnChartEvent

Back to topics list To post a new topic, please log in or register
avatar
6
pete_36 2015.10.26 21:53
 

Hi,


I am working building an EA where it will create 4 buttons for each pair (7 pairs in total), BUY PAIR, SELL PAIR, BUY ALL, SELL ALL.

Everything is working fine and the screen design is complete. I got to assigning functions to the buttons and Ive written the below code. All is working well but for only the pair which the EA is attached to. So say I attach the EA to EURUSD chart and I press the BUY PAIR button, it will open a long position for this pair but nothing happens when I press the buy button for the other pairs, though the EA is reading all the button denomination correctly and all the other variables as well but the buy order is not being sent. Where, if I attach the EA to GBPUSD chart, the orders will be sent... but only for this pair and not the others.


What am I doing wrong here? oh and the last line to depress the button ObjectSetInteger(0,obj, OBJPROP_BACK, false); is not executing. Is this line correct?

string sym[]={"EURUSD", "GBPUSD", "USDJPY", "USDCHF", "NZDUSD", "AUDUSD", "USDCAD"}; here are the symbol strings that I am using.


I really appreciate any help.


 - pete

/+------------------------------------------------------------------+
//| ChartEvent function                                                       |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---BUY PAIR Button
   int r=0;
   string obj;
  
   for(r=0; r<=6; r++)
      {
      obj=sym[r]+DoubleToStr((r+4),0);
      if(sparam==obj)
         {
         ticket=OrderSend(sym[r], OP_BUY, lots, Ask, slip, 0, 0, NULL, 0, 0, clrDarkBlue);
         ObjectSetInteger(0,obj, OBJPROP_BACK, false);
         }
      }
  }
avatar
Moderator
3427
GumRai 2015.10.26 22:59 #
 

You don't check and set a button with OBJPROP_BACK, use OBJPROP_STATE.

I don't see any check that the button has been pressed 

Ask is the price of the chart symbol, so you will be unable to use it to in OrderSend for other pairs 

avatar
6
pete_36 2015.10.27 07:49 #
 
GumRai:

You don't check and set a button with OBJPROP_BACK, use OBJPROP_STATE.

I don't see any check that the button has been pressed 

Ask is the price of the chart symbol, so you will be unable to use it to in OrderSend for other pairs 

Thanks GunRai. I will try and fix it when I get home this evening. Of course, I should have used the OBJPROP_STATE instead - thank you.

I will amend the OrderSend to read the Ask of the specific pair. For checking if the button has been pressed, I am using inside the for loop the if statement to check for whether sparam=the button denomination and execute the BUY. Should it be represented otherwise or this just fine? the code is executing the BUY order for the current pair. I think it is the ASK problem.

 

By amending the ASK and the button state, I think I should be OK... unless I am still missing anything.

 

Once again, thank you for your help. 

Back to topics list  

To add comments, please log in or register