Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 12.01.21
MA-EA MA-EA ist offline
Elite Mitglied
 
Registriert seit: Sep 2015
Beiträge: 1.178
MA-EA befindet sich auf einem aufstrebenden Ast
Standard Custom Indicator EA

Hallo.

Probiere seit einiger Zeit einen EA mit 3 (zum Teil ) selbst gemachten Indikatoren. Der hat bisher immer nur Buy-Orders geöffnet, obwohl es doch eigentlich wenigstens ein paar Chancen für Sell-Orders geben müsste. Hab den Code immer wieder durch geguckt und hab keine Ahnung, warum er nicht auch Sell-Orders öffnet. Fehlermeldungen oder Warnungen gibts Keine. Weder beim Kompilieren noch im MT4.

Im Anhang der EA und die 3 Indis. Braucht man nur in den Indikator-Ordner kopieren/speichern und Kompilieren. Dass der EA in den EA-Ordner kompiliert werden muss, brauch ich wohl nicht extra erklären.
Code:
Eigene Indikatoren:

-OnePrice

-Price+MAd2

-First MA+MAd2

-Second MA+MAd2

//-------------------------------------------------------------------------------------------------------------

//=============================================================================================================
// P R O P E R T Y
//============================================================================================================*/
// #property strict
// #property strict sorgt anscheinend dafür,
// dass Kommentare im Konfig-Fenster im MT4 sichtbar sind.
#property copyright"EIMT4EA_oPRPpMd2MpMd2.mq4"
#property copyright"daniel-rudloff@web.de"
//=============================================================================================================
// B E S C H R E I B U N G
//=============================================================================================================
extern string esTOY="true  = on / yes";
extern string esFON="false = off / no";

extern string esB01="Send Sell/Buy if:";
extern string esB02="first_OnePr";
extern string esB03=">=/<=";
extern string esB04="PRpMAd2_Price";
extern string esB05=">=/<=";
extern string esB06="first MAplMAd2";
extern string esB07=">=/<=";
extern string esB08="secon MAplMAd2";
//=============================================================================================================
// E I N S T E L L U N G E N
//=============================================================================================================
extern string esOOT="Open Orders";
input bool open_Sel=true;
input bool open_Buy=true;
//-----------------------------------------------------------------------------------------------------------*/
extern string esMN="Magic Numbers";
extern int MN_Sel=12;
extern int MN_Buy=34;
//-----------------------------------------------------------------------------------------------------------*/
extern string OOO1="Open Orders";
extern string OOO2="from/till";
extern string OOO3="(Server Time)";
extern int FromH=5; // Zum Testen ab 5 Uhr öffnen
extern int TillH=15;
//-----------------------------------------------------------------------------------------------------------*/
extern string CAOTOC1="Close all Orders at";
extern string CAOTOC2="(Server Time)";
extern bool CAOA=true;
extern int CloseH=17;
//-----------------------------------------------------------------------------------------------------------*/
extern int Slippage=12345; // ?
//-----------------------------------------------------------------------------------------------------------*/
extern string esIITCBSMS1="if IsTradeContexBusy";
extern string esIITCBSMS2="sleep Milli Seconds";
extern int Sl_MS=16;
//-----------------------------------------------------------------------------------------------------------*/
extern string esMS="Max Spread";
extern int Max_Spr=65; // Zum Testen 65
//-----------------------------------------------------------------------------------------------------------*/
extern int SL=175; // 175 testen
//-----------------------------------------------------------------------------------------------------------*/
// Bei ActivTrades müssen SL/TP anscheinend mindestens 5 sein
extern string esTS="Trailing Stop !VIELLEICHT ERROR DRIN!"; 
input bool TrailingStop=true;  // Zum Testen ein.
extern int TrailingStopStep=25; // Zum Testen 25. Bei TSS 6 wurden gar keine Orders geöffnet.
//-----------------------------------------------------------------------------------------------------------*/
extern int TP=2000; // Zum Testen 2000
//-----------------------------------------------------------------------------------------------------------*/
extern double Lots=0.01;
//-----------------------------------------------------------------------------------------------------------*/
extern string ALSZ="Auto Lotsize !ERROR!";
extern bool Percent_of_Balance=false; // Zum Testen aus. Berechnung ist falsch!
extern double Auto_Lotsize_Perc=0.32; // Zum Testen 0,32%
//-----------------------------------------------------------------------------------------------------------*/
extern string esTF="TimeFrame";
input ENUM_TIMEFRAMES TF=15;// Zum Testen M15
//-----------------------------------------------------------------------------------------------------------*/
// Distance Ask/Bid zu OpenPrice0
extern string esDABOP1="Distance Ask/Bid";
extern string esDABOP2="to";
extern string esDABOP3="OpenPrice Bar0";
extern int DistOP=15;// 15 zum Testen
//=============================================================================================================
// G L O B A L E   E I N S T E L L U N G E N   E I G E N E   I N D I

// P R I C E
//=============================================================================================================
extern string esEAP="EA Price One"; // Vielleicht später mehrere Preise nutzen.
input ENUM_APPLIED_PRICE first_OnePr=PRICE_CLOSE;
//=============================================================================================================
// G L O B A L E   E I N S T E L L U N G E N   E I G E N E   I N D I

// ( P R I C E + M A ) D 2
//=============================================================================================================

extern string esPpM21="PRpMAd2_CHA";
extern string esPpM22="( Price...";

input ENUM_APPLIED_PRICE PRpMAd2_Price=PRICE_CLOSE;

extern string esPpM2MA="... + Moving Average ) / 2";

extern int               PRpMAd2_MA_Period=2; // Periode scheint egal zu sein...
input ENUM_MA_METHOD     PRpMAd2_MA_Method=MODE_SMA;
input ENUM_APPLIED_PRICE PRpMAd2_MA_Price =PRICE_CLOSE;

//=============================================================================================================
// G L O B A L E   E I N S T E L L U N G E N   E I G E N E   I N D I

// M A p l MA d 2
//=============================================================================================================

extern string esMpMd2o="first MAplMAd2_CHA";

extern int               fiMpMd2_onePeriod=3;
input ENUM_MA_METHOD     fiMpMd2_oneMethod=MODE_SMA;
input ENUM_APPLIED_PRICE fiMpMd2_onePrice =PRICE_CLOSE;

extern int               fiMpMd2_twoPeriod=6;
input ENUM_MA_METHOD     fiMpMd2_twoMethod=MODE_SMA;
input ENUM_APPLIED_PRICE fiMpMd2_twoPrice =PRICE_CLOSE;

//-----------------------------------------------------------------------------------------------------------*/

extern string esMpMd2t="second MAplMAd2_CHA";

extern int               seMpMd2_onePeriod=4;
input ENUM_MA_METHOD     seMpMd2_oneMethod=MODE_SMA;
input ENUM_APPLIED_PRICE seMpMd2_onePrice =PRICE_CLOSE;

extern int               seMpMd2_twoPeriod=8;
input ENUM_MA_METHOD     seMpMd2_twoMethod=MODE_SMA;
input ENUM_APPLIED_PRICE seMpMd2_twoPrice =PRICE_CLOSE;

//=============================================================================================================
// G L O B A L E   D E K L A R A T I O N E N
//=============================================================================================================
bool
SHLO,
OMsel,OMbuy,
OCsel,OCbuy
;
//-----------------------------------------------------------------------------------------------------------*/
double
SL_Sel,SL_Buy,TP_Sel,TP_Buy,
SPR,
OPZ,OPZD_Sel,OPZD_Buy,
first_onePR,
first_PRpMAd2,
first_MAplMAd2,secon_MAplMAd2
;
//-----------------------------------------------------------------------------------------------------------*/
int
TiSel,TiBuy
;
//=============================================================================================================
// I N I T
//=============================================================================================================
void OnInit(){
  ChartSetSymbolPeriod(0,NULL,TF);}
//=============================================================================================================
// D E I N I T ?
//=============================================================================================================
void OnDeinit(const int reason){}
//=============================================================================================================
// E A   F U N K T I O N E N   S T A R T
//=============================================================================================================int 
void OnTick(){
//=============================================================================================================
// S T O P   L O S S
//=============================================================================================================
//SL auf 0 stellen, wenn oben <1,
//um irgendwelche Missverständnisse zu vermeiden.
if(SL<1){
  SL_Sel=0.0;
  SL_Buy=0.0;}
if(SL>=1){
  SL_Sel=NormalizeDouble(Bid+SL*_Point,_Digits);
  SL_Buy=NormalizeDouble(Ask-SL*_Point,_Digits);}
//SL genauso groß wie Minstoplevel machen, wenn er kleiner ist:
double MSL=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(SL_Sel<MSL)SL_Sel=MSL;
if(SL_Buy<MSL)SL_Buy=MSL;
//=============================================================================================================
// T A K E   P R O F I T
//=============================================================================================================
//TP auf 0 stellen, wenn oben <1,
//um irgendwelche Missverständnisse zu vermeiden.
if(TP<1){
  TP_Sel=0.0;
  TP_Buy=0.0;}
if(TP>=1){
  TP_Sel=NormalizeDouble(Bid-TP*_Point,_Digits);
  TP_Buy=NormalizeDouble(Ask+TP*_Point,_Digits);}
//=============================================================================================================
// L O T S   ?
//=============================================================================================================
double Min_L=MarketInfo(Symbol(),MODE_MINLOT);
double Max_L=MarketInfo(Symbol(),MODE_MAXLOT);
if(Lots<Min_L)Lots=Min_L;
if(Lots>Max_L)Lots=Max_L;
//=============================================================================================================
// A U T O L O T S   werden falsch berechnet!
//=============================================================================================================
double

MarReq,
AccBal,
oneL_ML,
MarReq_ML,
OnePercAccBal,
Print_Lots,
OnePercAccBal_AutoLotPerc,
OnePercAccBalAutoLotPerc_MREQMinL

;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

  MarReq=MarketInfo(Symbol(),MODE_MARGINREQUIRED); // nötige Margin für 1 Lot (100.000 Units)
  AccBal=AccountBalance(); // momentaner Kontostand

//  "1 Lot" geteilt durch Mindest-Lot, um später raus zu finden, wie viel Margin für Mindest-Lot gebraucht wird.
    if(Min_L<1.0 )oneL_ML=1.0*Min_L;
    if(Min_L>=1.0)oneL_ML=1.0/Min_L;

// müsste bis hier richtig sein...

//  Margin_für_1_Lot geteilt durch Ergebnis, um raus zu finden, wie viel Margin für Mindest_Lot benötigt wird.
//  z.B.:  €1000,00 / 100 = €10,00
    if(MarReq< 1.0){
      if(oneL_ML< 1.0)MarReq_ML = MarReq * oneL_ML;  // ?
      if(oneL_ML>=1.0)MarReq_ML = MarReq / oneL_ML;} // ?

    if(MarReq>=1.0){
      if(oneL_ML< 1.0)MarReq_ML = MarReq * oneL_ML;  // ?
      if(oneL_ML>=1.0)MarReq_ML = MarReq / oneL_ML;} // ?

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

//  1% vom Kontostand ausrechnen
//  z.B.: €1000,00 / 100% = €10,00
    OnePercAccBal = AccBal / 100.0; // ?

//  1% des Kontostands * Prozent, für die Lots gekauft werden sollen
//  z.B.: €10,00 * 2,5% = €25,00 ?
    if(OnePercAccBal<1.0){
      if(Auto_Lotsize_Perc< 1.0)OnePercAccBal_AutoLotPerc = OnePercAccBal / Auto_Lotsize_Perc;  // ?
      if(Auto_Lotsize_Perc>=1.0)OnePercAccBal_AutoLotPerc = OnePercAccBal * Auto_Lotsize_Perc;} // ?

    if(OnePercAccBal>=1.0){
      if(Auto_Lotsize_Perc< 1.0)OnePercAccBal_AutoLotPerc = OnePercAccBal / Auto_Lotsize_Perc;  // ?
      if(Auto_Lotsize_Perc>=1.0)OnePercAccBal_AutoLotPerc = OnePercAccBal * Auto_Lotsize_Perc;} // ?

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

//  
    OnePercAccBalAutoLotPerc_MREQMinL = OnePercAccBal_AutoLotPerc / MarReq_ML;

//  z.B.: €25,00 * 0.01L = 0.025L (?)

    Print_Lots = OnePercAccBalAutoLotPerc_MREQMinL * Min_L;

//=============================================================================================================
// E A   P R I C E   D E K L A R A T I O N / B E R E C H N U N G
//=============================================================================================================

first_onePR = iCustom(Symbol(),TF,

"OnePrice_CHA"
,
first_OnePr
,
0 // Line Index ?
,
1 // Bar 1
);

//=============================================================================================================
// I N D I K A T O R E N / O S Z I L L A T O R E N   D E K L A R A T I O N E N
//=============================================================================================================
//=============================================================================================================
// I N D I K A T O R E N / O S Z I L L A T O R E N   D E K L A R A T I O N E N

// MA minus MA +/- MA
//=============================================================================================================


/*
double  iCustom(

  string       symbol,           // symbol
  
  int          timeframe,        // timeframe
  
  string       name,             // path/name of the custom indicator compiled program
  
  ...                            // custom indicator input parameters (if necessary)
  
  int          mode,             // line index
  
  int          shift             // shift

);

double  iMA(
   string       symbol,           // symbol
   int          timeframe,        // timeframe
   int          ma_period,        // MA averaging period
   int          ma_shift,         // MA shift
   int          ma_method,        // averaging method
   int          applied_price,    // applied price
   int          shift             // shift
   );
*/

// 1.
first_PRpMAd2 = iCustom(Symbol(),TF,

"PRpMAd2_CHA"
,
PRpMAd2_Price,
PRpMAd2_MA_Period,
0, // MA-Shift
PRpMAd2_MA_Method,
PRpMAd2_MA_Price,
0 // Line Index ?
,
1 // Bar 1
);

//-----------------------------------------------------------------------------------------------------------*/

// 
first_MAplMAd2 = iCustom(Symbol(),TF,

"MAplMAd2_CHA"
,
fiMpMd2_onePeriod,
0,// MA-Shift
fiMpMd2_oneMethod,
fiMpMd2_onePrice,
fiMpMd2_twoPeriod,
0,// MA-Shift
fiMpMd2_twoMethod,
fiMpMd2_twoPrice,
0 // Line Index ?
,
1 // Bar 1
);

//-----------------------------------------------------------------------------------------------------------*/

secon_MAplMAd2 = iCustom(Symbol(),TF,

"MAplMAd2_CHA"
,
seMpMd2_onePeriod,
0,// MA-Shift
seMpMd2_oneMethod,
seMpMd2_onePrice,
seMpMd2_twoPeriod,
0,// MA-Shift
seMpMd2_twoMethod,
seMpMd2_twoPrice,
0 // Line Index ?
,
1 // Bar 1
);
//=============================================================================================================
// S P R E A D 
//=============================================================================================================
SPR=Ask-Bid;
//=============================================================================================================
// ?
//=============================================================================================================
//=============================================================================================================
// O P   B A R 0    D E K L A R A T I O N / B E R E C H N U N G
//=============================================================================================================

OPZ = iOpen(Symbol(),TF,0);

OPZD_Sel=NormalizeDouble( OPZ - DistOP *_Point,_Digits);
OPZD_Buy=NormalizeDouble( OPZ + DistOP *_Point,_Digits);

//=============================================================================================================
// O R D E R   S E N D   
//=============================================================================================================
if(Hour()>=FromH&&Hour()<=TillH){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(NormalizeDouble(SPR<=Max_Spr*_Point,_Digits)){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
SHLO=false;
for(int i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==Symbol()){
if(OrderMagicNumber()==MN_Sel||OrderMagicNumber()==MN_Buy)SHLO=true;}}}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(SHLO==false){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(open_Sel==true){

  if(

      first_onePR    <= first_PRpMAd2  &&
           
      first_PRpMAd2  <= first_MAplMAd2 &&
          
      first_MAplMAd2 <= secon_MAplMAd2 &&
      
                 Bid <= OPZD_Sel
      
    ){
    
        if(IsTradeAllowed()==true)TiSel=OrderSend(Symbol(),OP_SELL,Lots,NULL,Slippage,SL_Sel,TP_Sel,NULL,MN_Sel,clrBlue);
        if(IsTradeContextBusy()==true)Sleep(Sl_MS);
          
        Print("Sended Sell:",

              "-Ask=",Ask,
              "-Bid=",Bid,
              "-Spr=",SPR,
              "-OPZD_Sel=",OPZD_Sel,
              "-OpenPr0=",OPZ,
              "-1.OnePr=",first_onePR,
              "-1.PRpMAd2=",first_PRpMAd2,
              "-1.MAplMAd2=",first_MAplMAd2,
              "-2.MAplMAd2=",secon_MAplMAd2

             );

        Print("AutoLots:",

              "-MarReq=",MarReq,
              "-AccBal=",AccBal,
              "-MinL=",Min_L,
              "-oneL_ML=",oneL_ML,
              "-MarReq_1L=",MarReq,
              "-MarReq_ML=",MarReq_ML,
              "-OnePercAccBal=",OnePercAccBal,
              "-Auto_PrintLots=",Print_Lots

             );

} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(open_Buy==true){

  if(
          
      first_onePR    >= first_PRpMAd2  &&
          
      first_PRpMAd2  >= first_MAplMAd2 &&
          
      first_MAplMAd2 >= secon_MAplMAd2 &&
      
                 Ask >= OPZD_Buy

    ){

       if(IsTradeAllowed()==true)TiBuy=OrderSend(Symbol(),OP_BUY,Lots,NULL,Slippage,SL_Buy,TP_Buy,NULL,MN_Buy,clrBlue);
       if(IsTradeContextBusy()==true)Sleep(Sl_MS);
          
       Print("Sended Buy:",

             "-Ask=",Ask,
             "-Bid=",Bid,
             "-Spr=",SPR,
             "-OPZD_Buy=",OPZD_Buy,
             "-OpenPr1=",OPZ,
             "-1.OnePr=",first_onePR,
             "-1.PRpMAd2=",first_PRpMAd2,
             "-1.MAplMAd2=",first_MAplMAd2,
             "-2.MAplMAd2=",secon_MAplMAd2

            );

       Print("AutoLots:",

             "-MarReq=",MarReq,
             "-AccBal=",AccBal,
             "-MinL=",Min_L,
             "-oneL_ML=",oneL_ML,
             "-MarReq_1L=",MarReq,
             "-MarReq_ML=",MarReq_ML,
             "-OnePercAccBal=",OnePercAccBal,
             "-Auto_PrintLots=",Print_Lots
 
            );

} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
} } }
//=============================================================================================================
// ? O R D E R   M O D I F Y   ( T R A I L I N G   S T O P ) ?
//=============================================================================================================
if(TrailingStop==true){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(int k=OrdersTotal()-1;k>=0;k--){
if(OrderSelect(k,SELECT_BY_POS)){
if(OrderSymbol()==Symbol()){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Neuer SELL-"SL" (S_TS) Funktionen/Berechnungen
if(OrderMagicNumber()==MN_Sel){

//neuer Sell_SL = alter Sell_SL - TSS
  double TS_Sel = NormalizeDouble( OrderStopLoss() - TrailingStopStep *_Point,_Digits);

//
  double TSSel_SL = NormalizeDouble( TS_Sel - SL *_Point,_Digits);

//Wenn Bid drunter ist, soll neuer Sell-SL gesendet werden.
  if( Bid < TSSel_SL ){
    if(IsTradeAllowed()==true)OMsel=OrderModify(OrderTicket(),OrderOpenPrice(),TS_Sel,OrderTakeProfit(),NULL,clrBlue);
    if(IsTradeContextBusy()==true)Sleep(Sl_MS);} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Neuer Buy-"SL" (S_TS) Funktionen/Berechnungen
if(OrderMagicNumber()==MN_Buy){

// Alter Buy-SL + TSS = neuer Buy-SL
  double TS_Buy = NormalizeDouble( OrderStopLoss() + TrailingStopStep *_Point,_Digits);

// neuer BUY_"SL" + SL
  double TSBuy_SL = NormalizeDouble( TS_Buy + SL *_Point,_Digits);

  if( Ask > TSBuy_SL ){
    if(IsTradeAllowed()==true)OMbuy=OrderModify(OrderTicket(),OrderOpenPrice(),TS_Buy,OrderTakeProfit(),NULL,clrBlue);
    if(IsTradeContextBusy()==true)Sleep(Sl_MS);} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
} } } }
//=============================================================================================================
// O R D E R   C L O S E
//=============================================================================================================
for(int l=OrdersTotal()-1;l>=0;l--){
if(OrderSelect(l,SELECT_BY_POS)){
if(OrderSymbol()==Symbol()){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(OrderMagicNumber()==MN_Sel){

  if( 

      ( first_onePR   >= first_PRpMAd2  &&
 
        first_PRpMAd2 >= first_MAplMAd2 

      )||(CAOA==true&&Hour()>=CloseH)){

      if(IsTradeAllowed()==true)OCsel=OrderClose(NULL,NULL,NULL,Slippage,clrRed);
      if(IsTradeContextBusy()==true)Sleep(Sl_MS);

      Print("Closed Sel:",

            "-Ask=",Ask,
            "-Bid=",Bid,
            "-Spr=",SPR,
            "-1.onePR=",first_onePR,
            "-1.PRpMAd2=",first_PRpMAd2,
            "-1.MAplMAd2=",first_MAplMAd2

           );

} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(OrderMagicNumber()==MN_Buy){

  if( 
          
      ( first_onePR   <= first_PRpMAd2  &&
          
        first_PRpMAd2 <= first_MAplMAd2 

      )||(CAOA==true&&Hour()>=CloseH)){

        if(IsTradeAllowed()==true)OCbuy=OrderClose(NULL,NULL,NULL,Slippage,clrRed);
        if(IsTradeContextBusy()==true)Sleep(Sl_MS);
          
        Print("Closed Buy:"

              "-Ask=",Ask,
              "-Bid=",Bid,
              "-Spr=",SPR,
              "-1.onePR=",first_onePR,
              "-1.PRpMAd2=",first_PRpMAd2,
              "-1.MAplMAd2=",first_MAplMAd2

             );

} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
} } }
//=============================================================================================================
// E A   F U N K T I O N E N   B E E N D E N
//=============================================================================================================
}// void OnTick
Angehängte Dateien
Dateityp: mq4 EIMT4EA_oPRPpMd2MpMd2.mq4 (47,3 KB, 4x aufgerufen)
Dateityp: mq4 OnePrice_CHA.mq4 (10,5 KB, 3x aufgerufen)
Dateityp: mq4 PRpMAd2_CHA.mq4 (12,6 KB, 3x aufgerufen)
Dateityp: mq4 MAplMAd2_CHA.mq4 (12,3 KB, 3x aufgerufen)