Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Objektorientierung unter MQL4 Build600 (http://www.expert-advisor.com/forum/showthread.php?t=3730)

Hosch 26.06.14 14:35

Objektorientierung unter MQL4 Build600
 
Hoi zäme,

ich habe eine Klasse in MQL4 geschrieben und möchte das in einem EA nutzen, aber irgendwie klappt das nicht. D.h. obwohl ich in der Init-Methode eine Private Variable mit true setze, ist diese Variable in der OnTick-Methode immer Default-mässig false(Strategytester)?Ich habe das Objekt der Klasse als globale Variable definiert. Was mache ich falsch?


Hier ein exemplarisches Beispiels meines Codes:
PHP-Code:

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;





Hier der EA, wo ich die Klasse verwende:
PHP-Code:

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

//|                                              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()

  {

//---

   

   
//Hier ist die private Variable m_tradeFirst = true;
   
cTrendLong.setFirstTrade(true);

//---

   
return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

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

//| Expert tick function                                             |

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

void OnTick()

  {
// Hier ist beim Abruf der Variable der Parameter immer false?
//What is wrong?
if( cTrendLong.getFirstTrade() == true )

{
/// Buy Sell etc...
}


Dank Vielmal für eure Hilfe,
Hosch


Alle Zeitangaben in WEZ +2. Es ist jetzt 01:45 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum