Einzelnen Beitrag anzeigen
  #2 (permalink)  
Alt 28.12.16
RetepM RetepM ist offline
Mitglied
 
Registriert seit: Feb 2016
Beiträge: 240
RetepM befindet sich auf einem aufstrebenden Ast
Standard

Hi, so kann es gehen :

------------------------------------------------------------------
#include <stdlib.mqh>
#include <WinUser32.mqh>

// exported variables
extern double BuyLots6 = 0.1;
extern int BuyStoploss6 = 20;
extern int BuyTakeprofit6 = 30;
extern double SellLots7 = 0.1;
extern int SellStoploss7 = 20;
extern int SellTakeprofit7 = 30;


// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n"; // use this in custom or utility blocks where you need line feeds
int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names
int current = 0; // current bar index, used by Cross Up, Cross Down and many other blocks
int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar

bool FirstTime2 = true;
bool FirstTime4 = true;


int init()
{
NDigits = Digits;

if (false) ObjectsDeleteAll(); // clear the chart


Comment(""); // clear the chart
return (0);
}

// Expert start
int start()
{
if (Bars < 10)
{
Comment("Not enough bars");
return (0);
}
if (Terminated == true)
{
Comment("EA Terminated.");
return (0);
}

OnEveryTick1();
return (0);
}

void OnEveryTick1()
{
PipValue = 1;
if (NDigits == 3 || NDigits == 5) PipValue = 10;

CheckLastOrderType2();
CheckLastOrderType4();

}

void CheckLastOrderType2()
{
int orderType = -1;
int orderId = -1;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime() && orderId == 1)
{
lastCloseTime = OrderCloseTime();
orderType = OrderType();
orderId = OrderMagicNumber();
}
}
if (orderType == OP_SELL || FirstTime2)
{
FirstTime2 = false;
BuyOrder6();

}
}

void BuyOrder6()
{
double SL = Ask - BuyStoploss6*PipValue*Point;
if (BuyStoploss6 == 0) SL = 0;
double TP = Ask + BuyTakeprofit6*PipValue*Point;
if (BuyTakeprofit6 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 4, 0, 0, "My Expert", 1, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 4, SL, TP, "My Expert", 1, 0, Blue);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}

}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}

void CheckLastOrderType4()
{
int orderType = -1;
int orderId = -1;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime() && orderId == 1)
{
lastCloseTime = OrderCloseTime();
orderType = OrderType();
orderId = OrderMagicNumber();
}
}
if (orderType == OP_BUY || FirstTime4)
{
FirstTime4 = false;
SellOrder7();

}
}

void SellOrder7()
{
double SL = Bid + SellStoploss7*PipValue*Point;
if (SellStoploss7 == 0) SL = 0;
double TP = Bid - SellTakeprofit7*PipValue*Point;
if (SellTakeprofit7 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, SellLots7, Bid, 4, 0, 0, "My Expert", 1, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, SellLots7, Bid, 4, SL, TP, "My Expert", 1, 0, Red);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}

}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}



int deinit()
{
if (false) ObjectsDeleteAll();


return (0);
}


------------------------------------------------------------------

PS Code kommt aus meinem Generator.