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

@Varo Trading
Hier ein EA aus meinem FrameWork. Das Teil erlaubt jeweils einen Trade für Long/Short. Vielleicht hilft es Dir weiter, ich habe Deine Indi-Werte eingesetzt. Viel Spaß beim Gucken:-)

//##################################################
#property copyright "RetepM"
#property link "http://www.expert-advisor.com"

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

extern int MagicNo = 1110;
extern double LotSize = 0.01;
extern double SLSize = 20;
extern double TPSize = 20;

double PipValue=1;
bool Terminated = false;
string LF = "\n";
int NDigits = 4;
double K0;
double D0;
double K1;
double D1;

//----------------------------------------------------
int init()
{
NDigits = Digits;

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

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

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

PipValue = 1;
if (NDigits == 3 || NDigits == 5) PipValue = 10;
GetValues();
ShowComment();
return (0);
}

//----------------------------------------------------
void GetValues()
{
K0=iStochastic(_Symbol,_Period,5,3,3,MODE_SMA,0,MO DE_MAIN,0);
D0=iStochastic(_Symbol,_Period,5,3,3,MODE_SMA,0,MO DE_SIGNAL,0);
K1=iStochastic(_Symbol,_Period,5,3,3,MODE_SMA,0,MO DE_MAIN,1);
D1=iStochastic(_Symbol,_Period,5,3,3,MODE_SMA,0,MO DE_SIGNAL,1);
CheckBuyOrder();
CheckSellOrder();

}

//----------------------------------------------------
void CheckBuyOrder()
{
if ((K0<44)&&(D0<44) && (D1<K0)&&(D1>K1))
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNo)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}

if (exists == false)
{
double SL = Ask - SLSize*PipValue*Point;
if (SLSize == 0) SL = 0;
double TP = Ask + TPSize*PipValue*Point;
if (TPSize == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 4, 0, 0, "Buy", MagicNo, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 4, SL, TP, "Buy", MagicNo, 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 CheckSellOrder()
{
if ((K0>56)&&(D0>56) && (D1>K0)&&(D1<K1))
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNo)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}

if (exists == false)
{
double SL = Bid + SLSize*PipValue*Point;
if (SLSize == 0) SL = 0;
double TP = Bid - TPSize*PipValue*Point;
if (TPSize == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 4, 0, 0, "Sell", MagicNo, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 4, SL, TP, "Sell", MagicNo, 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()));
}
}
}
}

//----------------------------------------------------
void ShowComment()
{
string temp = "Show Balance/Profit\n";
temp = temp + "------------------------------------------------\n"
+ "Balance: " + DoubleToStr(AccountBalance(), 5) + "\n"
+ "Profit: " + DoubleToStr(AccountProfit(), 5) + "\n"
+ "------------------------------------------------\n";
Comment(temp);

}

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

return (0);
}

//##################################################