寻一个ea开发朋友和做,开发特殊东西,百分百盈利只要能实现,简单原理,互盈,共粒,关注涡,,实抄
.大家好我研究黄金原油,股票,期货好长时间了,发展到研究庄,手法,规律,推盘,手法,砸,,拉,诱,洗,盘,对,出,,,非常非常好,里面太复杂,深奥,人工做太复杂,累,,,寻一个ea开发朋友和做,开发特殊东西,百分百盈利只要能实现,简单原理,互盈,共粒,关注涡,,实抄void OnStart()
{
//---
string up_arrow="up_arrow";
datetime time=TimeCurrent();
double lastClose;
int close=CopyClose(Symbol(),Period(),0,1,lastClose); // 获得收盘价
//--- 如果获得价格
if(close>0)
{
ObjectCreate(0,up_arrow,OBJ_ARROW,0,0,0,0,0); // 创建一个箭头
ObjectSetInteger(0,up_arrow,OBJPROP_ARROWCODE,241); // 设置箭头代码
ObjectSetInteger(0,up_arrow,OBJPROP_TIME,time); // 设置时间
ObjectSetDouble(0,up_arrow,OBJPROP_PRICE,lastClose);// 预定价格
ChartRedraw(0); // 现在绘制箭头
}
else
Print("Unable to get the latest Close price!");
} long handle=ChartOpen("EURUSD",PERIOD_H12);
if(handle!=0)
{
ChartSetInteger(handle,CHART_AUTOSCROLL,false);
ChartSetInteger(handle,CHART_SHIFT,true);
ChartSetInteger(handle,CHART_MODE,CHART_LINE);
ResetLastError();
bool res=ChartNavigate(handle,CHART_END,150);
if(!res) Print("Navigate failed. Error = ",GetLastError());
ChartRedraw();
} //---- maximums counting
i=Bars-KPeriod;
if(counted_bars>KPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double max=-1000000;
k = i + KPeriod-1;
while(k>=i)
{
price=High;
if(max<price) max=price;
k--;
}
HighesBuffer=max;
i--;
}
//---- #property copyright "1"
#property link "1"
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 100.0
#property indicator_buffers 1
#property indicator_color1 LawnGreen
#property indicator_level3 50.0
extern string Tips = "本交易系统来着1";
int gi_84 = 16;
double g_ibuf_88[];
int init() {
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3, LawnGreen);
SetIndexBuffer(0, g_ibuf_88);
IndicatorShortName("绿色线");
return (0);
}
int deinit() {
return (0);
}
int start() {
double ld_0;
double ld_8;
double ld_16;
double ld_24;
double ld_32;
double ld_40;
double ld_48;
double ld_56;
double ld_64;
double ld_72;
double ld_80;
double ld_88;
double ld_96;
double ld_104;
double ld_112;
double ld_120;
double ld_128;
double ld_136;
double ld_144;
double ld_152;
double ld_160;
double ld_168;
double ld_176;
double ld_184;
double ld_192;
double ld_200;
double ld_208;
double ld_216 = Bars - gi_84 - 1;
for (int li_224 = ld_216; li_224 >= 0; li_224--) {
if (ld_8 == 0.0) {
ld_8 = 1.0;
ld_16 = 0.0;
if (gi_84 - 1 >= 5) ld_0 = gi_84 - 1.0;
else ld_0 = 5.0;
ld_80 = 100.0 * ((High + Low + Close) / 3.0);
ld_96 = 3.0 / (gi_84 + 2.0);
ld_104 = 1.0 - ld_96;
} else {
if (ld_0 <= ld_8) ld_8 = ld_0 + 1.0;
else ld_8 += 1.0;
ld_88 = ld_80;
ld_80 = 100.0 * ((High + Low + Close) / 3.0);
ld_32 = ld_80 - ld_88;
ld_112 = ld_104 * ld_112 + ld_96 * ld_32;
ld_120 = ld_96 * ld_112 + ld_104 * ld_120;
ld_40 = 1.5 * ld_112 - ld_120 / 2.0;
ld_128 = ld_104 * ld_128 + ld_96 * ld_40;
ld_208 = ld_96 * ld_128 + ld_104 * ld_208;
ld_48 = 1.5 * ld_128 - ld_208 / 2.0;
ld_136 = ld_104 * ld_136 + ld_96 * ld_48;
ld_152 = ld_96 * ld_136 + ld_104 * ld_152;
ld_56 = 1.5 * ld_136 - ld_152 / 2.0;
ld_160 = ld_104 * ld_160 + ld_96 * MathAbs(ld_32);
ld_168 = ld_96 * ld_160 + ld_104 * ld_168;
ld_64 = 1.5 * ld_160 - ld_168 / 2.0;
ld_176 = ld_104 * ld_176 + ld_96 * ld_64;
ld_184 = ld_96 * ld_176 + ld_104 * ld_184;
ld_144 = 1.5 * ld_176 - ld_184 / 2.0;
ld_192 = ld_104 * ld_192 + ld_96 * ld_144;
ld_200 = ld_96 * ld_192 + ld_104 * ld_200;
ld_72 = 1.5 * ld_192 - ld_200 / 2.0;
if (ld_0 >= ld_8 && ld_80 != ld_88) ld_16 = 1.0;
if (ld_0 == ld_8 && ld_16 == 0.0) ld_8 = 0.0;
}
if (ld_0 < ld_8 && ld_72 > 0.0000000001) {
ld_24 = 50.0 * (ld_56 / ld_72 + 1.0);
if (ld_24 > 100.0) ld_24 = 100.0;
if (ld_24 < 0.0) ld_24 = 0.0;
} else ld_24 = 50.0;
g_ibuf_88 = ld_24;
}
return (0);
} int start() {
double ld_0;
double ld_8;
double ld_16;
double ld_24;
double ld_32;
double ld_40;
double ld_48;
double ld_56;
double ld_64;
double ld_72;
double ld_80;
double ld_88;
double ld_96;
double ld_104;
double ld_112;
double ld_120;
double ld_128;
double ld_136;
double ld_144;
double ld_152;
double ld_160;
double ld_168;
double ld_176;
double ld_184;
double ld_192;
double ld_200;
double ld_208;
double ld_216 = Bars - gi_84 - 1;
for (int li_224 = ld_216; li_224 >= 0; li_224--) {
if (ld_8 == 0.0) {
ld_8 = 1.0;
ld_16 = 0.0;
if (gi_84 - 1 >= 5) ld_0 = gi_84 - 1.0;
else ld_0 = 5.0;
ld_80 = 100.0 * ((High + Low + Close) / 3.0);
ld_96 = 3.0 / (gi_84 + 2.0);
ld_104 = 1.0 - ld_96;
} else {
if (ld_0 <= ld_8) ld_8 = ld_0 + 1.0;
else ld_8 += 1.0;
ld_88 = ld_80;
ld_80 = 100.0 * ((High + Low + Close) / 3.0);
ld_32 = ld_80 - ld_88;
ld_112 = ld_104 * ld_112 + ld_96 * ld_32;
ld_120 = ld_96 * ld_112 + ld_104 * ld_120;
ld_40 = 1.5 * ld_112 - ld_120 / 2.0;
ld_128 = ld_104 * ld_128 + ld_96 * ld_40;
ld_208 = ld_96 * ld_128 + ld_104 * ld_208;
ld_48 = 1.5 * ld_128 - ld_208 / 2.0;
ld_136 = ld_104 * ld_136 + ld_96 * ld_48;
ld_152 = ld_96 * ld_136 + ld_104 * ld_152;
ld_56 = 1.5 * ld_136 - ld_152 / 2.0;
ld_160 = ld_104 * ld_160 + ld_96 * MathAbs(ld_32);
ld_168 = ld_96 * ld_160 + ld_104 * ld_168;
ld_64 = 1.5 * ld_160 - ld_168 / 2.0;
ld_176 = ld_104 * ld_176 + ld_96 * ld_64;
ld_184 = ld_96 * ld_176 + ld_104 * ld_184;
ld_144 = 1.5 * ld_176 - ld_184 / 2.0;
ld_192 = ld_104 * ld_192 + ld_96 * ld_144;
ld_200 = ld_96 * ld_192 + ld_104 * ld_200;
ld_72 = 1.5 * ld_192 - ld_200 / 2.0;
if (ld_0 >= ld_8 && ld_80 != ld_88) ld_16 = 1.0;
if (ld_0 == ld_8 && ld_16 == 0.0) ld_8 = 0.0;
}
if (ld_0 < ld_8 && ld_72 > 0.0000000001) {
ld_24 = 50.0 * (ld_56 / ld_72 + 1.0);
if (ld_24 > 100.0) ld_24 = 100.0;
if (ld_24 < 0.0) ld_24 = 0.0;
} else ld_24 = 50.0;
g_ibuf_88 = ld_24;
}
return (0);
} int init() {
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3, LawnGreen);
SetIndexBuffer(0, g_ibuf_88);
IndicatorShortName("绿色线");
return (0);
}
#property copyright "1"
#property link "1"
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 100.0
#property indicator_buffers 1
#property indicator_color1 LawnGreen
#property indicator_level3 50.0
https://cn.tradingview.com/pricing/?share_your_love=bigwin_sun //+------------------------------------------------------------------+
//| MA_In_Color.mq4 |
//| Copyright 2004, MetaQuotes Software Corp. |
//| Modified from LSMA_In_Color to use any MA by Robert Hill |
//+------------------------------------------------------------------+
#propertycopyright "Copyright 2006, FX Sniper and Robert Hill"
#propertylink "http://www.metaquotes.net/"
//---- indicator settings
#propertyindicator_chart_window
#propertyindicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
//----
extern int MAPeriod=14;
extern int MAType=1;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//---- variables
int MAMode;
string strMAType;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
//---- drawing settings
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(0,ExtMapBuffer3);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
switch(MAType)
{
case 1: strMAType="EMA"; MAMode=MODE_EMA; break;
case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break;
case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break;
case 4: strMAType="LSMA"; break;
default: strMAType="SMA"; MAMode=MODE_SMA; break;
}
IndicatorShortName( strMAType+ " (" +string(MAPeriod) + ") ");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LSMA(int Rperiod, int shift)
{
int i;
double sum;
int length;
double lengthvar;
double tmp;
double wt;
//----
length=Rperiod;
//----
sum=0;
for(i=length; i>=1 ;i--)
{
lengthvar=length + 1;
lengthvar/=3;
tmp=0;
tmp =(i - lengthvar)*Close;
sum+=tmp;
}
wt=sum*6/(length*(length+1));
//----
return(wt);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MA_Cur, MA_Prev;
int counted_bars = IndicatorCounted();
if(counted_bars < 0)return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
if(counted_bars==0) limit-=1+MAPeriod;
//----
for(int i=limit; i>=0; i--)
{
if (MAType==4)
{
MA_Cur=LSMA(MAPeriod,i);
MA_Prev=LSMA(MAPeriod,i+1);
}
else
{
MA_Cur=iMA(NULL,0,MAPeriod,0,MAMode,PRICE_CLOSE,i);
MA_Prev=iMA(NULL,0,MAPeriod,0,MAMode,PRICE_CLOSE,i+1);
}
//---- COLOR CODING
ExtMapBuffer3=MA_Cur; //red
ExtMapBuffer2=MA_Cur; //green
ExtMapBuffer1=MA_Cur; //yellow
//----
if (MA_Prev > MA_Cur)
{
ExtMapBuffer2=EMPTY_VALUE;
}
else if (MA_Prev < MA_Cur)
{
ExtMapBuffer1=EMPTY_VALUE; //-1 red/greem tight
}
else
{
ExtMapBuffer1=EMPTY_VALUE;//EMPTY_VALUE;
ExtMapBuffer2=EMPTY_VALUE;//EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| DoubleLoong.mq5 |
//| Copyright 2024, Kevin Quant. |
//| https://www.kevin.cn.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Kevin Quant."
#property link "https://www.kevin.cn.com"
#property version "1.00"
#property script_show_inputs
#include <Trade\SymbolInfo.mqh>
#include <Trade\Trade.mqh>
#include <Indicators\Trend.mqh> //CiMA
#include <Indicators\Oscilators.mqh> //CiMACD, CiATR
#include <Trade\PositionInfo.mqh>
#include <Expert\Money\MoneyFixedRisk.mqh>
input int inp_atrPeriod = 10 ; //ATR长度
input double inp_atrFactor = 3.0 ;//ATR倍数
//input int inp_tp= 30; //止盈点数
input int inp_sl= 30; //止损点数
input int inp_act = 30; //追踪激活点数
input int inp_off = 1; // 回撤点数
input double minGap= 0.1; //K线变动阀值(价格)
input double inp_lot = 0.1; //最小手数
input int inp_magic = 5555; //幻数
CSymbolInfo m_symbol;
CTrade m_trade;
CiMA ema5, veg576, veg676; //均线EMA
CiMACD macd_12_26_9; //MACD
CPositionInfo m_position;
CMoneyFixedRisk m_money;
int handle_SuperTrend; //SuperTrend指标句柄
bool macdOK=true;
double exp_sl; //止盈价格
double exp_act; //跟踪止损激活价格
double exp_tp; //止盈价格
double exp_off; //止损价格回撤幅度
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
m_symbol.Name(Symbol());//初始化商品品种
//----格式化价格-------------------------------------------
int dig = 1;
if(m_symbol.Digits() == 3 || m_symbol.Digits() == 5)
dig = 10;
if(m_symbol.Digits() == 2)
dig = 100;
m_money.Init(GetPointer( m_symbol), PERIOD_CURRENT, m_symbol.Point() * dig );
//----点数转化为价格-------------------------------------------
//exp_tp= inp_tp* m_symbol.Point()*10;//止盈价格 m_symbol.Point() =0.01
exp_sl= inp_sl* m_symbol.Point()*10;//止损价格
exp_act = inp_act * m_symbol.Point()*10;//跟踪激活价格
exp_off = inp_off * m_symbol.Point()*10;//止损价格差
if(exp_sl<=0 || exp_act<=0 || exp_off<=0 || inp_lot<=0) return(0);
Print(" 1: offset"+string(exp_off)+" 2:sl"+exp_sl+" 3:m_symbol.Point()"+ m_symbol.Point()+" 4:act"+ exp_act);
//---指标调用-------------------------------------------------------------------
//vegas 3条EMA
ema5.Create(m_symbol.Name(), PERIOD_CURRENT, 5, 0, MODE_EMA, PRICE_CLOSE);
veg576.Create(m_symbol.Name(), PERIOD_CURRENT, 576, 0, MODE_EMA, PRICE_CLOSE);
veg676.Create(m_symbol.Name(), PERIOD_CURRENT, 676, 0, MODE_EMA, PRICE_CLOSE);
//MACD
macd_12_26_9.Create(m_symbol.Name(),PERIOD_CURRENT, 12,26,9 , PRICE_CLOSE);
//画图,测试后取消
ema5.AddToChart(ChartID(), 0);
veg576.AddToChart(ChartID(), 0);
veg676.AddToChart(ChartID(), 0);
macd_12_26_9.AddToChart(ChartID(), 1);
//---- SuperTrend--------------------------------------------------------------------------------------------------------------------
handle_SuperTrend=iCustom(m_symbol.Name(), PERIOD_CURRENT,"supertrend",inp_atrPeriod,inp_atrFactor);
ChartIndicatorAdd(0,0,handle_SuperTrend);
if(handle_SuperTrend==INVALID_HANDLE)
{
Print(" 未获取 SuperTrend");
return(INIT_FAILED);
}
//幻数----------
m_trade.SetExpertMagicNumber(inp_magic);
m_trade.SetMarginMode();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
//删除所有窗口中的所有指标--
int windows_id = 4;//4个窗口
for(int j = 0; j < windows_id; j++)
{
for(int i = 0; i <= ChartIndicatorsTotal(ChartID(), j); i++)//某个窗口的数量
{
string name = ChartIndicatorName(ChartID(), j, i);//指标名
ChartIndicatorDelete(ChartID(), j, name);//删除指标
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
Refresh();
ema5.Refresh();
veg576.Refresh();
veg676.Refresh();
macd_12_26_9.Refresh();
//---获取SuperTrend指标中的trend(方向)数据-----------------------------------
double trend[];//数组,存放BB指标数据
//Copy方式 获取数值
ArraySetAsSeries(trend, true);//倒序排列,形成时间序列排序
if(CopyBuffer(handle_SuperTrend, 8, 0, 5, trend)<=0)return;//读取BB指标数据
//ArrayPrint(close);
//---K线条件----同向,当前K线强于前K 线---------------------------------------------------------1.--K线条件-
bool candlebuy= (Close(1) > Open(1)) && (Close(0) > (Open(0) + minGap/10));
bool candlesell = (Close(1) < Open(1)) && (Close(0) < (Open(0) - minGap/10));
//---vegas条件-----------------------------------------------------------------------------------------------------------------2.--Vegas条件-
bool vegbuy= (ema5.Main(0) > veg576.Main(0)) && (ema5.Main(0) > veg676.Main(0)) && (Close(0) > veg576.Main(0)) && (Close(0) > veg676.Main(0));
bool vegsell = (ema5.Main(0) < veg576.Main(0)) && (ema5.Main(0) < veg676.Main(0)) && (Close(0) < veg576.Main(0)) && (Close(0) < veg676.Main(0));
bool cross = (Low(0)> veg576.Main(0)) && (Low(1)< veg576.Main(1)) ||
(High(0) < veg576.Main(0)) && (High(1) > veg576.Main(1));
//---macd条件-------------------------------------------------------------------------------------------------------3.--macd条件-
bool macdbuy= (macd_12_26_9.Main(0) > macd_12_26_9.Signal(0)) && (macd_12_26_9.Main(0) > 0);
bool macdsell = (macd_12_26_9.Main(0) < macd_12_26_9.Signal(0)) && (macd_12_26_9.Main(0) < 0);
bool macdcross = ((macd_12_26_9.Main(0) > macd_12_26_9.Signal(0)) && (macd_12_26_9.Main(1) < macd_12_26_9.Signal(1))) ||
((macd_12_26_9.Main(0) < macd_12_26_9.Signal(0)) && (macd_12_26_9.Main(1) > macd_12_26_9.Signal(1)));
if(macdcross==NULL) return;
if( macdcross==true)
macdOK=true;
//下单条件
bool longCond= (vegbuy&& macdbuy && int(trend)==-1 && int(trend)==-1 && macdOK && candlebuy);//
bool shortCond = (vegsell && macdsell&& int(trend)== 1 && int(trend)== 1 && macdOK && candlesell);//
//---新柱订单操作:下单-------------------------------------------------------------------------------------
if(isNewBar())
{
double lot = inp_lot;//手数
// 多单-------------------------------------------------------------
if(longCond)
{
m_trade.Buy(lot);
macdOK=false; //macd条件消失
}
//空单-----------------------------------------------------------
if(shortCond)
{
m_trade.Sell(lot);
macdOK=false; //macd条件消失
}
//Vegas 交叉
if(cross)
减仓(100);
Trailing();
}
//----------------跟踪止损------------
//Trailing();
}
//----------------------------------------获取 高开低收--------------------------------K线价格
//获取开盘价格
double Open(const int idx)
{
return iOpen(m_symbol.Name(), PERIOD_CURRENT, idx);//品种,周期,K线
}
//获取收盘价格
double Close(const int idx)
{
return iClose(m_symbol.Name(), PERIOD_CURRENT, idx);
}
//获取最低价格
double Low(const int idx)
{
return iLow(m_symbol.Name(), PERIOD_CURRENT, idx);
}
//获取最高价格
double High(const int idx)
{
return iHigh(m_symbol.Name(), PERIOD_CURRENT, idx);
}
//+------------------------------------------------------------------+
//| 跟踪止损 |
//+------------------------------------------------------------------+
//订单跟踪-------------------------------------------------------------------------------------------------------------------<<订单跟踪
void Trailing()
{
if(exp_off <= 0 && exp_act <= 0) return;
for(int i = PositionsTotal(); i >= 0; i--)
{
if(m_position.SelectByIndex(i)>0)
{
if(m_position.Symbol() == m_symbol.Name())// && m_position.Magic() == inp_magic)
{
//开仓价格
double open = PositionGetDouble(POSITION_PRICE_OPEN);
//当前 价格
double current = PositionGetDouble(POSITION_PRICE_CURRENT);
//double 初始止损 = PositionGetDouble(POSITION_SL);
//多单
if(m_position.PositionType() == POSITION_TYPE_BUY)
{
if((current <= (open - exp_sl)))//初始止损位(初始止损 ==0)&&
减仓(100);//平仓100%
if(current >= open + exp_act + exp_off);// || (current <= (open - exp_sl)))//激活跟踪止损
{
跟踪止损(exp_off);
}
}
//空单
if((m_position.PositionType() == POSITION_TYPE_SELL))
{
if((current >= (open + exp_sl)))//初始止损位(初始止损 ==0)&&
减仓(100);//平仓100%
if(current <= open - exp_act -exp_off);// || (current >= (open + exp_sl)))//激活跟踪止损
{
跟踪止损(exp_off);
}
}
}
}
}
}
//跟踪止损--修改止盈止损-----------------------------------------------------------------------------------------------------------------------<<跟踪止盈止损
void 跟踪止损(double off)
{
for(int i=PositionsTotal()-1; i>=0; i--)
{
if(PositionGetTicket(i)>0 || PositionGetSymbol(i)!="")//如果有订单
{
//如果多单。
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
MqlTradeRequest request={};
MqlTradeResultresult={};
double 初始化止损 = PositionGetDouble(POSITION_SL);
request.action=TRADE_ACTION_SLTP;//用于修改订单
request.position=PositionGetInteger(POSITION_TICKET);
request.symbol=PositionGetString(POSITION_SYMBOL);
request.price=SymbolInfoDouble(m_symbol.Name(),SYMBOL_BID);
if(初始化止损==0){
request.sl=PositionGetDouble(POSITION_PRICE_OPEN) + exp_act;
}
else if(request.price>=初始化止损 + off)
{
request.sl= request.price - off;
}
else
{
request.sl= 初始化止损;
}
request.type=ORDER_TYPE_BUY;
bool X=OrderSend(request,result);
if(X==false)
{
Print("修改多单止损返回代码:" + IntegerToString(result.retcode));
}
}
//如果空单。
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
MqlTradeRequest request={};
MqlTradeResultresult={};
double 初始化止损 = PositionGetDouble(POSITION_SL);
request.action=TRADE_ACTION_SLTP;//用于修改订单
request.position=PositionGetInteger(POSITION_TICKET);
request.symbol=PositionGetString(POSITION_SYMBOL);
request.price=SymbolInfoDouble(m_symbol.Name(),SYMBOL_BID);
if(初始化止损==0){
//request.sl=PositionGetDouble(POSITION_PRICE_OPEN)+MathAbs(off-PositionGetDouble(POSITION_PRICE_OPEN));
request.sl=PositionGetDouble(POSITION_PRICE_OPEN) - exp_act;
}
else if(request.price<=初始化止损 - off)
{
request.sl=request.price + off;
}
else
{
request.sl=初始化止损;
}
request.type=ORDER_TYPE_SELL;
bool X=OrderSend(request,result);
if(X==false)
{
Print("修改空单止损返回代码:" + IntegerToString(result.retcode));
}
}
}
}
}
//减仓-----------------------------------------------------------------------------------------------------------------------<<减仓
void 减仓(int 减仓比例)
{
for(int i=PositionsTotal()-1; i>=0; i--)
{
if(PositionGetTicket(i)>0 || PositionGetSymbol(i)!="")
{
//如果多单。
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
MqlTradeRequest request={};
MqlTradeResultresult={};
request.action=TRADE_ACTION_DEAL;
request.magic=PositionGetInteger(POSITION_MAGIC);
request.position=PositionGetInteger(POSITION_TICKET);
//减仓的比例
double vol=NormalizeDouble(PositionGetDouble(POSITION_VOLUME)*减仓比例/100, 2);//减仓手数
request.volume=vol;//减仓--按比例
request.symbol=PositionGetString(POSITION_SYMBOL);
request.price=PositionGetDouble(POSITION_PRICE_CURRENT);
request.deviation=10;
request.type=ORDER_TYPE_SELL;
request.comment=PositionGetString(POSITION_COMMENT);
bool X=OrderSend(request,result);
if(X==false)
{
Print("多单减仓发送失败代码:" + IntegerToString(GetLastError()));
Print("多单减仓返回代码:" + IntegerToString(result.retcode));
}
}
//如果空单。
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
MqlTradeRequest request={};
MqlTradeResultresult={};
request.action=TRADE_ACTION_DEAL;
request.magic=PositionGetInteger(POSITION_MAGIC);
request.position=PositionGetInteger(POSITION_TICKET);
//减仓的比例
double vol=NormalizeDouble(PositionGetDouble(POSITION_VOLUME)*减仓比例/100, 2);//减仓手数
request.volume=vol;//比例减持 仓位
request.symbol=PositionGetString(POSITION_SYMBOL);
request.price=PositionGetDouble(POSITION_PRICE_CURRENT);
request.deviation=10;
request.type=ORDER_TYPE_BUY;
request.comment=PositionGetString(POSITION_COMMENT);
bool X=OrderSend(request,result);
if(X==false)
{
Print("空单减仓发送失败代码:" + IntegerToString(GetLastError()));
Print("空单减仓返回代码:" + IntegerToString(result.retcode));
}
}
}
}
}
//原仓位-----------------------------------------------------------------------------------------------------------------------<<仓位
bool 原仓位(void)
{
for(int i = PositionsTotal(); i >= 0; i--)
{
if(m_position.SelectByIndex(i))
{
//持仓手数
double vol = PositionGetDouble(POSITION_VOLUME);
if(vol == inp_lot)
{
return true;
}
}
}
return false;
}
//刷新函数
bool Refresh(void)
{
if(!m_symbol.RefreshRates())
{
Print("refresh error");
return (false);
}
if(m_symbol.Ask() == 0 || m_symbol.Bid() == 0)
{
Print("refresh error");
return (false);
}
return(true);
}
//检查是不是新K线
bool isNewBar()
{
static datetime last_time = 0;
datetime lastbar_time = (datetime)SeriesInfoInteger(Symbol(), Period(), SERIES_LASTBAR_DATE);
if(last_time == 0)
{
last_time = lastbar_time;
return(false);
}
if(last_time != lastbar_time)
{
last_time = lastbar_time;
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
DeleteFromChart(ChartID(), 0);//删除窗口中的指标
删除所有窗口中的所有指标--
int windows_id = 4;//4个窗口
for(int j = 0; j < windows_id; j++)
{
for(int i = 0; i <= ChartIndicatorsTotal(ChartID(), j); i++)//某个窗口的数量
{
string name = ChartIndicatorName(ChartID(), j, i);//指标名
ChartIndicatorDelete(ChartID(), j, name);//删除指标
}
}
} [偷笑] 还能投稿嘛 ?怎么联系楼主? 欢迎合作。
⦁ TradingView脚本编写
⦁ MetaTrader(MT4/MT5)策略编写
⦁ Python/C++自动交易程序开发
⦁ 复盘回测服务,提供十年历史数据
声明:所提供的策略和程序仅供学习和研究使用,对实际交易结果概不负责。如有需求,请通过聊天联系,详细沟通后再决定购买。
价格:¥100(根据具体需求定价) 怎么个和做法?
页:
[1]