代码拉取完成,页面将自动刷新
#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());
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。