Object Oriented Programm under MT4

 

Hi,

 I wrote a Class and a Expert Advisor. But now I have following problem regarding calling an object of a class with private variable:

For instance:

My Class 

class CTrendTraderLong

 {

private:

bool m_tradeFirst;

 

 

public:

 CTrendTraderLong();

 ~CTrendTraderLong();

void setFirstTrade(bool trade);

 bool getFirstTrade(); 

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

//| |

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

CTrendTraderLong::CTrendTraderLong()

 {





 }

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

//| |

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

CTrendTraderLong::~CTrendTraderLong()

 {



 }

void CTrendTraderLong::setFirstTrade(bool Trade )

{

m_tradeFirst = Trade;

}

 

bool CTrendTraderLong::getFirstTrade(void)

{

return m_tradeFirst;

} 

}

 The Expert Advisor

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

//|                                              TrendTrader.mq4 |

//|                        Copyright 2014, MetaQuotes Software Corp. |

//|                                              http://www.mql4.com |

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

#property copyright "Copyright 2014, "

#property link      "http://www.mql4.com"

#property version   "1.00"

#property strict
#include <TrendTraderLong.mqh>

input int MagicNumber = 12342;

input double Lot = 0.01;

CTrendTraderLong cTrendLong;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   

   
//Here I set the member_variable m_tradeFirst = true;
   cTrendLong.setFirstTrade(true);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }
//+------------------------------------------------------------------+

//| Expert tick function                                             |

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

void OnTick()

  {
// This will never called, but the member_variable was set to true in the Init-Method.
//What is wrong?
if( cTrendLong.getFirstTrade() == true )

{
/// Buy Sell etc...
}
}

Can you explain me, how I have to define the object of the class. Should I make a dnamical object with pointer? Because the member variable m_tradeFirst is on the OnTick method always false and not true. But it should be true because I set it on the init-Method.

 

Thanks for your help,

Hosch 

 
Check your real code. What you posted here is correct.
Reason: