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)
-   -   mein EA geht nur Short Warum ? (http://www.expert-advisor.com/forum/showthread.php?t=1806)

plewka1968 04.01.12 10:34

mein EA geht nur Short Warum ?
 
mein EA geht nur Short obwohl Long und Short eingestellt ist. Woran kann das liegen? kann einer helfen


extern int Magic = 1010;
extern double Lots = 0.1;
extern bool RiskManagement=false;
extern double RiskPercent=10;
extern bool Martingale=false;
extern double Multiplier=5;
extern double MinProfit=0;
extern double MinLot = 0.1;
extern int MaxLot = 100;
extern int TrailingStop = 0;
extern double StopLoss = 20;
extern double TakeProfit = 50;
extern bool EnableHiddenSL=false;
extern int HiddenSL=20;
extern bool EnableHiddenTP=false;
extern int HiddenTP=50;
extern int Start = 0;
extern int End = 24;
extern bool FridayNoTrading = false;
extern double RSI_PERIOD = 14;
extern double RSI_TF = 5;
extern double RSI_BUY = 30;
extern double RSI_SELL = 70;

extern double RSI_BUY_Zera = 40;
extern double RSI_SELL_Zera = 60;
extern bool Compra = true;
extern bool Venda = true;

double Balance=0.0;int err=0;int TK;

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

int isMgNum(int magic)
{
int ordtotal = OrdersTotal();
for (int i = 0; i < ordtotal; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderMagicNumber() == magic) && (OrderSymbol() == Symbol())) return(1);
}
}

void MoveTrailingStopsPerMN(int iMN)
{
string symbol = Symbol();
int icnt, itotal;
itotal=OrdersTotal();
for(icnt=0;icnt<itotal;icnt++)
{ // order loop boundary
OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
// check for opened position, symbol & MagicNumber
if(OrderType()==OP_SELL && OrderSymbol()==symbol && OrderMagicNumber()==iMN)
{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
}
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if(OrderStopLoss()>(Ask+Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}

if(OrderType()==OP_BUY && OrderSymbol()==symbol && OrderMagicNumber()==iMN)
{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}

if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
} // order loop boundary
return(0);
}

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

int init()
{
return(0);
}

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

int deinit()
{
return(0);
}

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

int start()
{
//+------------------------------------------------------------------+
//|Easy Money Management |
//+------------------------------------------------------------------+
//risk management
bool MM=RiskManagement;
if(MM){if(RiskPercent<0.1||RiskPercent>10){Comment ("Invalid Risk Value.");return(0);}
else{Lots=MathFloor((AccountFreeMargin()*AccountLe verage()*RiskPercent*Point*10)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*
MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symb ol(),MODE_MINLOT);}}
if(MM==false){Lots=Lots;}

//martingale
if(Balance!=0.0&&Martingale==True){if(Balance>Acco untBalance())Lots=Multiplier*Lots;else if((Balance+MinProfit)<AccountBalance())Lots=Lots/Multiplier;
else if((Balance+MinProfit)>=AccountBalance()&&Balance< =AccountBalance())Lots=Lots;}Balance=AccountBalanc e();


if (Lots < MinLot) Lots = MinLot;
if (Lots > MaxLot) Lots = MaxLot;

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

double IN;

double RSI = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 0);


if ((TimeHour(TimeCurrent()) <= Start ) && (TimeHour(TimeCurrent()) >= End)) return(0);

IN = NormalizeDouble(AccountFreeMargin() / 500,2);

if ((isMgNum(Magic) == 0) && (RSI <RSI_BUY))
{
if (Compra&&(FridayNoTrading==false||(FridayNoTrading &&Day()!=5)))
TK=OrderSend(Symbol(),OP_BUY,Lots,Ask,4,Ask - StopLoss * Point, Ask + TakeProfit * Point,0,Magic,0,Green);
Compra = false;
Venda = true;
}

if ((isMgNum(Magic) == 0) && (RSI >RSI_SELL))
{
if (Venda&&(FridayNoTrading==false||(FridayNoTrading& &Day()!=5)))
TK=OrderSend(Symbol(),OP_SELL,Lots,Bid,4,Bid + StopLoss * Point,Bid - TakeProfit * Point,0,Magic,0,Red);
Venda = false;
Compra = true;
}

MoveTrailingStopsPerMN(Magic);

if ( ( RSI < RSI_SELL_Zera ) && ( RSI > RSI_BUY_Zera ) )
{
Venda = true;
Compra = true;
}

if((FridayNoTrading&&Day()==5)||(EnableHiddenSL&&( OrderOpenPrice()-Bid)/Point>=HiddenSL)||(EnableHiddenTP&&(Ask-OrderOpenPrice())/Point>=HiddenTP)){
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&( (OrderMagicNumber()==Magic)||Magic==0)){OrderClose (OrderTicket(),OrderLots(),Bid,0,Red);}
}
if((FridayNoTrading&&Day()==5)||(EnableHiddenSL&&( Ask-OrderOpenPrice())/Point>=HiddenSL)||(EnableHiddenTP&&(OrderOpenPrice ()-Bid)/Point>=HiddenTP)){
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&& ((OrderMagicNumber()==Magic)||Magic==0)){OrderClos e(OrderTicket(),OrderLots(),Ask,0,Red);}
}

if(TK<0){if (GetLastError()==134){err=1;Print("NOT ENOGUGHT MONEY!!");}return (-1);}

naranjoe 04.01.12 21:35

Liste der Anhänge anzeigen (Anzahl: 1)
Also bei meinem kurzen Test geht er Long und Short
Du solltest etwas mehr Struktur in deinen Code bringen.

Gruß
naranjoe


Alle Zeitangaben in WEZ +2. Es ist jetzt 09:22 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