Mały dylemat EA otwiera na walutach,na indeksach nie np DAX

O jezykach programowania w platformach i nie tylko.
marcin76
Gaduła
Gaduła
Posty: 300
Rejestracja: 14 lis 2012, 12:42

Mały dylemat EA otwiera na walutach,na indeksach nie np DAX

Nieprzeczytany post autor: marcin76 »

Witam

mam problem z EA bo na walutach działa bez problemu a na indeksach już nie chce otwierać pozycji.

od czego to zależy , czy może ktoś zerknąć o co chodzi i poprawić

albo zerknąć na ten kod

//////////////////////////////////////////////////////////////////////////////////////////////////////////


//+------------------------------------------------------------------+
//| Swing.mq4 |
//+------------------------------------------------------------------+
#property copyright "Swing"
#property link "--"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+

extern double LotSize=0.01;
extern int StopLoss=20;
extern int TakeProfit=20;
extern double RiskPercent = 1;
extern int MagicNumber=1000;

int Slippage=1;


int OnInit()
{



//---
int x=10;

CreateButton("button1","BUY",x,20,80,30,Gold,Black,White,10);
CreateButton("button2","SELL",x,20,80,30,Gold,Black,White,10);
CreateButton("button3","Close",x,20,80,30,Gold,Black,White,10);

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
DeleteButtons();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{


if (IsTesting()) {
if(ObjectGetInteger(ChartID(),"button1",OBJPROP_STATE)==true) {
OrderBuy();
ObjectSetInteger(ChartID(),"button1",OBJPROP_STATE,false);
}
if(ObjectGetInteger(ChartID(),"button2",OBJPROP_STATE)==true) {
OrderSell();
ObjectSetInteger(ChartID(),"button2",OBJPROP_STATE,false);
}
if(ObjectGetInteger(ChartID(),"button3",OBJPROP_STATE)==true) {
CloseThis();
ObjectSetInteger(ChartID(),"button3",OBJPROP_STATE,false);
}
}

}
//+------------------------------------------------------------------+

void CreateButton(string btnName,string btnText,int &x,int y,int w,int h,color clrText,color clrBg,color clrBorder,int fontSize)
{
ObjectCreate(0,btnName,OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,btnName,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,btnName,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,btnName,OBJPROP_XSIZE,w);
ObjectSetInteger(0,btnName,OBJPROP_YSIZE,h);
ObjectSetString(0,btnName,OBJPROP_TEXT,btnText);
ObjectSetInteger(0,btnName,OBJPROP_COLOR,clrText);
ObjectSetInteger(0,btnName,OBJPROP_BGCOLOR,clrBg);
ObjectSetInteger(0,btnName,OBJPROP_BORDER_COLOR,clrBorder);
ObjectSetInteger(0,btnName,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,btnName,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,btnName,OBJPROP_STATE,false);
ObjectSetInteger(0,btnName,OBJPROP_FONTSIZE,fontSize);
x=x+w+10;
}

void DeleteButtons()
{
for(int i=ObjectsTotal()-1; i>-1; i--)
{
if(StringFind(ObjectName(i),"button")>=0) ObjectDelete(ObjectName(i));
}
}

void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
if(sparam=="button1") // Buy
{
Action_Button1();
ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
}
else if(sparam=="button2") // Sell
{
Action_Button2();
ObjectSetInteger(0,"button2",OBJPROP_STATE,false);
}
else if(sparam=="button3") // Close This
{
Action_Button3();
ObjectSetInteger(0,"button3",OBJPROP_STATE,false);
}


}

void Action_Button1(){
{
OrderBuy();
PlaySound("ok.wav");
}
}


void Action_Button2(){
{
OrderSell();
PlaySound("ok.wav");
}
}


void Action_Button3(){
{
CloseThis();
PlaySound("ok.wav");
}
}


void OrderBuy(){
int ticket;
for(int i=0;i<3;i++)
{


double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); if (Digits==1 || Digits==2 || Digits==3 || Digits==4 || Digits==5 ) pipValue *= 10;

double step = MarketInfo(Symbol(),MODE_LOTSTEP);
int norm = 0;
if (step==1) norm = 0;
if (step==0.1) norm = 1;
if (step==0.01) norm = 2;
double minLot = MarketInfo(Symbol(),MODE_MINLOT);
double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
double lots = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
lots = NormalizeDouble(lots,norm);



ticket=OrderSend(Symbol(),OP_BUY,lots + LotSize ,Ask,Slippage,Ask-StopLoss*GetScale(),Ask+TakeProfit*GetScale(),"Swing Buy",MagicNumber,0,Green);
if(ticket>0){break;}
RefreshRates();


}



}


void OrderSell(){
int ticket;
for(int i=0;i<3;i++)
{



double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); if (Digits==1 || Digits==2 || Digits==3 || Digits==4 || Digits==5 ) pipValue *= 10;
double step = MarketInfo(Symbol(),MODE_LOTSTEP);
int norm = 0;
if (step==1) norm = 0;
if (step==0.1) norm = 1;
if (step==0.01) norm = 2;
double minLot = MarketInfo(Symbol(),MODE_MINLOT);
double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
double lots = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
lots = NormalizeDouble(lots,norm);




ticket=OrderSend(Symbol(),OP_SELL,lots + LotSize,Bid,Slippage,Bid+StopLoss*GetScale(),Bid-TakeProfit*GetScale(),"Swing Sell",MagicNumber,0,Red);
if(ticket>0){break;}
RefreshRates();
}
}

void CloseThis() {
bool closed = false;
for (int i = OrdersTotal(); i >=0; i--) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
while(IsTradeContextBusy()) Sleep(100);
RefreshRates();
if (OrderType() == OP_BUY && Symbol() == OrderSymbol() )
{
closed = OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
}
if (OrderType() == OP_SELL && Symbol() == OrderSymbol())
{
closed = OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
}
}
return;

}


double GetScale() {
double res = 0;
if (Digits == 5) { // EURUSD, GBPUSD etc
res = 0.0001;
} else if (Digits == 4) { // USDJPY etc
res = 0.001;
} else if (Digits == 3) { // USDJCZK etc
res = 0.01;
} else if (Digits == 2) { // XAUUSD
res = 0.1;
} else if (Digits == 1) { //
res = 1;
}
return res;
}

-- Dodano: 30 paź 2018, 21:55 --

Już się wyjaśniło więc nie trzeba tego sprawdzać
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.

z6yszko
Gaduła
Gaduła
Posty: 266
Rejestracja: 17 sty 2011, 10:09

Re: Mały dylemat EA otwiera na walutach,na indeksach nie np

Nieprzeczytany post autor: z6yszko »

Sprawdź czy na DAX możesz otworzyć 0.01 lota

ODPOWIEDZ