Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools
Zurück   Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools > Metatrader 5 > Programmierung MQL5

Programmierung MQL5 Hier gehts rund ums Programmieren in MQL5.


Portalsuche


Werbung

Login
Benutzername:
Kennwort:


Statistik
Themen: 3824
Beiträge: 36908
Benutzer: 6.074
Aktive Benutzer: 494
Links: 80
Wir begrüßen unseren neuesten Benutzer: hmf44
Mit 483 Benutzern waren die meisten Benutzer gleichzeitig online (21.04.16 um 17:12).
Neue Benutzer:
vor einem Tag
- hmf44
vor einem Tag
- Crossa
vor einem Tag
- snatshit
vor 2 Tagen
- Roerich
vor 2 Tagen
- John_Liver...

Onlineuser
'Wer ist online' anzeigen Benutzer: 2
Gäste: 50
Gesamt: 52
Team: 0
Team:  
Benutzer:  Dennis605, jimydirektsaft
Freunde anzeigen

Empfehlungen

Werbung

Thema geschlossen
 
Themen-Optionen Thema durchsuchen Ansicht
  #1 (permalink)  
Alt 09.11.15
Neues Mitglied
 
Registriert seit: Nov 2015
Beiträge: 7
nothin_ befindet sich auf einem aufstrebenden Ast
Standard Erster eigener EA

Hallo zusammen,
ich habe meinen ersten einfachen eigenen EA (nach einer Vorlage) gebaut - es soll gekauft werden wenn der beiliegende Indikator 0 erreicht und vice versa bei 100. Das Skript kompiliert nun anstandlos - leider werden bloß keine Trades ausgeführt. Hat jemand eine Idee wo ich hier einen Denkfehler habe, in meinen Augen müsste eigentlich alles passen?

Code:
//+------------------------------------------------------------------+
//|                                                    EaTemplate.mq4|
//|                                          Jacek Dzambuіat-Colojew |
//|                                                jacekdc@gmail.com |
//+------------------------------------------------------------------+

#property copyright "Jacek Dzambuіat-Colojew"
#property link      "jacekdc@gmail.com"
#property version   "1.00"

input double Lot = 0.1;
input bool AutoLots = False; // if its True it will automatically calculate Lot based on Accont Balance. Go down to open() function to see how does it work.
input int TakeProfit = 200;
input int StopLoss = 200;
input int TrailingStart = 1; // 200 mean tralingstop will start to work above 200 pips
input int TrailingStop = 20; // 150 mean it will move 150 pips above current order price
input int Ba = 100; // BA at 100 mean, that order stop loss will be moved at open price + spread to make order safe.
input int Slippage = 3;
input int MaxOrders = 1; // How many orders script can open on current symbol
input int Magic = 666; // Magic number
input int Pips = 10; // How far ( in pips ) from actual price sellstop / buystop order will be placed.
input int Mins = 30; // Lifetime of buystop / sellstop order ( in minutes ) after it is deleted if not reached open price.
input int PERIOD = 15; // 15 mean it will work on M15, for exampe PERIOD = 240 mean it will work on H4
input int Candles = 8; // Number of candles scanned in Scan() function, which shows the highes and the lowest order price in the past.
input int shift = 1; // Shift = 1 mean it will start to scan from previous candle.
input int MaxSpread = 20; // If spread is above 20, orders will not be opened

int Ticket, LastOrder = 2; // LastOrder = 2 mean script can make sell and buy orders. 0 mean it can only buy. 1 mean it can only sell.
double lows, highs, low, high, range; // To learn how does LastOrder works look down in open() script.
// low, high and range are used in Scan Loop which calculate the highest and the lowest Order Price in the past. Range show how many pips are beetwen high and low value

int start() { // Executed when there is new tick.

   int m = 0; // m is a number of opened orders on current symbol.

   for ( int n = 0; n < OrdersTotal(); n++ ) {  // That loop search if there is opened order on current symbol.

      if ( OrderSelect ( n, SELECT_BY_POS ) ) {  

         if ( OrderSymbol() == Symbol() ) {  
        
            if ( OrderMagicNumber() == Magic ) {  
  
               Ticket = OrderTicket();  
               if ( OrderSelect ( Ticket, SELECT_BY_TICKET ) == True ) { close(); } // If it found opened order, script jump to close() function which close orders and make trailing stops.
               m++;
              
            }

         }

      }

   }
  
   if ( m == 0 ) { LastOrder = 2; } // If there are no orders script LastOrder = 2 which allow script to sell and buy
   if ( m < MaxOrders ) { open(); } // If MaxOrders are not reached it allow script to open one more order in order() function.
  
return ( 0 );
}
// time is a number of candles which are scanned
// period is a time of 1 candle. For ex. if period = 15 it will work on M15 candles.
// shifte = 1 mean it will start to scan from previous candle.
int Scan ( int time, int period, int shifte ) { // That loop calculate the highest and the lowest order price with range, which show how many pips are beetwen high and low value
   for ( int n = shifte; n < time; n++ ) {    
  
      lows = iLow(NULL, period, n);
      highs = iHigh(NULL, period, n);
  
      if ( n == shifte ) {
      
         low = lows;
         high = highs;    
        
      } else {
      
         if ( low >= lows ) { low = lows; }
         if ( high <= highs ) { high = highs; }
      
      }  
   }
  
   range = high - low;
  
return ( 0 );
}

int open() {  

   double Lots;

   Scan ( Candles, PERIOD, shift ); // Here is example how to find the lowest, the highest value and range in the past.
   double BackHigh = high;
   double BackLow = low;
   double BackRange = range;
   
   #define IND_NAME "StochRSI"
   double ind_1 = iCustom(NULL,0,IND_NAME,14,PRICE_CLOSE,3,3,5000,0,0);
  
   if ( AutoLots == False ) { Lots = Lot; }
   else { Lots = MathRound ( AccountBalance() / 100 ) / 100; } // First 100 say, that every 100$ will increase lot by 1 point.
                                                               // Second 100 say, that 1 point is equal to 0.01 lot
   // Here you can place indicators and all stuff              // For ex. if you want to play 0.5 Lot with 1000$ account you can write MathRound ( AccountBalance() / 20 ) / 100;
   // Which will calculate when script should buy or sell.
  
   RefreshRates();  // RefreshRate() update Bid and Ask value.
  
   if ( ( Ask - Bid ) / Point < MaxSpread ) { // Checking, if spread is less than MaxSpread from inputs. If its Bigger, orders wont open
  
      if (ind_1==0 && LastOrder != 1 ) { // LastOrder!= 1 prevent script from making a lot of same buy orders
         Ticket = OrderSend ( Symbol(), OP_BUY, Lots, Ask, Slippage, Ask - ( StopLoss * Point ), Ask + ( TakeProfit * Point ), NULL, 0, 0, Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }
  
      if (ind_1==100 && LastOrder != 0 ) { // LastOrder!= 0 prevent script from making a lot of same sell orders
         Ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, Bid + ( StopLoss * Point ), Bid - ( TakeProfit * Point ), NULL, 0, 0, Red);
         LastOrder = 0; // It prevent script from making a lot of same sell orders
      }
      
   }

return ( 0 );
}

int close() { // Close is executed when script find opened order on current symbol

   // Here you can place indicators, candle scan and other stuff to set condidtions for closing the order.

   if ( OrderType() == OP_BUY ) {
    
         RefreshRates(); // RefreshRate() update Bid and Ask value.
         // Calculate Trailing Stop.
         if ( Bid >= OrderOpenPrice() + TrailingStart * Point && OrderStopLoss() < Bid - ( TrailingStop * Point ) ) {
            Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), Bid - ( TrailingStop * Point ), OrderTakeProfit() , 0 );
         }    
         // Calculate BA.          
         if ( Bid >= OrderOpenPrice() + Ba * Point && Bid < OrderOpenPrice() + ( Ba + 5 ) * Point ) {
            Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + ( 10 * Point ), OrderTakeProfit() , 0 );                
         }
        
         // Replace 1 == 0 to conditions to close Buy order.
         if ( 1 == 0 ) {
            Ticket = OrderClose ( Ticket, OrderLots(), OrderClosePrice(), Slippage, Green );
         }    
          
      }
  
   if ( OrderType() == OP_SELL ) {
    
         RefreshRates(); // RefreshRate() update Bid and Ask value.
         // Calculate Trailing Stop.
         if ( Ask <= OrderOpenPrice() - TrailingStart * Point && OrderStopLoss() > Ask + ( TrailingStop * Point ) ) {
            Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), Ask + ( TrailingStop * Point ), OrderTakeProfit(), 0 );
         }  
         // Calculate BA.
         if ( Ask <= OrderOpenPrice() - Ba * Point &&  Ask > OrderOpenPrice() - ( Ba + 5 ) * Point  ) {
            Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - ( 10 * Point ) , OrderTakeProfit(), 0 );
         }
        
         // Replace 1 == 0 to conditions to close Sell order.
         if ( 1 == 0 ) {
            Ticket = OrderClose ( Ticket, OrderLots(), OrderClosePrice(), Slippage, Red );
         }    
          
      }    
      
  
  
return ( 0 );
}
Schöne Grüße!
nothin_
Angehängte Dateien
Dateityp: mq4 StochRSI.mq4 (4,9 KB, 1x aufgerufen)
Thema geschlossen

Lesezeichen

Stichworte
keine trades, mql5, programmierung, programmierung metatrader, trades


Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are aus
Pingbacks are aus
Refbacks are aus




Alle Zeitangaben in WEZ +1. Es ist jetzt 16:24 Uhr.



Der Wavesnode - Spam Firewall
-----------------------------------------------------------------------------------------------------------------------------
Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Powered by vBCMS® 2.7.0 ©2002 - 2017 vbdesigns.de
SEO by vBSEO 3.6.1
Copyright ©2009 - 2017 by Expert-Advisor.com - Das Metatrader Forum
MetaTrader bzw. MetaTrader 4 und MetaTrader 5 sind eingetragene Marken der MetaQuotes Software Corp.
-----------------------------------------------------------------------------------------------------------------------------