Also irgendwie bekomme ich es nicht hin. Ich habe bestimmt irgendwo ein Denkfehler und stehe dazu noch auf dem Schlauch.
Ich habe mal den Code eingefügt. Es geht ja nur um die Lotsize. Im Test macht er 4 Trades auf und schließt sie wieder. Aber er soll eigentlich 8 Trades eröffnen.
Kannst du bitte noch mal drüber schauen?
Sorry.
Code:
//+------------------------------------------------------------------+
//| Beispiel.mq4 |
//+------------------------------------------------------------------+
#property strict
#property icon "icon.ico"
#include <stderror.mqh>
#include <stdlib.mqh>
extern double TP = 100;
extern double SL = 100;
extern double LS = 0.02;
extern string MyComment = "Beispiel";
extern bool AutoTrade = true;
double lotArray[4] = {0.03, 0.12, 0.18, 0.24};
double lotSize = lotArray[0];
int count_lotSize = 0;
double pips;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Determine what a pip is.
pips=Point; //.00001 or .0001. .001 .01.
if(Digits==3 || Digits==5 || Digits==1) pips*=10;
else if(Digits==2) pips*=100;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(AutoTrade == true)
CheckForSignal();
if(TotalOpenOrders() > 4)
{
lotSize = lotArray[3];
}
else
{
lotSize = lotArray[0];
}
//if(TotalOpenOrders() >= count_lotSize)
// {
// lotSize = lotArray[0];
// }
}
//+------------------------------------------------------------------+
//| Check for Signal - Signal für automatischen Handel |
//+------------------------------------------------------------------+
void CheckForSignal()
{
if(TotalOpenOrders() < 9)
PlaceOrder(OP_SELL);
}
//+------------------------------------------------------------------+
//| PlaceOrder-Function |
//+------------------------------------------------------------------+
void PlaceOrder(int dir)
{
if(dir==OP_BUY)
{
int ticket=OrderSend(Symbol(),dir,lotArray[count_lotSize],Ask,30,Ask-(SL*pips),Ask+(TP*pips),MyComment,0,0,clrGreen);
count_lotSize++;
}
if(dir==OP_SELL)
{
int ticket=OrderSend(Symbol(),dir,lotArray[count_lotSize],Bid,30,Bid+(SL*pips),Bid-(TP*pips),MyComment,0,0,clrRed);
count_lotSize++;
}
}
//+------------------------------------------------------------------+
//| Total of ALL orders place by this expert. |
//+------------------------------------------------------------------+
int TotalOpenOrders()
{
int total=0;
if(OrdersTotal()>0)for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol() == Symbol())
total++;
}
else Print(__FUNCTION__," Failed to select order ",i," ",GetLastError());
}
return (total);
}
//+------------------------------------------------------------------+