比特币通信协议 - 币圈消息

比特币通信协议篇11、二、TURN简介。在典型的情况下,TURN客户端连接到内网中,并且通过一个或者多个NAT到 详细

改编了网上的一个EA

  [复制链接]
1606 16
efpe 发表于 2018-1-11 00:41:34 | 只看该作者 |阅读模式 打印 上一主题 下一主题
本人菜鸟,改编了网上的一个EA,使用的时候却只能够运行一次,之后就停止了,不能循环运行,请各位高手帮忙指出错误,万分感谢!
#include
#include //---- input parameters
extern double Lots=0.10;extern double StopDistance = 30;
extern double TakeProfit = 0;
extern double StopLoss= 0;
extern bool FirstOrderIsLong = true;
extern int MagicNumber=999;int Slippage = 2;double OpenBuy=0;
double OpenSell=0;
double OpenBuyLimit=0;
double OpenSellLimit=0;
double OpenBuyStop=0;
double OpenSellStop=0;
double EntryPrice=0;double LastBuyStopPrice=0;
double LastSellStopPrice=0;
double BuyStopPrice=0;
double SellStopPrice=0;
double aLots[]={0.1,0.3,0.9,2.7,8.1,24.3,72.9,218.7,656.1,1968.3};
double MaxLots=0;//Trade Signal
#define _NONE 0
#define _BUY 1
#define _SELL 2
#define _CLOSEBUY 4
#define _CLOSESELL 8
#define _OPENBUYSTOP 16
#define _OPENSELLSTOP 32
#define _DELETEBUYSTOP 64
#define _DELETESELLSTOP 128int cur_signal=_NONE;//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- TODO: add your code here
CheckOpenPositions();
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
return(0);
}//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double llots;
double lSL;
double ordernumber=OrdersTotal();if(MaxLots==0) llots=Lots; else
if(MaxLots==Lots) llots=3*Lots; else
llots=MaxLots*3;
lSL=StopLoss;
CheckSignal();
if(cur_signal & _BUY !=0)
OpenOrder(OP_BUY, llots, Ask, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);if(cur_signal & _SELL !=0)
OpenOrder(OP_SELL, llots, Bid, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);if(cur_signal & _CLOSEBUY !=0)
{
CloseLongs(MagicNumber);
}if(cur_signal & _CLOSESELL !=0)
{
CloseShorts(MagicNumber);
}
if(cur_signal & _DELETEBUYSTOP !=0)
DeleteOpenOrder(OP_BUYSTOP);if(cur_signal & _DELETESELLSTOP !=0)
DeleteOpenOrder(OP_SELLSTOP);if(cur_signal & _OPENBUYSTOP !=0)
{
DeleteOpenOrder(OP_BUYSTOP);
if(FirstOrderIsLong) BuyStopPrice=EntryPrice; else BuyStopPrice=EntryPrice+StopDistance*Point;
OpenOrder(OP_BUYSTOP, llots, BuyStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
}if(cur_signal & _OPENSELLSTOP !=0)
{
DeleteOpenOrder(OP_SELLSTOP);
if(FirstOrderIsLong) SellStopPrice=EntryPrice-StopDistance*Point; else SellStopPrice=EntryPrice;
OpenOrder(OP_SELLSTOP, llots, SellStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
}CheckOpenPositions();
HandleOpenPositions();
closeall();
return(0);
}
//+------------------------------------------------------------------+
void CheckSignal()
{
cur_signal=_NONE;
if(OpenBuy==0 && OpenSell==0)
{
if(OpenBuyStop>0) cur_signal |= _DELETEBUYSTOP;
if(OpenSellStop>0) cur_signal |= _DELETESELLSTOP;
if(cur_signal==_NONE)
{
if(FirstOrderIsLong) cur_signal |= _BUY; else cur_signal |= _SELL;
EntryPrice=0;
}
}
if(OpenBuy!=0 || OpenSell!=0)
{
if(OpenBuy>OpenSell && OpenSellStop==0)
{
cur_signal |= _OPENSELLSTOP;
}
if(OpenBuy=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if(OrderType() == OP_BUY)
{
}if(OrderType() == OP_SELL)
{
}
}
return(0);
}
int OpenOrder(int aCmd, double aLots, double aPrice, int aSlipPage, int aStopLoss, int aTakeProfit, string aComment, int aMagic, datetime aExpiration, color aColor)
{
int order_ticket = 0;
int err = 0;
int l_Try = 0;
int l_MaxTry = 10;
double aPrice2=aPrice+0.0002;
switch (aCmd) {
case OP_BUY:
case OP_BUYLIMIT:
case OP_BUYSTOP:
for (l_Try = 0; l_Try  0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
Print("Error Code= ", err);
break;
}
}
break;
case OP_SELL:
case OP_SELLLIMIT:
case OP_SELLSTOP:
for (l_Try = 0; l_Try  0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
Print("Error Code= ", err);
break;
}
}
}
return (order_ticket);
}double StopLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (aPrice - aPips * Point);
}double StopShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (aPrice + aPips * Point);
}double TakeLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (aPrice + aPips * Point);
}double TakeShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (aPrice - aPips * Point);
}double CheckOpenPositions(bool InclOpenOrder=true)
{
int cnt, total;
double NumPositions;
NumPositions = 0;
total=OrdersTotal();
OpenBuy=0;
OpenSell=0;
OpenBuyLimit=0;
OpenSellLimit=0;
OpenBuyStop=0;
OpenSellStop=0;
MaxLots=0;for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if(MaxLots=0;trade--)
{
if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()!=OP_BUY) continue;
if (clots==0) llots=OrderLots(); else llots=clots;
//Print("Ticket:",OrderTicket(),", MagicNumber:",OrderMagicNumber(),", Lots:",llots);
OrderClose(OrderTicket(),llots,Bid,Slippage,Blue);err=GetLastError();
if(err!=0) Print("Error = ", err," - ",ErrorDescription(err));
}//for
}void CloseShorts(int MagicNumber, double clots=0)
{
int trade, err;
double olots;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()!=OP_SELL) continue;
olots=OrderLots();
if (clots==0) clots=olots;
OrderClose(OrderTicket(),clots,Ask,Slippage,Red);err=GetLastError();
if(err!=0) Print("Error = ", err," - ",ErrorDescription(err));
}//for
}
int DeleteOpenOrder(int aOrderType=-1)
{
int cnt;
bool YesClose;
double pt;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() != Symbol()) continue;
if(OrderMagicNumber() != MagicNumber) continue;
if(aOrderType==OrderType()) OrderDelete(OrderTicket());
else if(aOrderType==-1)
switch(OrderType())
{
case OP_BUYLIMIT:
case OP_SELLLIMIT:
case OP_BUYSTOP:
case OP_SELLSTOP: OrderDelete(OrderTicket()); break;
}
}
return(0);
}
//+------------------------------------------------------------------+
int closeall(){int k, order_num=OrdersTotal();
double yingli=0;
int diancha=Ask-Bid;
int iOrders=OrdersTotal()-1, i;
bool CloseOpenOrders = true;
bool DeleteAllPendingOrders = true;
double Price[2];
int giSlippage;
double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);if(dPoint==0) return(false);
RefreshRates();
Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
giSlippage=2;for(k=0; k30) yingli=6;
if(diancha=4 && OrderProfit()/OrderLots()>20) yingli=9;
if(CloseOpenOrders && yingli>=3){
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()>OP_SELL) && !OrderDelete(OrderTicket())) Print("Close Order Error");
}
}
}
return(0);
}
//+------------------------------------------------------------------+
收藏
收藏0
转播
转播
分享
分享
分享
淘帖0

精彩评论16

跳转到指定楼层
沙发
kitgain 发表于 2018-1-11 01:40:17 | 只看该作者
菜鸟也会改EA?那我是菜菜鸟了,看到楼主的代码头晕,
请菜鸟楼主大致解释一下咯

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
板凳
xiaoming58123 发表于 2018-1-11 03:02:51 | 只看该作者
TODO: add your code here问题在这一句吧
地板
who 发表于 2018-1-11 04:36:57 | 只看该作者
学习一下  谢谢分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
5#
流星划过夜空 发表于 2018-1-11 05:37:50 | 只看该作者
~连看看都要......就太........
6#
byrontang 发表于 2018-1-11 06:40:09 | 只看该作者
先说说你改了哪个部分?
7#
zw0806 发表于 2018-1-11 07:52:01 | 只看该作者
谢谢楼主分享!
8#
alumi999 发表于 2018-1-11 09:25:13 | 只看该作者
thanks for sharing..............
9#
137936 发表于 2018-1-11 10:36:32 | 只看该作者
学习一下  谢谢分享
10#
tongyijiang 发表于 2018-1-11 11:34:58 | 只看该作者
学习一下  谢谢分享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

发布主题
阅读排行更多+

Powered by 顺水鱼MT4外汇EA网! X3.2© 2001-2017 顺水MT4外汇EA公司.( 陕ICP备17014341号-1