1 Star 2 Fork 0

joye1230/ea

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
IchimokuKinkoHyo.mq4 16.52 KB
一键复制 编辑 原始数据 按行查看 历史
#property copyright "2005-2015, joye.zhang Corp."
#property link "http://www.ijoye.org"
input double N = 100;
input double TakeProfit =50;//止赢
input double TrailingStop =30;//止损
input double Lots =0.1; //开单手数
input double bandsShift = -26;//boll平移
//input double NewTrailingStop =30;//当触发移动止损条件的时候修改的止损
//设置Ichimoku Kinko Hyo的三个指标
input int tenkanSen =9;
input int KijunSen =26;
input int SenkouSpanB =52;
enum{
timeparamentA = 0,
timeparamentB = 1,
};
struct TIchimokuTime
{
double tenkansenCurren;
double kijunsenCurren;
double SenkouSpanACurren;
double SenkouSpanBCurren;
double SenkouSpanCurren;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick(void)
{
//定义Ichimoku Kinko Hyo各个指标
int IchimokuTimeValue[2]={60,15};
TIchimokuTime IchimokuTime[2];
int cnt,ticket,total,ret,buy_orders_count = 0,sell_orders_count = 0;
/*
if(Bars<100)
{
Print("bars less than 100");
return;
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return;
}
*/
//Ichimoku Kinko Hyo 中的各值
for(int i = 0;i< 2 ;i++)
{
IchimokuTime[i].tenkansenCurren=iIchimoku(NULL,IchimokuTimeValue[i],tenkanSen, KijunSen,SenkouSpanB, MODE_TENKANSEN, 1);
IchimokuTime[i].kijunsenCurren=iIchimoku(NULL,IchimokuTimeValue[i],tenkanSen, KijunSen,SenkouSpanB, MODE_KIJUNSEN, 1);
IchimokuTime[i].SenkouSpanACurren=iIchimoku(NULL,IchimokuTimeValue[i],tenkanSen, KijunSen,SenkouSpanB, MODE_SENKOUSPANA, 1);
IchimokuTime[i].SenkouSpanBCurren=iIchimoku(NULL,IchimokuTimeValue[i],tenkanSen, KijunSen,SenkouSpanB, MODE_SENKOUSPANB, 1);
//Print("IchimokuTime index :",i," tenkansen:",IchimokuTime[i].tenkansenCurren," kijunsen:", IchimokuTime[i].kijunsenCurren,
//" SenkouSpanA",IchimokuTime[i].SenkouSpanACurren," SenkouSpanB",IchimokuTime[i].SenkouSpanBCurren);
}
//boll最低收盘价格
double BandsLower = iBands(NULL,IchimokuTimeValue[1],20,2,bandsShift,PRICE_LOW,MODE_LOWER,0);
double BandsUpper = iBands(NULL,IchimokuTimeValue[1],20,2,bandsShift,PRICE_LOW,MODE_UPPER,0);
//b的收盘价
double timeparamentB_close = iClose(NULL,IchimokuTimeValue[timeparamentB],0);
//b的中间价
double timeparamentB_parityRate = (iHigh(NULL,IchimokuTimeValue[timeparamentB],0)+iLow(NULL,IchimokuTimeValue[timeparamentB],0) )/2;
// Print("BandsLower:",BandsLower," timeparamentB_close:",timeparamentB_close," timeparamentB_parityRate:",timeparamentB_parityRate,"now close",iClose(NULL,0,0),
// "NPoint ",N*Point, "Close[0]", Close[0]);
// Print("--------Bid - IchimokuTime[timeparamentB].kijunsenCurren",Bid - IchimokuTime[timeparamentB].kijunsenCurren);
/*
Print("对于 USDCHF H1当前柱: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ",
iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ",
iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));
*/
//--- check for long position (BUY) possibility
//ret -1为默认值 0为下单 1不下单;
total=OrdersTotal();
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
//这里遍历当前的订单,修改符合条件订单,并修改移动止损
for(cnt=0;cnt<total;cnt++)
{
//判断 订单是否存在 和是否是来自交易的订单
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//是否为多单
//--- long position is opened
if(OrderType()==OP_BUY)
{
//平仓
ret = -1;
if(IchimokuTime[timeparamentB].SenkouSpanBCurren < BandsUpper
// ||IchimokuTime[timeparamentB].tenkansenCurren < IchimokuTime[timeparamentB].kijunsenCurren
){
ret = 0;
}
if(!ret)
{
//--- modify order and exit
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
Print("OrderModify error ",GetLastError());
continue;
}
}
}
else // go to short position
{
//平仓
ret = -1;
if(IchimokuTime[timeparamentB].SenkouSpanBCurren > BandsLower
// || IchimokuTime[timeparamentB].tenkansenCurren > IchimokuTime[timeparamentB].kijunsenCurren
){
ret = 0;
}
if(!ret)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
Print("OrderModify error ",GetLastError());
continue;
}
}
}
for(cnt=0;cnt<total;cnt++){
if(OrderSelect(cnt,SELECT_BY_POS)==false) continue;
if(OrderType()== OP_BUY){
buy_orders_count++;
}
else if(OrderType()== OP_SELL){
sell_orders_count++;
}
}
if(buy_orders_count >= 1 || sell_orders_count >=1){
Print("buy_orders_count",buy_orders_count,"sell_orders_count",sell_orders_count);
return;
}
/*
if(total>=1){
Print("total",total);
return ;
}
*/
ret = -1;
if(IchimokuTime[timeparamentA].SenkouSpanACurren > IchimokuTime[timeparamentA].SenkouSpanBCurren){
//多单条件1
if(
IchimokuTime[timeparamentB].SenkouSpanACurren > IchimokuTime[timeparamentB].SenkouSpanBCurren &&
IchimokuTime[timeparamentB].tenkansenCurren >= IchimokuTime[timeparamentB].kijunsenCurren &&
iClose(NULL,0,0) >= IchimokuTime[timeparamentB].kijunsenCurren &&
Bid - IchimokuTime[timeparamentB].kijunsenCurren < N*Point
){
ret = 0;
}
//多单条件2
if( timeparamentB_parityRate > IchimokuTime[timeparamentB].kijunsenCurren &&
IchimokuTime[timeparamentB].tenkansenCurren > IchimokuTime[timeparamentB].kijunsenCurren &&
IchimokuTime[timeparamentB].SenkouSpanACurren > IchimokuTime[timeparamentB].SenkouSpanBCurren
){
ret = 0;
}
}
if(!ret)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-TrailingStop*Point,Ask+TakeProfit*Point,"Ichimoku_BUY",10000,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else
Print("Error opening BUY order : ",GetLastError());
return;
}
//--- check for short position (SELL) possibility
ret = -1;
if(IchimokuTime[timeparamentA].SenkouSpanACurren < IchimokuTime[timeparamentA].SenkouSpanBCurren){
//做空的条件1
if(IchimokuTime[timeparamentB].SenkouSpanACurren < IchimokuTime[timeparamentB].SenkouSpanBCurren &&
IchimokuTime[timeparamentB].tenkansenCurren <= IchimokuTime[timeparamentB].kijunsenCurren &&
Close[0] < IchimokuTime[timeparamentB].kijunsenCurren &&
Bid - IchimokuTime[timeparamentB].kijunsenCurren < N*Point
){
ret =0;
}
//做空的条件2
if(timeparamentB_parityRate < IchimokuTime[timeparamentB].kijunsenCurren &&
IchimokuTime[timeparamentB].tenkansenCurren < IchimokuTime[timeparamentB].kijunsenCurren &&
IchimokuTime[timeparamentB].SenkouSpanACurren < IchimokuTime[timeparamentB].SenkouSpanBCurren
){
ret = 0;
}
}
if(!ret)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+TrailingStop*Point,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else
Print("Error opening SELL order : ",GetLastError());
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/joye1230/ea.git
git@gitee.com:joye1230/ea.git
joye1230
ea
ea
master

搜索帮助