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

Hi, hier funktionierender EA-Code, den mein Framework erzeugt. Achtung der EA setzt Pending Orders, nur Demo oder AutoTrading false!

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

//------------------------------------------------
extern double LotSize = 0.1;
extern int SLSize = 20;
extern int TPSize = 30;
extern int PriceOffset = 20;

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 ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names

//------------------------------------------------
int init()
{

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);
}

OnEveryTick();
return (0);
}

//------------------------------------------------
void OnEveryTick()
{
PipValue = 1;
if (Digits == 3 || Digits == 5) PipValue = 10;

PrintFunctionsToChart();
IfNoOrderExist();

}

//------------------------------------------------
void PrintFunctionsToChart()
{
string temp = "Show Points And Digits:\n";
temp = temp + "Points; " + DoubleToStr(Point, Digits) + "\n"
+ "Digits: " + DoubleToStr(Digits, 0) + "\n"
+ "------------------------------------------------\n";
Comment(temp);

}

//------------------------------------------------
void IfNoOrderExist()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol())
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}

if (exists == false)
{
BuyPendingOrder();
SellPendingOrder();

}
}

//------------------------------------------------
void BuyPendingOrder()
{
int expire = TimeCurrent() + 60 * 0;
double price = NormalizeDouble(Ask, Digits) + PriceOffset*PipValue*Point;
double SL = price - SLSize*PipValue*Point;
if (SLSize == 0) SL = 0;
double TP = price + TPSize*PipValue*Point;
if (TPSize == 0) TP = 0;
if (0 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_BUYSTOP, LotSize, price, 4, SL, TP, "Test Digits", 100, expire, Blue);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}

}

//------------------------------------------------
void SellPendingOrder()
{
int expire = TimeCurrent() + 60 * 60;
double price = NormalizeDouble(Bid, Digits) - PriceOffset*PipValue*Point;
double SL = price + SLSize*PipValue*Point;
if (SLSize == 0) SL = 0;
double TP = price - TPSize*PipValue*Point;
if (TPSize == 0) TP = 0;
if (60 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_SELLSTOP, LotSize, price, 4, SL, TP, "Test Digits", 100, expire, Red);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}

}

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

return (0);
}


+++++++++++++++++++++++++++++++++