Help with passing a struct as a param to constructor.

 
/+------------------------------------------------------------------+
//|                                                     buyOrder.mq4 |
//|                                                       David_kdcp |
//|                                                  falavaspace.com |
//+------------------------------------------------------------------+
class Order{

//order_param sis a struct
public:
    Order(struct *params) {
      string symbol = params.symbol;                // symbol
      double market_entry = params.market_entry;    // price
      double stop_loss_pips = params.loss_pips;     // stop loss
      double take_profit_pips = params.profit_pips; // take profit
      string   comment=NULL;                        // comment
      int      magic=0;                             // magic number
      datetime expiration=0;                        // pending order expiration
    };
};

//+------------------------------------------------------------------+


class BuyOrder : public Order {

  private:
    double LOTS =1.0;     // volume a.k.a lots
    int    SLIPPAGE = 3;       // slippage
    color  ARROW_COLOR = Yellow;   // color

    double orderStoploss(double market_entry, double pips_loss){
      return market_entry - (pips_loss * Point)
    }

    double orderTakeProfit(double market_entry, double pips_in_profit){
      return market_entry + (pips_in_profit * Point)
    }

  protected:
    int execute(void) {
      return OrderSend(
        this.symbol,
        OP_BUY,
        this.lots,
        this.market_entry,
        OrderStoploss(this.price, this.stoploss)
        OrderTakeprofit(this.price, this.takeprofit)
        SLIPAGE,
        this.comment,
        this.experiration,
        ARROW_COLOR
      );
    }
};// BuyOrder


Hi Guys/Girls

Wasn't sure where to post this. I need some help with trying to pass a struct to a constructor.

Passing each individual param is tedious and not very maintainable. 

So I want to pass a key value pair object to the constructor. Unfortunately I am getting - struct cannot be defined in param list. I am a total n00b at C and this is my first MetaQuotes4 programme(EA) attempt. I have Googled and trawled the docs. Can't find a thing besides the docs saying that passing classes, arrays and structs can only be done using pass by reference.

The issue is line 10. 

I also attached the full file - it's loaded with compile errors - due to this being a WIP.  The rest of the errors I can handle but the struct not allowed in params issue has be baffled. Any help or advice would be awesome. 

Thanks in advance.



Files:
buy.mqh  3 kb
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. This is babel. You define parameters as TYPE [&] NAME; struct is not a type.
    Order(struct & params){ ...
    Try
    struct values{ int i; double d; };
    :
    Order(values& params){ ... params.i ...
 
ah I see!  This is a great help. thanks.
 

hey,

just to clear some things up; what you are after is not about C but about C++. C has not classes or objects so maybe it is a reason why you are not finding anything usefull while searching on the internet

 

best regards 

Reason: